Add tlmConfirm to tlm_dl ota packet-structure (#2991)
[ExpressLRS.git] / src / lib / MeanAccumulator / MeanAccumulator.h
blob658b2967b6dd400e1b51801e4f28c98b55d49c0a
1 #pragma once
3 template <typename StorageType, typename IncrementType, IncrementType NoValueReturn>
4 class MeanAccumulator
6 public:
7 void add(IncrementType val)
9 _accumulator += val;
10 ++_count;
13 IncrementType mean()
15 if (_count)
17 _previousMean = _accumulator / _count;
18 reset();
20 return _previousMean;
22 return NoValueReturn;
25 IncrementType previousMean()
27 return _previousMean;
30 void reset()
32 _accumulator = 0;
33 _count = 0;
36 size_t getCount() const
38 return _count;
41 private:
42 StorageType _accumulator;
43 StorageType _count;
44 IncrementType _previousMean;