Potentiometer with EWMA smoothing, calibration and deadband.
More...
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>
|
| | 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)
|
| |
◆ Pot()
| sbl::control::input::Pot::Pot |
( |
const PotConfig & |
config = {} | ) |
|
|
inlineexplicit |
Construct with a smoothing strength and a deadband.
- Parameters
-
Definition at line 53 of file pot.hpp.
◆ update()
| void sbl::control::input::Pot::update |
( |
uint16_t |
raw | ) |
|
|
inline |
◆ 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
-
| buffer | DMA scan buffer |
| channel_index | Index 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 |
◆ 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()
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 |
The documentation for this class was generated from the following file: