From 64c247fee453da33cd090ac51b7e5a90e23a95f8 Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Sun, 9 Oct 2011 22:19:32 +0200 Subject: [PATCH] testing --- libraries/RunningAverage/RunningAverage.cpp | 57 ---------------- libraries/RunningAverage/RunningAverage.h | 33 --------- .../examples/ra_hour/ra_hour.pde | 28 -------- .../examples/ra_test/ra_test.pde | 27 -------- libraries/RunningMedian/RunningMedian.cpp | 68 ------------------- libraries/RunningMedian/RunningMedian.h | 37 ---------- 6 files changed, 250 deletions(-) delete mode 100644 libraries/RunningAverage/RunningAverage.cpp delete mode 100644 libraries/RunningAverage/RunningAverage.h delete mode 100644 libraries/RunningAverage/examples/ra_hour/ra_hour.pde delete mode 100644 libraries/RunningAverage/examples/ra_test/ra_test.pde delete mode 100644 libraries/RunningMedian/RunningMedian.cpp delete mode 100644 libraries/RunningMedian/RunningMedian.h diff --git a/libraries/RunningAverage/RunningAverage.cpp b/libraries/RunningAverage/RunningAverage.cpp deleted file mode 100644 index 079b9bb6..00000000 --- a/libraries/RunningAverage/RunningAverage.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// -// FILE: RunningAverage.cpp -// AUTHOR: Rob Tillaart -// VERSION: 0.1.01 -// PURPOSE: RunningAverage library for Arduino -// -// The library does store the last N individual values, to -// calculate the running average. -// -// HISTORY: -// 0.1.00 - 2011-01-30 initial version -// 0.1.01 - 2011-02-28 fixed missing destructor in .h -// -// Released to the public domain -// - -#include "RunningAverage.h" -#include - -RunningAverage::RunningAverage(int n) -{ - _size = n; - _ar = (float*) malloc(_size * sizeof(float)); - clr(); -} - -RunningAverage::~RunningAverage() -{ - free(_ar); -} - -// resets all counters -void RunningAverage::clr() -{ - _cnt = 0; - _idx = 0; - _sum = 0.0; - for (int i=0; i< _size; i++) _ar[i] = 0.0; -} - -// adds a new value to the data-set -void RunningAverage::add(float f) -{ - _sum -= _ar[_idx]; - _ar[_idx] = f; - _sum += _ar[_idx]; - _idx = (_idx + 1) % _size; - if (_cnt < _size) _cnt++; -} - -// returns the average of the data-set added sofar -float RunningAverage::avg() -{ - return _sum / _cnt; -} - -// END OF FILE \ No newline at end of file diff --git a/libraries/RunningAverage/RunningAverage.h b/libraries/RunningAverage/RunningAverage.h deleted file mode 100644 index fa74d113..00000000 --- a/libraries/RunningAverage/RunningAverage.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef RunningAverage_h -#define RunningAverage_h -// -// FILE: RunningAverage.h -// AUTHOR: Rob dot Tillaart at gmail dot com -// PURPOSE: RunningAverage library for Arduino -// VERSION: 0.1.01 -// URL: http://arduino.cc/playground/Main/RunningAverage -// HISTORY: See RunningAverage.cpp -// -// Released to the public domain -// - -class RunningAverage -{ - public: - RunningAverage(void); - RunningAverage(int); - ~RunningAverage(); - void clr(); - void add(float); - float avg(); - -protected: - int _size; - int _cnt; - int _idx; - float _sum; - float * _ar; -}; - -#endif -// END OF FILE \ No newline at end of file diff --git a/libraries/RunningAverage/examples/ra_hour/ra_hour.pde b/libraries/RunningAverage/examples/ra_hour/ra_hour.pde deleted file mode 100644 index 56d78339..00000000 --- a/libraries/RunningAverage/examples/ra_hour/ra_hour.pde +++ /dev/null @@ -1,28 +0,0 @@ -#include "RunningAverage.h" - -RunningAverage raMinute(60); -RunningAverage raHour(60); - -int samples = 0; - -void setup(void) -{ - Serial.begin(115200); - Serial.println("Demo RunningAverage lib - average per minute & hour"); - raHour.clr(); - raMinute.clr(); -} - -void loop(void) -{ - long rn = random(0, 100); - raMinute.add(rn); - samples++; - - if (samples % 60 == 0) raHour.add(raMinute.avg()); - - Serial.print(" raMinute: "); - Serial.print(raMinute.avg(), 4); - Serial.print(" raHour: "); - Serial.println(raHour.avg(), 4); -} \ No newline at end of file diff --git a/libraries/RunningAverage/examples/ra_test/ra_test.pde b/libraries/RunningAverage/examples/ra_test/ra_test.pde deleted file mode 100644 index 41e6af12..00000000 --- a/libraries/RunningAverage/examples/ra_test/ra_test.pde +++ /dev/null @@ -1,27 +0,0 @@ -#include "RunningAverage.h" - -RunningAverage myRA(10); // use default size -int samples = 0; - -void setup(void) -{ - Serial.begin(115200); - Serial.println("Demo RunningAverage lib"); - myRA.clr(); // explicitly start clean -} - -void loop(void) -{ - long rn = random(0, 100); - myRA.add(rn/100.0); - samples++; - Serial.print("Running Average: "); - Serial.println(myRA.avg(), 4); - - if (samples == 300) - { - samples = 0; - myRA.clr(); - } - delay(100); -} \ No newline at end of file diff --git a/libraries/RunningMedian/RunningMedian.cpp b/libraries/RunningMedian/RunningMedian.cpp deleted file mode 100644 index 3f8b9ce2..00000000 --- a/libraries/RunningMedian/RunningMedian.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// -// FILE: RunningMedian.cpp -// AUTHOR: Rob dot Tillaart at gmail dot com -// VERSION: 0.1 -// PURPOSE: RunningMedian library for Arduino -// -// HISTORY: -// 0.1.00 - 2011-02-16 initial version -// 0.1.01 - 2011-02-22 added remarks from CodingBadly -// -// Released to the public domain -// - -#include "RunningMedian.h" - -RunningMedian::RunningMedian() -{ - // size hardcoded - clear(); -} - -// resets all counters -void RunningMedian::clear() -{ - _cnt = 0; - _idx = 0; -} - -// adds a new value to the data-set -// or overwrites the oldest if full. -void RunningMedian::add(long value) -{ - _ar[_idx++] = value; - if ( _idx >= MEDIAN_SIZE ) _idx = 0; // wrap around - if (_cnt < MEDIAN_SIZE) _cnt++; - return; -} - -long RunningMedian::getMedian() -{ - sort(); - return _as[_cnt/2]; -} - - -void RunningMedian::sort() -{ - // copy - for (uint8_t i=0; i< _cnt; i++) _as[i] = _ar[i]; - - // sort all - for (uint8_t i=0; i< _cnt-1; i++) - { - uint8_t m = i; - for (uint8_t j=i+1; j< _cnt; j++) - { - if (_as[j] < _as[m]) m = j; - } - if (m != i) - { - long t = _as[m]; - _as[m] = _as[i]; - _as[i] = t; - } - } -} - -// END OF FILE \ No newline at end of file diff --git a/libraries/RunningMedian/RunningMedian.h b/libraries/RunningMedian/RunningMedian.h deleted file mode 100644 index 8424da18..00000000 --- a/libraries/RunningMedian/RunningMedian.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef RunningMedian_h -#define RunningMedian_h -// -// FILE: RunningMedian.h -// AUTHOR: Rob dot Tillaart at gmail dot com -// PURPOSE: RunningMedian library for Arduino -// VERSION: 0.1.01 -// URL: http://arduino.cc/playground/Main/RunningMedian -// HISTORY: See RunningMedian.cpp -// -// Released to the public domain -// - -#include - -#define RUNNINGMEDIANVERSION "1.0" -// should at least be 5 and odd. -#define MEDIAN_SIZE 5 - -class RunningMedian -{ - public: - RunningMedian(); - void clear(); - void add(long); - long getMedian(); - -protected: - uint8_t _cnt; - uint8_t _idx; - long _ar[MEDIAN_SIZE]; - long _as[MEDIAN_SIZE]; - void sort(); -}; - -#endif -// END OF FILE \ No newline at end of file