39template<
typename T, u
int8_t DURATION_IN_MINUTES = 10, u
int8_t VALUES_PER_MINUTE = 10 >
60 uint8_t
i{ DURATION_IN_MINUTES };
98 _sum = DURATION_IN_MINUTES * _value;
100 uint8_t
i{ DURATION_IN_MINUTES };
117 if constexpr (DURATION_IN_MINUTES == 1)
119 else if constexpr (DURATION_IN_MINUTES == 2)
121 else if constexpr (DURATION_IN_MINUTES == 4)
123 else if constexpr (DURATION_IN_MINUTES == 8)
125 else if constexpr (DURATION_IN_MINUTES == 16)
127 else if constexpr (DURATION_IN_MINUTES == 32)
135 if (idx >= DURATION_IN_MINUTES)
146 [[nodiscard]]
constexpr uint8_t
getSize()
const
148 return DURATION_IN_MINUTES;
161 uint8_t
i{ VALUES_PER_MINUTE };
178 if (
_idx == DURATION_IN_MINUTES)
196 T
_ar[DURATION_IN_MINUTES]{};
198 static constexpr float invD{ 1.0 / VALUES_PER_MINUTE };
199 static constexpr float invN{ 1.0 / DURATION_IN_MINUTES };
Template class for implementing a sliding average.
static constexpr float invN
conditional< is_floating_point< T >::value, T, int32_t >::type _sum
auto getAverage() const
Get the sliding average.
constexpr uint8_t getSize() const
T _ar[DURATION_IN_MINUTES]
void _addValue(const T &_value)
void addValue(const T &_value)
Add a value.
void fillValue(const T &_value)
conditional< is_floating_point< T >::value, T, int32_t >::type _sub_sum
void clear()
Reset everything.
static constexpr float invD
T _sub_ar[VALUES_PER_MINUTE]
auto getElement(uint8_t idx) const
Some useful but missing stl functions templates.