Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
sbl::control::input::Pot Class Reference

Potentiometer with EWMA smoothing, calibration and deadband. More...

Detailed Description

Potentiometer with EWMA smoothing, calibration and deadband.

No hardware I/O.

Context
update() and update_dma() may run in an ISR; call them from exactly one context. changed() reads and clears its flag without masking interrupts, so a change that update() makes in an ISR during that call can be lost.

Definition at line 47 of file pot.hpp.

#include <pot.hpp>

Public Member Functions

 Pot (const PotConfig &config={})
 Construct with a smoothing strength and a deadband.
 
void update (uint16_t raw)
 Feed a new raw ADC sample through EWMA -> calibration -> deadband.
 
void update_dma (const uint16_t *buffer, uint8_t channel_index)
 Read one channel from a DMA scan buffer and update.
 
float value () const
 Stable (deadbanded) value in [0, 1].
 
float smoothed () const
 Calibrated, smoothed value in [0, 1] - no deadband.
 
uint16_t raw () const
 Last raw (unfiltered) ADC count - for calibration routines.
 
void set_calibration (PotCalibration cal)
 Apply two-point calibration.
 
bool changed ()
 True if value moved past deadband since last check.
 
void set_deadband (float deadband)
 Override the deadband threshold, in the [0, 1] output (default: 0.001)
 
void reset ()
 Reset all state (filter, stable value, changed flag)
 

Constructor & Destructor Documentation

◆ Pot()

sbl::control::input::Pot::Pot ( const PotConfig &  config = {})
inlineexplicit

Construct with a smoothing strength and a deadband.

Parameters
configSettings; the defaults are Smoothing::Medium and a 0.001 deadband

Definition at line 53 of file pot.hpp.

Member Function Documentation

◆ update()

void sbl::control::input::Pot::update ( uint16_t  raw)
inline

Feed a new raw ADC sample through EWMA -> calibration -> deadband.

Parameters
rawADC sample, 0 to 65535

Definition at line 60 of file pot.hpp.

References raw(), smoothed(), and sbl::control::input::Ewma::update().

Referenced by update_dma().

◆ update_dma()

void sbl::control::input::Pot::update_dma ( const uint16_t *  buffer,
uint8_t  channel_index 
)
inline

Read one channel from a DMA scan buffer and update.

Parameters
bufferDMA scan buffer
channel_indexIndex of this pot's channel in the buffer
Context
ISR-safe, from the one context that calls update().

Definition at line 82 of file pot.hpp.

References update().

◆ value()

float sbl::control::input::Pot::value ( ) const
inline

Stable (deadbanded) value in [0, 1].

Definition at line 87 of file pot.hpp.

◆ smoothed()

float sbl::control::input::Pot::smoothed ( ) const
inline

Calibrated, smoothed value in [0, 1] - no deadband.

Use for parameters driven unconditionally (no changed() gate): full resolution, no deadband quantization steps.

Definition at line 95 of file pot.hpp.

References sbl::control::input::PotCalibration::normalize(), and sbl::control::input::Ewma::value().

Referenced by update().

◆ raw()

uint16_t sbl::control::input::Pot::raw ( ) const
inline

Last raw (unfiltered) ADC count - for calibration routines.

Definition at line 101 of file pot.hpp.

Referenced by update().

◆ set_calibration()

void sbl::control::input::Pot::set_calibration ( PotCalibration  cal)
inline

Apply two-point calibration.

Definition at line 104 of file pot.hpp.

◆ changed()

bool sbl::control::input::Pot::changed ( )
inline

True if value moved past deadband since last check.

Resets the flag on read - call once per update cycle.

Definition at line 111 of file pot.hpp.

◆ set_deadband()

void sbl::control::input::Pot::set_deadband ( float  deadband)
inline

Override the deadband threshold, in the [0, 1] output (default: 0.001)

Definition at line 118 of file pot.hpp.

◆ reset()

void sbl::control::input::Pot::reset ( )
inline

Reset all state (filter, stable value, changed flag)

Definition at line 121 of file pot.hpp.

References sbl::control::input::Ewma::reset().


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