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

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

Detailed Description

Potentiometer with EWMA smoothing, calibration and deadband.

Note
All public methods are ISR-safe — pure state machine, no hardware I/O; 32-bit stores are atomic on Cortex-M. Call update from exactly one context.

Definition at line 44 of file pot.hpp.

#include <pot.hpp>

Public Member Functions

 Pot (const PotConfig &config={})
 
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 (ISR-safe)
 
float value () const
 Stable (deadbanded) value in su [0, 1].
 
float smoothed () const
 Calibrated, smoothed value in su [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_su)
 Override deadband threshold in su (default: 0.001)
 
void reset ()
 Reset all state (filter, stable value, changed flag)
 

Constructor & Destructor Documentation

◆ Pot()

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

Definition at line 46 of file pot.hpp.

Member Function Documentation

◆ update()

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

Feed a new raw ADC sample through EWMA → calibration → deadband.

Definition at line 51 of file pot.hpp.

References raw(), smoothed(), and sbl::primitives::math::Ewma::update().

Referenced by update_dma().

◆ update_dma()

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

Read one channel from a DMA scan buffer and update (ISR-safe)

Definition at line 65 of file pot.hpp.

References update().

◆ value()

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

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

Definition at line 70 of file pot.hpp.

◆ smoothed()

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

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

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

Definition at line 78 of file pot.hpp.

References sbl::components::input::PotCalibration::kOutputMax, sbl::components::input::PotCalibration::normalize(), and sbl::primitives::math::Ewma::value().

Referenced by update().

◆ raw()

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

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

Definition at line 84 of file pot.hpp.

Referenced by update().

◆ set_calibration()

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

Apply two-point calibration.

Definition at line 87 of file pot.hpp.

◆ changed()

bool sbl::components::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 94 of file pot.hpp.

◆ set_deadband()

void sbl::components::input::Pot::set_deadband ( float  deadband_su)
inline

Override deadband threshold in su (default: 0.001)

Definition at line 101 of file pot.hpp.

◆ reset()

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

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

Definition at line 104 of file pot.hpp.

References sbl::primitives::math::Ewma::reset().


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