From 3ce6434919d7607917e366a7b69fcbfb918d534b Mon Sep 17 00:00:00 2001 From: bernie Date: Wed, 13 Aug 2008 09:45:31 +0000 Subject: [PATCH] Move algorithms from mware/ to algo/ git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1627 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/algo/mean.h | 41 +++++++++++++++++++++++++++++++ bertos/{mware => algo}/rle.c | 0 bertos/algo/rle.h | 45 ++++++++++++++++++++++++++++++++++ bertos/mware/hex.c | 2 -- bertos/mware/rle.h | 47 ++---------------------------------- 5 files changed, 88 insertions(+), 47 deletions(-) create mode 100644 bertos/algo/mean.h rename bertos/{mware => algo}/rle.c (100%) create mode 100644 bertos/algo/rle.h diff --git a/bertos/algo/mean.h b/bertos/algo/mean.h new file mode 100644 index 00000000..893241e2 --- /dev/null +++ b/bertos/algo/mean.h @@ -0,0 +1,41 @@ +#warning revise me! + + +/** + * DECLARE_SMEAN(temperature, uint8_t, uint16_t); + * for (i = 0; i < TEMP_MEANS; ++i) + * SMEAN_ADD(temperature, adc_get(), TEMP_MEANS); + * printf("mean temperature = %d\n", SMEAN_GET(temperature)); + */ + +/** + * Instantiate a mean instance + */ +#define DECLARE_SMEAN(name, Type, SumType) \ + struct { \ + SumType sum; \ + Type result; \ + int count; \ + } name = { 0, 0, 0 } + +/** + * Insert a new sample into the mean. + * + * \note \a mean and \a max_samples are evaluated multiple times + */ +#define SMEAN_ADD(mean, sample, max_samples) \ + do { \ + (mean).sum += (sample); \ + if ((mean).count++ >= (max_samples)) \ + { \ + (mean).result = (mean).sum / (max_samples); \ + (mean).sum = 0; \ + (mean).count = 0; \ + } \ + } while (0) + +/** + * Return current mean value. + */ +#define SMEAN_GET(mean) ((mean).result) + diff --git a/bertos/mware/rle.c b/bertos/algo/rle.c similarity index 100% rename from bertos/mware/rle.c rename to bertos/algo/rle.c diff --git a/bertos/algo/rle.h b/bertos/algo/rle.h new file mode 100644 index 00000000..6e056d22 --- /dev/null +++ b/bertos/algo/rle.h @@ -0,0 +1,45 @@ +/** + * \file + * + * + * \version $Id$ + * \author Bernie Innocenti + * + * \brief General-purpose run-length {en,de}coding algorithm (interface) + */ +#ifndef RLE_H +#define RLE_H + +int rle(unsigned char *output, const unsigned char *input, int length); +int unrle(unsigned char *output, const unsigned char *input); + +#endif /* RLE_H */ diff --git a/bertos/mware/hex.c b/bertos/mware/hex.c index dd326c43..4b22f1ef 100644 --- a/bertos/mware/hex.c +++ b/bertos/mware/hex.c @@ -27,13 +27,11 @@ * the GNU General Public License. * * Copyright 2005 Develer S.r.l. (http://www.develer.com/) - * * --> * * \brief Poor man's hex arrays (implementation). * * \version $Id$ - * * \author Bernie Innocenti */ diff --git a/bertos/mware/rle.h b/bertos/mware/rle.h index 6e056d22..0ca9a28d 100644 --- a/bertos/mware/rle.h +++ b/bertos/mware/rle.h @@ -1,45 +1,2 @@ -/** - * \file - * - * - * \version $Id$ - * \author Bernie Innocenti - * - * \brief General-purpose run-length {en,de}coding algorithm (interface) - */ -#ifndef RLE_H -#define RLE_H - -int rle(unsigned char *output, const unsigned char *input, int length); -int unrle(unsigned char *output, const unsigned char *input); - -#endif /* RLE_H */ +#warning This header is OBSOLETE +#include -- 2.25.1