forked from RobTillaart/RunningAverage
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RunningAverage.h
85 lines (63 loc) · 2.19 KB
/
RunningAverage.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef RUNNINGAVERAGE_H_
#define RUNNINGAVERAGE_H_
#include <stdint.h>
#include <stddef.h>
#pragma once
//
// FILE: RunningAverage.h
// AUTHOR: [email protected]
// VERSION: 0.3.2
// DATE: 2016-dec-01
// PURPOSE: Arduino library to calculate the running average by means of a circular buffer
// URL: https://github.com/RobTillaart/RunningAverage
//
// HISTORY: See RunningAverage.cpp
// #include "Arduino.h"
#include "CircularBuffer.h"
#define RUNNINGAVERAGE_LIB_VERSION (F("0.3.2"))
template<typename dataType, size_t bufferSize> class RunningAverage
{
public:
// RunningAverage(const uint8_t size);
// static constexpr uint8_t capacity = static_cast<uint8_t>(T);
/**
* Disables copy constructor
*/
// RunningAverage(const RunningAverage&) = delete;
// RunningAverage(RunningAverage&&) = delete;
RunningAverage();
~RunningAverage();
void clear();
// void add(const float value) { addValue(value); };
void addValue(const dataType);
// void fillValue(const float, const uint8_t);
// float getValue(const uint8_t);
float getAverage(); // iterates over all elements.
float getFastAverage() const; // reuses previous calculated values.
// return statistical characteristics of the running average
float getStandardDeviation() const;
float getStandardError() const;
// returns min/max added to the data-set since last clear
dataType getMin() const { return _min; };
dataType getMax() const { return _max; };
// returns min/max from the values in the internal buffer
dataType getMinInBuffer() const;
dataType getMaxInBuffer() const;
// return true if buffer is full
bool bufferIsFull() const { return _array.isFull(); };
dataType getElement(uint8_t idx) const;
size_t getCapacity() const { return _array.capacity(); };
uint8_t getCount() const { return _array.size(); }
protected:
// uint8_t _size;
// uint8_t _count;
// uint8_t _index;
float _sum;
// float* _array;
dataType _min;
dataType _max;
CircularBuffer<dataType, bufferSize> _array;
};
#include <RunningAverage.tpp>
// -- END OF FILE --t
#endif