This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
Public Member Functions | Private Attributes | Static Private Attributes | List of all members
Hysteresis< BITS, T_in, T_out > Class Template Reference

A class for applying hysteresis to a given input. More...

#include <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. More...
 
T_out getValue () const
 Get the current output level. More...
 

Private Attributes

T_out prevLevel = 0
 

Static Private Attributes

constexpr static T_in margin = (1 << BITS) - 1
 
constexpr static T_in offset = 1 << (BITS - 1)
 
constexpr static T_in max_in = -1
 
constexpr static T_out max_out = static_cast<T_out>(max_in >> BITS)
 

Detailed Description

template<uint8_t BITS, class T_in = uint16_t, class T_out = uint8_t>
class 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

7 ┌───◄───┬───
o 6 ┌───◄───┼───►───┘
u 5 ┌───◄───┼───►───┘
t 4 ┌───◄───┼───►───┘
p 3 ┌───◄───┼───►───┘
u 2 ┌───◄───┼───►───┘
t 1 ┌───◄───┼───►───┘
0 ────┴───►───┘
0 128 256 384 512 640 768 896 1023
i n p u t
Template Parameters
BITSThe number of bits to decrease in resolution. Increasing this number will result in a decrease in fluctuations.

Definition at line 33 of file Hysteresis.hpp.

Member Function Documentation

◆ update()

template<uint8_t BITS, class T_in = uint16_t, class T_out = uint8_t>
bool Hysteresis< BITS, T_in, T_out >::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 45 of file Hysteresis.hpp.

◆ getValue()

template<uint8_t BITS, class T_in = uint16_t, class T_out = uint8_t>
T_out Hysteresis< BITS, T_in, T_out >::getValue ( ) const
inline

Get the current output level.

Returns
The output level.

Definition at line 61 of file Hysteresis.hpp.

Member Data Documentation

◆ prevLevel

template<uint8_t BITS, class T_in = uint16_t, class T_out = uint8_t>
T_out Hysteresis< BITS, T_in, T_out >::prevLevel = 0
private

Definition at line 64 of file Hysteresis.hpp.

◆ margin

template<uint8_t BITS, class T_in = uint16_t, class T_out = uint8_t>
constexpr static T_in Hysteresis< BITS, T_in, T_out >::margin = (1 << BITS) - 1
staticconstexprprivate

Definition at line 65 of file Hysteresis.hpp.

◆ offset

template<uint8_t BITS, class T_in = uint16_t, class T_out = uint8_t>
constexpr static T_in Hysteresis< BITS, T_in, T_out >::offset = 1 << (BITS - 1)
staticconstexprprivate

Definition at line 66 of file Hysteresis.hpp.

◆ max_in

template<uint8_t BITS, class T_in = uint16_t, class T_out = uint8_t>
constexpr static T_in Hysteresis< BITS, T_in, T_out >::max_in = -1
staticconstexprprivate

Definition at line 67 of file Hysteresis.hpp.

◆ max_out

template<uint8_t BITS, class T_in = uint16_t, class T_out = uint8_t>
constexpr static T_out Hysteresis< BITS, T_in, T_out >::max_out = static_cast<T_out>(max_in >> BITS)
staticconstexprprivate

Definition at line 68 of file Hysteresis.hpp.


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