29#ifndef SBL_COMPONENTS_CONTROL_POT_HPP_
30#define SBL_COMPONENTS_CONTROL_POT_HPP_
53 : input_(config.smoothing), deadband_(config.deadband),
54 stable_value_(0), changed_(false) {}
68 uint16_t smoothed = input_.
value();
71 bool now_above = smoothed > pickup_target_;
72 bool crossed = (pickup_above_ && !now_above) ||
73 (!pickup_above_ && now_above);
76 int32_t dist =
static_cast<int32_t
>(smoothed) -
77 static_cast<int32_t
>(pickup_target_);
78 if (dist < 0) dist = -dist;
79 if (crossed ||
static_cast<uint16_t
>(dist) <= deadband_) {
80 pickup_armed_ =
false;
81 stable_value_ = smoothed;
87 int32_t delta =
static_cast<int32_t
>(smoothed) -
static_cast<int32_t
>(stable_value_);
88 if (delta < 0) delta = -delta;
90 if (
static_cast<uint16_t
>(delta) >= deadband_) {
91 stable_value_ = smoothed;
97 uint16_t
value()
const {
return stable_value_; }
100 uint16_t
raw()
const {
return input_.
raw(); }
109 int32_t
scaled(int32_t min, int32_t max)
const {
110 int64_t v = stable_value_;
111 return static_cast<int32_t
>(min + (v * (max - min)) / 65535);
129 return static_cast<int32_t
>(min + (v * (max - min)) / 65535);
156 uint16_t smoothed = input_.
value();
157 int32_t dist =
static_cast<int32_t
>(smoothed) -
158 static_cast<int32_t
>(target);
159 if (dist < 0) dist = -dist;
162 if (
static_cast<uint16_t
>(dist) <= deadband_) {
163 stable_value_ = smoothed;
167 pickup_target_ = target;
168 pickup_above_ = smoothed > target;
169 pickup_armed_ =
true;
170 stable_value_ = target;
184 pickup_armed_ =
false;
190 uint16_t stable_value_;
191 uint16_t pickup_target_ = 0;
193 bool pickup_armed_ =
false;
194 bool pickup_above_ =
false;
Potentiometer with EWMA smoothing, deadband, and change detection.
bool picked_up() const
True if knob has caught up (or pickup was never armed)
Pot(const PotConfig &config={})
void clear_pickup()
Cancel pickup, resume normal tracking immediately.
uint16_t value() const
Current stable (deadbanded) value (0-65535)
int32_t scaled_curved(int32_t min, int32_t max, uint16_t curve=sbl::dsp::curve::Log) const
Map stable value with curve shaping.
uint16_t raw() const
Last raw (unfiltered) ADC value.
void set_pickup(uint16_t target)
Arm pickup mode — freeze output until knob crosses target.
void update(uint16_t raw)
Feed a new raw ADC sample through EWMA → deadband check.
void reset()
Reset all state (filter, stable value, changed flag, pickup)
int32_t scaled(int32_t min, int32_t max) const
Map stable value to an output range (linear)
bool changed()
True if value moved past deadband since last check.
Smoothing
Smoothing presets for CvInput EWMA filter.
@ Medium
alpha=1/8, settles in ~24 samples (pots, knobs)
static constexpr uint16_t Log
Root namespace for all Sound Byte Libs functionality.
static uint16_t warp(uint16_t phase, uint16_t curve)