added https://playground.arduino.cc/Main/RunningAverage
[Arduino] / wlan_si / RunningAverage.h
1 #ifndef RunningAverage_h
2 #define RunningAverage_h
3 //
4 //    FILE: RunningAverage.h
5 //  AUTHOR: Rob dot Tillaart at gmail dot com
6 // PURPOSE: RunningAverage library for Arduino
7 //     URL: http://arduino.cc/playground/Main/RunningAverage
8 // HISTORY: See RunningAverage.cpp
9 //
10 // Released to the public domain
11 //
12
13 // backwards compatibility
14 // clr() clear()
15 // add(x) addValue(x)
16 // avg() getAverage()
17
18 #define RUNNINGAVERAGE_LIB_VERSION "0.2.04"
19
20 #include "Arduino.h"
21
22 class RunningAverage
23 {
24 public:
25     RunningAverage(void);
26     RunningAverage(int);
27     ~RunningAverage();
28
29     void clear();
30     void addValue(float);
31     void fillValue(float, int);
32
33     float getAverage();
34
35     float getElement(uint8_t idx);
36     uint8_t getSize() { return _size; }
37     uint8_t getCount() { return _cnt; }
38
39 protected:
40     uint8_t _size;
41     uint8_t _cnt;
42     uint8_t _idx;
43     float   _sum;
44     float * _ar;
45 };
46
47 #endif
48 // END OF FILE