mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-11-29 16:06:57 -05:00
Additional debounce control parameters for rotary encoder settings (for bad/noisy encoders) (#2841)
* Added debounce control options for rotary encoder settings * ran format-code.sh to adjust whitespace --------- Co-authored-by: Robert McKay <robert.mckay@ubermorgen.land>
This commit is contained in:
parent
81afec9ea4
commit
bf18851b6b
8 changed files with 144 additions and 64 deletions
|
|
@ -234,6 +234,11 @@ struct data_t {
|
|||
|
||||
uint16_t UNUSED : 4;
|
||||
|
||||
// Encoder debounce parameters for noisy hardware
|
||||
uint8_t encoder_consecutive_hits; // Number of consecutive same-direction hits required (1-10)
|
||||
uint8_t encoder_cooldown_ms; // Cooldown period in ms after movement (0-255ms)
|
||||
uint8_t encoder_debounce_ms; // Debounce stability window in ms (4-32ms)
|
||||
|
||||
// Headphone volume in centibels.
|
||||
int16_t headphone_volume_cb;
|
||||
|
||||
|
|
@ -304,6 +309,10 @@ struct data_t {
|
|||
encoder_rate_multiplier(1),
|
||||
UNUSED(0),
|
||||
|
||||
encoder_consecutive_hits(3), // Default: 3 hits (Version 1 setting)
|
||||
encoder_cooldown_ms(20), // Default: 20ms (Version 1 setting)
|
||||
encoder_debounce_ms(16), // Default: 16ms stability window
|
||||
|
||||
headphone_volume_cb(-600),
|
||||
misc_config(),
|
||||
ui_config2(),
|
||||
|
|
@ -1121,6 +1130,38 @@ void set_encoder_dial_direction(bool v) {
|
|||
data->encoder_dial_direction = v;
|
||||
}
|
||||
|
||||
// Encoder debounce parameters for noisy hardware
|
||||
uint8_t encoder_consecutive_hits() {
|
||||
uint8_t v = data->encoder_consecutive_hits;
|
||||
if (v == 0) v = 3; // default to 3 if not set
|
||||
if (v > 10) v = 10; // cap at 10
|
||||
return v;
|
||||
}
|
||||
void set_encoder_consecutive_hits(uint8_t v) {
|
||||
if (v < 1) v = 1; // minimum 1
|
||||
if (v > 10) v = 10; // maximum 10
|
||||
data->encoder_consecutive_hits = v;
|
||||
}
|
||||
|
||||
uint8_t encoder_cooldown_ms() {
|
||||
return data->encoder_cooldown_ms;
|
||||
}
|
||||
void set_encoder_cooldown_ms(uint8_t v) {
|
||||
data->encoder_cooldown_ms = v;
|
||||
}
|
||||
|
||||
uint8_t encoder_debounce_ms() {
|
||||
uint8_t v = data->encoder_debounce_ms;
|
||||
if (v < 4) v = 16; // default to 16ms if not set or too low
|
||||
if (v > 32) v = 32; // cap at 32ms
|
||||
return v;
|
||||
}
|
||||
void set_encoder_debounce_ms(uint8_t v) {
|
||||
if (v < 4) v = 4; // minimum 4ms
|
||||
if (v > 32) v = 32; // maximum 32ms
|
||||
data->encoder_debounce_ms = v;
|
||||
}
|
||||
|
||||
// Recovery mode magic value storage
|
||||
static data_t* data_direct_access = reinterpret_cast<data_t*>(memory::map::backup_ram.base());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue