#include <AH/Filters/Hysteresis.hpp>
A class for applying hysteresis to a given input.
This reduces the noise by decreasing the resolution, and it prevents flipping back and forth between two values.
An example for BITS
= 7 and an input from 0 to 1023
BITS | The number of bits to decrease in resolution. Increasing this number will result in a decrease in fluctuations. |
Definition at line 36 of file Hysteresis.hpp.
Public Member Functions | |
bool | update (T_in inputLevel) |
Update the hysteresis output with a new input value. More... | |
T_out | getValue () const |
Get the current output level. More... | |
void | setValue (T_in inputLevel) |
Forcefully update the internal state to the given level. More... | |
Private Attributes | |
T_out | prevLevel = 0 |
Static Private Attributes | |
static constexpr T_in | margin = (1UL << BITS) - 1 |
static constexpr T_in | offset = 1UL << (BITS - 1) |
static constexpr T_in | max_in = -1 |
static constexpr T_out | max_out = static_cast<T_out>(max_in >> BITS) |
|
inline |
Update the hysteresis output with a new input value.
inputLevel | The input to calculate the output level from. |
true | The output level has changed. |
false | The output level is still the same. |
Definition at line 48 of file Hysteresis.hpp.
|
inline |
Get the current output level.
Definition at line 64 of file Hysteresis.hpp.
|
inline |
Forcefully update the internal state to the given level.
Definition at line 69 of file Hysteresis.hpp.
|
private |
Definition at line 72 of file Hysteresis.hpp.
|
staticconstexprprivate |
Definition at line 73 of file Hysteresis.hpp.
|
staticconstexprprivate |
Definition at line 74 of file Hysteresis.hpp.
|
staticconstexprprivate |
Definition at line 75 of file Hysteresis.hpp.
|
staticconstexprprivate |
Definition at line 76 of file Hysteresis.hpp.