2014-07-03 16:00:45 -04:00
|
|
|
//
|
2011-10-09 16:24:50 -04:00
|
|
|
// FILE: RunningAverage.h
|
|
|
|
// AUTHOR: Rob dot Tillaart at gmail dot com
|
2015-09-05 06:14:02 -04:00
|
|
|
// VERSION: 0.2.11
|
|
|
|
// DATE: 2015-sep-04
|
2011-10-09 16:24:50 -04:00
|
|
|
// PURPOSE: RunningAverage library for Arduino
|
|
|
|
// URL: http://arduino.cc/playground/Main/RunningAverage
|
|
|
|
// HISTORY: See RunningAverage.cpp
|
|
|
|
//
|
|
|
|
// Released to the public domain
|
|
|
|
//
|
2013-08-17 08:43:42 -04:00
|
|
|
// backwards compatibility
|
2015-04-10 15:23:24 -04:00
|
|
|
// clr() clear()
|
|
|
|
// add(x) addValue(x)
|
|
|
|
// avg() getAverage()
|
2013-08-17 08:43:42 -04:00
|
|
|
|
2014-12-16 16:04:21 -05:00
|
|
|
#ifndef RunningAverage_h
|
|
|
|
#define RunningAverage_h
|
|
|
|
|
2015-09-05 06:14:02 -04:00
|
|
|
#define RUNNINGAVERAGE_LIB_VERSION "0.2.11"
|
2014-07-03 16:00:45 -04:00
|
|
|
|
|
|
|
#include "Arduino.h"
|
2013-08-17 08:43:42 -04:00
|
|
|
|
2014-07-03 16:00:45 -04:00
|
|
|
class RunningAverage
|
2011-10-09 16:24:50 -04:00
|
|
|
{
|
2014-07-03 16:00:45 -04:00
|
|
|
public:
|
|
|
|
RunningAverage(void);
|
2015-09-05 06:14:02 -04:00
|
|
|
explicit RunningAverage(const uint8_t);
|
2014-07-03 16:00:45 -04:00
|
|
|
~RunningAverage();
|
|
|
|
|
|
|
|
void clear();
|
2015-09-05 06:14:02 -04:00
|
|
|
void addValue(const double);
|
|
|
|
void fillValue(const double, const uint8_t);
|
|
|
|
|
|
|
|
double getAverage() const; // does iterate over all elements.
|
|
|
|
double getFastAverage() const; // reuses previous values.
|
|
|
|
|
|
|
|
// returns min/max added to the data-set since last clear
|
|
|
|
double getMin() const { return _min; };
|
|
|
|
double getMax() const { return _max; };
|
|
|
|
|
|
|
|
// returns min/max from the values in the internal buffer
|
|
|
|
double GetMinInBuffer() const;
|
|
|
|
double GetMaxInBuffer() const;
|
|
|
|
|
|
|
|
double getElement(uint8_t idx) const;
|
|
|
|
|
|
|
|
uint8_t getSize() const { return _size; }
|
|
|
|
uint8_t getCount() const { return _cnt; }
|
2011-10-09 16:24:50 -04:00
|
|
|
|
|
|
|
protected:
|
2014-07-03 16:00:45 -04:00
|
|
|
uint8_t _size;
|
|
|
|
uint8_t _cnt;
|
|
|
|
uint8_t _idx;
|
2015-04-10 15:23:24 -04:00
|
|
|
double _sum;
|
2014-12-16 16:04:21 -05:00
|
|
|
double * _ar;
|
2015-04-10 15:23:24 -04:00
|
|
|
double _min;
|
|
|
|
double _max;
|
2011-10-09 16:24:50 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
// END OF FILE
|