Make debounce delay configurable via on-screen menu

This commit is contained in:
Frederik Walk 2023-11-06 00:36:56 +01:00
parent f66420b2a0
commit e8c3e5d697
7 changed files with 42 additions and 2 deletions

View File

@ -103,6 +103,7 @@ class Drum {
void updateInputState(Utils::InputState &input_state); void updateInputState(Utils::InputState &input_state);
void setDebounceDelay(const uint16_t delay);
void setThresholds(const Config::Thresholds &thresholds); void setThresholds(const Config::Thresholds &thresholds);
void setThresholdScaleLevel(const uint8_t threshold_scale_level); void setThresholdScaleLevel(const uint8_t threshold_scale_level);
}; };

View File

@ -24,6 +24,7 @@ class Menu {
TriggerThresholdDonRight, TriggerThresholdDonRight,
TriggerThresholdKaRight, TriggerThresholdKaRight,
TriggerThresholdScaleLevel, TriggerThresholdScaleLevel,
DebounceDelay,
LedBrightness, LedBrightness,
Reset, Reset,
Bootsel, Bootsel,
@ -54,6 +55,7 @@ class Menu {
GotoPageTriggerThresholdDonRight, GotoPageTriggerThresholdDonRight,
GotoPageTriggerThresholdKaRight, GotoPageTriggerThresholdKaRight,
GotoPageTriggerThresholdScaleLevel, GotoPageTriggerThresholdScaleLevel,
GotoPageDebounceDelay,
GotoPageLedBrightness, GotoPageLedBrightness,
GotoPageReset, GotoPageReset,
GotoPageBootsel, GotoPageBootsel,
@ -72,6 +74,7 @@ class Menu {
SetTriggerThresholdDonRight, SetTriggerThresholdDonRight,
SetTriggerThresholdKaRight, SetTriggerThresholdKaRight,
SetTriggerThresholdScaleLevel, SetTriggerThresholdScaleLevel,
SetDebounceDelay,
SetLedBrightness, SetLedBrightness,
DoRebootToBootsel, DoRebootToBootsel,

View File

@ -22,9 +22,11 @@ class SettingsStore {
Peripherals::Drum::Config::Thresholds trigger_thresholds; Peripherals::Drum::Config::Thresholds trigger_thresholds;
uint8_t trigger_threshold_scale_level; uint8_t trigger_threshold_scale_level;
uint8_t led_brightness; uint8_t led_brightness;
uint16_t debounce_delay;
uint8_t _padding[m_store_size - sizeof(uint8_t) - sizeof(usb_mode_t) - uint8_t _padding[m_store_size - sizeof(uint8_t) - sizeof(usb_mode_t) -
sizeof(Peripherals::Drum::Config::Thresholds) - sizeof(uint8_t) - sizeof(uint8_t)]; sizeof(Peripherals::Drum::Config::Thresholds) - sizeof(uint8_t) - sizeof(uint8_t) -
sizeof(uint16_t)];
}; };
static_assert(sizeof(Storecache) == m_store_size); static_assert(sizeof(Storecache) == m_store_size);
@ -57,6 +59,9 @@ class SettingsStore {
void setLedBrightness(const uint8_t brightness); void setLedBrightness(const uint8_t brightness);
uint8_t getLedBrightness(); uint8_t getLedBrightness();
void setDebounceDelay(const uint16_t delay);
uint16_t getDebounceDelay();
void scheduleReboot(const bool bootsel = false); void scheduleReboot(const bool bootsel = false);
void store(); void store();

View File

@ -129,6 +129,7 @@ int main() {
ctrl_message = {ControlCommand::SetLedBrightness, {.brightness = settings_store->getLedBrightness()}}; ctrl_message = {ControlCommand::SetLedBrightness, {.brightness = settings_store->getLedBrightness()}};
queue_add_blocking(&control_queue, &ctrl_message); queue_add_blocking(&control_queue, &ctrl_message);
drum.setDebounceDelay(settings_store->getDebounceDelay());
drum.setThresholds(settings_store->getTriggerThresholds()); drum.setThresholds(settings_store->getTriggerThresholds());
drum.setThresholdScaleLevel(settings_store->getTriggerThresholdScaleLevel()); drum.setThresholdScaleLevel(settings_store->getTriggerThresholdScaleLevel());
}; };

View File

@ -133,6 +133,8 @@ void Drum::updateInputState(Utils::InputState &input_state) {
input_state.drum.ka_right.triggered = m_pads.at(Id::KA_RIGHT).getState(); input_state.drum.ka_right.triggered = m_pads.at(Id::KA_RIGHT).getState();
} }
void Drum::setDebounceDelay(const uint16_t delay) { m_config.debounce_delay_ms = delay; }
void Drum::setThresholds(const Config::Thresholds &thresholds) { m_config.trigger_thresholds = thresholds; } void Drum::setThresholds(const Config::Thresholds &thresholds) { m_config.trigger_thresholds = thresholds; }
void Drum::setThresholdScaleLevel(const uint8_t threshold_scale_level) { void Drum::setThresholdScaleLevel(const uint8_t threshold_scale_level) {

View File

@ -9,6 +9,7 @@ const std::map<Menu::Page, const Menu::Descriptor> Menu::descriptors = {
{{"Mode", Menu::Descriptor::Action::GotoPageDeviceMode}, // {{"Mode", Menu::Descriptor::Action::GotoPageDeviceMode}, //
{"Brightness", Menu::Descriptor::Action::GotoPageLedBrightness}, // {"Brightness", Menu::Descriptor::Action::GotoPageLedBrightness}, //
{"Sensitvty", Menu::Descriptor::Action::GotoPageTriggerThreshold}, // {"Sensitvty", Menu::Descriptor::Action::GotoPageTriggerThreshold}, //
{"DebnceDly", Menu::Descriptor::Action::GotoPageTriggerThreshold}, //
{"Reset", Menu::Descriptor::Action::GotoPageReset}, // {"Reset", Menu::Descriptor::Action::GotoPageReset}, //
{"BOOTSEL", Menu::Descriptor::Action::GotoPageBootsel}}, // {"BOOTSEL", Menu::Descriptor::Action::GotoPageBootsel}}, //
0}}, // 0}}, //
@ -64,7 +65,13 @@ const std::map<Menu::Page, const Menu::Descriptor> Menu::descriptors = {
{Menu::Descriptor::Type::Value, // {Menu::Descriptor::Type::Value, //
"Sensitivity Scale Lvl", // "Sensitivity Scale Lvl", //
{{"", Menu::Descriptor::Action::SetTriggerThresholdScaleLevel}}, // {{"", Menu::Descriptor::Action::SetTriggerThresholdScaleLevel}}, //
UINT8_MAX}}, // UINT8_MAX}},
{Menu::Page::DebounceDelay, //
{Menu::Descriptor::Type::Value, //
"Debounce Delay (ms)", //
{{"", Menu::Descriptor::Action::SetDebounceDelay}}, //
255}},
{Menu::Page::LedBrightness, // {Menu::Page::LedBrightness, //
{Menu::Descriptor::Type::Value, // {Menu::Descriptor::Type::Value, //
@ -197,6 +204,9 @@ uint16_t Menu::getCurrentSelection(Menu::Page page) {
case Page::TriggerThresholdScaleLevel: case Page::TriggerThresholdScaleLevel:
return m_store->getTriggerThresholdScaleLevel(); return m_store->getTriggerThresholdScaleLevel();
break; break;
case Page::DebounceDelay:
return m_store->getDebounceDelay();
break;
case Page::LedBrightness: case Page::LedBrightness:
return m_store->getLedBrightness(); return m_store->getLedBrightness();
break; break;
@ -247,6 +257,9 @@ void Menu::performSelectionAction(Menu::Descriptor::Action action) {
case Descriptor::Action::GotoPageLedBrightness: case Descriptor::Action::GotoPageLedBrightness:
gotoPage(Page::LedBrightness); gotoPage(Page::LedBrightness);
break; break;
case Descriptor::Action::GotoPageDebounceDelay:
gotoPage(Page::DebounceDelay);
break;
case Descriptor::Action::GotoPageReset: case Descriptor::Action::GotoPageReset:
gotoPage(Page::Reset); gotoPage(Page::Reset);
break; break;
@ -292,6 +305,9 @@ void Menu::performSelectionAction(Menu::Descriptor::Action action) {
case Descriptor::Action::SetTriggerThresholdScaleLevel: case Descriptor::Action::SetTriggerThresholdScaleLevel:
gotoParent(); gotoParent();
break; break;
case Descriptor::Action::SetDebounceDelay:
gotoParent();
break;
case Descriptor::Action::SetLedBrightness: case Descriptor::Action::SetLedBrightness:
gotoParent(); gotoParent();
break; break;
@ -341,6 +357,9 @@ void Menu::performValueAction(Menu::Descriptor::Action action, uint16_t value) {
case Descriptor::Action::SetTriggerThresholdScaleLevel: case Descriptor::Action::SetTriggerThresholdScaleLevel:
m_store->setTriggerThresholdScaleLevel(value); m_store->setTriggerThresholdScaleLevel(value);
break; break;
case Descriptor::Action::SetDebounceDelay:
m_store->setDebounceDelay(value);
break;
case Descriptor::Action::SetLedBrightness: case Descriptor::Action::SetLedBrightness:
m_store->setLedBrightness(value); m_store->setLedBrightness(value);
break; break;

View File

@ -16,6 +16,7 @@ SettingsStore::SettingsStore()
Config::Default::drum_config.trigger_thresholds, Config::Default::drum_config.trigger_thresholds,
Config::Default::drum_config.trigger_threshold_scale_level, Config::Default::drum_config.trigger_threshold_scale_level,
Config::Default::led_config.brightness, Config::Default::led_config.brightness,
Config::Default::drum_config.debounce_delay_ms,
{}}), {}}),
m_dirty(true), m_scheduled_reboot(RebootType::None) { m_dirty(true), m_scheduled_reboot(RebootType::None) {
uint32_t current_page = m_flash_offset + m_flash_size - m_store_size; uint32_t current_page = m_flash_offset + m_flash_size - m_store_size;
@ -74,6 +75,14 @@ void SettingsStore::setLedBrightness(const uint8_t brightness) {
} }
uint8_t SettingsStore::getLedBrightness() { return m_store_cache.led_brightness; } uint8_t SettingsStore::getLedBrightness() { return m_store_cache.led_brightness; }
void SettingsStore::setDebounceDelay(const uint16_t delay) {
if (m_store_cache.debounce_delay != delay) {
m_store_cache.debounce_delay = delay;
m_dirty = true;
}
}
uint16_t SettingsStore::getDebounceDelay() { return m_store_cache.debounce_delay; }
void SettingsStore::store() { void SettingsStore::store() {
if (m_dirty) { if (m_dirty) {
multicore_lockout_start_blocking(); multicore_lockout_start_blocking();