Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | Static Private Attributes | List of all members
Hysteresis< Bits, T_in, T_out > Class Template Reference

#include <AH/Filters/Hysteresis.hpp>

Detailed Description

template<uint8_t Bits, class T_in = uint16_t, class T_out = uint8_t>
class AH::Hysteresis< Bits, T_in, T_out >

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

Template Parameters
BITSThe number of bits to decrease in resolution. Increasing this number will result in a decrease in fluctuations.

Definition at line 37 of file Hysteresis.hpp.

+ Collaboration diagram for Hysteresis< Bits, T_in, T_out >:

Public Member Functions

bool update (T_in inputLevel)
 Update the hysteresis output with a new input value.
 
T_out getValue () const
 Get the current output level.
 
void setValue (T_in inputLevel)
 Forcefully update the internal state to the given level.
 

Private Attributes

T_out prevLevel = 0
 

Static Private Attributes

static constexpr T_in margin = (1ul << Bits) - 1ul
 
static constexpr T_in offset = Bits >= 1 ? 1ul << (Bits - 1) : 0
 
static constexpr T_in max_in = static_cast<T_in>(-1)
 
static constexpr T_out max_out = static_cast<T_out>(max_in >> Bits)
 

Member Function Documentation

◆ update()

template<uint8_t Bits, class T_in = uint16_t, class T_out = uint8_t>
bool update ( T_in inputLevel)
inline

Update the hysteresis output with a new input value.

Parameters
inputLevelThe input to calculate the output level from.
Return values
trueThe output level has changed.
falseThe output level is still the same.

Definition at line 49 of file Hysteresis.hpp.

◆ getValue()

template<uint8_t Bits, class T_in = uint16_t, class T_out = uint8_t>
T_out getValue ( ) const
inline

Get the current output level.

Returns
The output level.

Definition at line 65 of file Hysteresis.hpp.

◆ setValue()

template<uint8_t Bits, class T_in = uint16_t, class T_out = uint8_t>
void setValue ( T_in inputLevel)
inline

Forcefully update the internal state to the given level.

Definition at line 70 of file Hysteresis.hpp.

Member Data Documentation

◆ prevLevel

template<uint8_t Bits, class T_in = uint16_t, class T_out = uint8_t>
T_out prevLevel = 0
private

Definition at line 73 of file Hysteresis.hpp.

◆ margin

template<uint8_t Bits, class T_in = uint16_t, class T_out = uint8_t>
constexpr T_in margin = (1ul << Bits) - 1ul
staticconstexprprivate

Definition at line 74 of file Hysteresis.hpp.

◆ offset

template<uint8_t Bits, class T_in = uint16_t, class T_out = uint8_t>
constexpr T_in offset = Bits >= 1 ? 1ul << (Bits - 1) : 0
staticconstexprprivate

Definition at line 75 of file Hysteresis.hpp.

◆ max_in

template<uint8_t Bits, class T_in = uint16_t, class T_out = uint8_t>
constexpr T_in max_in = static_cast<T_in>(-1)
staticconstexprprivate

Definition at line 76 of file Hysteresis.hpp.

◆ max_out

template<uint8_t Bits, class T_in = uint16_t, class T_out = uint8_t>
constexpr T_out max_out = static_cast<T_out>(max_in >> Bits)
staticconstexprprivate

Definition at line 77 of file Hysteresis.hpp.


The documentation for this class was generated from the following file: