Sound Byte Libs 29c5ff3
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
Public Member Functions | List of all members
sbl::components::control::Pot Class Reference

Potentiometer with EWMA smoothing, deadband, and change detection. More...

#include <pot.hpp>

Collaboration diagram for sbl::components::control::Pot:

Public Member Functions

 Pot (const PotConfig &config={})
 
void update (uint16_t raw)
 Feed a new raw ADC sample through EWMA → deadband check.
 
uint16_t value () const
 Current stable (deadbanded) value (0-65535)
 
uint16_t raw () const
 Last raw (unfiltered) ADC value.
 
int32_t scaled (int32_t min, int32_t max) const
 Map stable value to an output range (linear)
 
int32_t scaled_curved (int32_t min, int32_t max, uint16_t curve=sbl::dsp::curve::Log) const
 Map stable value with curve shaping.
 
bool changed ()
 True if value moved past deadband since last check.
 
void set_pickup (uint16_t target)
 Arm pickup mode — freeze output until knob crosses target.
 
bool picked_up () const
 True if knob has caught up (or pickup was never armed)
 
void clear_pickup ()
 Cancel pickup, resume normal tracking immediately.
 
void reset ()
 Reset all state (filter, stable value, changed flag, pickup)
 

Detailed Description

Potentiometer with EWMA smoothing, deadband, and change detection.

Note
All public methods are ISR-safe — pure state machine with no hardware I/O.

Definition at line 50 of file pot.hpp.

Constructor & Destructor Documentation

◆ Pot()

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

Definition at line 52 of file pot.hpp.

Member Function Documentation

◆ changed()

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

◆ clear_pickup()

void sbl::components::control::Pot::clear_pickup ( )
inline

Cancel pickup, resume normal tracking immediately.

Definition at line 177 of file pot.hpp.

◆ picked_up()

bool sbl::components::control::Pot::picked_up ( ) const
inline

True if knob has caught up (or pickup was never armed)

Definition at line 174 of file pot.hpp.

◆ raw()

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

Last raw (unfiltered) ADC value.

Definition at line 100 of file pot.hpp.

References sbl::components::cv::CvInput::raw().

Referenced by update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

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

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

Definition at line 180 of file pot.hpp.

References sbl::components::cv::CvInput::reset().

Here is the call graph for this function:

◆ scaled()

int32_t sbl::components::control::Pot::scaled ( int32_t  min,
int32_t  max 
) const
inline

Map stable value to an output range (linear)

Linear interpolation from [0, 65535] -> [min, max]. Uses int64_t intermediate to avoid overflow. For non-linear mapping (frequency, filter cutoff), see scaled_curved().

Definition at line 109 of file pot.hpp.

◆ scaled_curved()

int32_t sbl::components::control::Pot::scaled_curved ( int32_t  min,
int32_t  max,
uint16_t  curve = sbl::dsp::curve::Log 
) const
inline

Map stable value with curve shaping.

Applies ExpCurveWarp::warp() before scaling, useful for knob-friendly non-linear mapping (frequency, filter cutoff, gain).

Parameters
minOutput minimum (inclusive)
maxOutput maximum (inclusive)
curveShape preset or arbitrary value (see sbl::dsp::curve)
Returns
Scaled value in [min, max]

Definition at line 125 of file pot.hpp.

References sbl::dsp::ExpCurveWarp::warp().

Here is the call graph for this function:

◆ set_pickup()

void sbl::components::control::Pot::set_pickup ( uint16_t  target)
inline

Arm pickup mode — freeze output until knob crosses target.

The physical knob must cross target (a raw 0-65535 position) before stable_value_ resumes tracking. Until then, value(), scaled(), and scaled_curved() all return values based on target.

Use on mode switch: save the current knob position per-mode, then set_pickup(saved_position) when re-entering that mode.

Parameters
targetThe knob position (0-65535) that must be crossed

Definition at line 155 of file pot.hpp.

References sbl::components::cv::CvInput::value().

Here is the call graph for this function:

◆ update()

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

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

The EWMA filter smooths the raw value first. Then, if the smoothed value has moved more than deadband from the last stable value, we update the stable value and set the changed flag.

When pickup is armed, the EWMA filter tracks the physical position but stable_value_ stays frozen until the knob crosses the target.

Definition at line 66 of file pot.hpp.

References raw(), sbl::components::cv::CvInput::update(), and sbl::components::cv::CvInput::value().

Referenced by sbl::pot::read(), and sbl::pot::read_dma().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ value()

uint16_t sbl::components::control::Pot::value ( ) const
inline

Current stable (deadbanded) value (0-65535)

Definition at line 97 of file pot.hpp.

Referenced by sbl::pot::read(), and sbl::pot::read_dma().

Here is the caller graph for this function:

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