diff --git a/include/peripherals/Drum.h b/include/peripherals/Drum.h index eecde3f..9bfbdcd 100644 --- a/include/peripherals/Drum.h +++ b/include/peripherals/Drum.h @@ -103,6 +103,7 @@ class Drum { void updateInputState(Utils::InputState &input_state); + void setDebounceDelay(const uint16_t delay); void setThresholds(const Config::Thresholds &thresholds); void setThresholdScaleLevel(const uint8_t threshold_scale_level); }; diff --git a/include/utils/Menu.h b/include/utils/Menu.h index a286675..1d48de2 100644 --- a/include/utils/Menu.h +++ b/include/utils/Menu.h @@ -24,6 +24,7 @@ class Menu { TriggerThresholdDonRight, TriggerThresholdKaRight, TriggerThresholdScaleLevel, + DebounceDelay, LedBrightness, Reset, Bootsel, @@ -54,6 +55,7 @@ class Menu { GotoPageTriggerThresholdDonRight, GotoPageTriggerThresholdKaRight, GotoPageTriggerThresholdScaleLevel, + GotoPageDebounceDelay, GotoPageLedBrightness, GotoPageReset, GotoPageBootsel, @@ -72,6 +74,7 @@ class Menu { SetTriggerThresholdDonRight, SetTriggerThresholdKaRight, SetTriggerThresholdScaleLevel, + SetDebounceDelay, SetLedBrightness, DoRebootToBootsel, diff --git a/include/utils/SettingsStore.h b/include/utils/SettingsStore.h index 864974c..6d0aa7a 100644 --- a/include/utils/SettingsStore.h +++ b/include/utils/SettingsStore.h @@ -22,9 +22,11 @@ class SettingsStore { Peripherals::Drum::Config::Thresholds trigger_thresholds; uint8_t trigger_threshold_scale_level; uint8_t led_brightness; + uint16_t debounce_delay; 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); @@ -57,6 +59,9 @@ class SettingsStore { void setLedBrightness(const uint8_t brightness); uint8_t getLedBrightness(); + void setDebounceDelay(const uint16_t delay); + uint16_t getDebounceDelay(); + void scheduleReboot(const bool bootsel = false); void store(); diff --git a/src/main.cpp b/src/main.cpp index 02431e0..5816986 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -129,6 +129,7 @@ int main() { ctrl_message = {ControlCommand::SetLedBrightness, {.brightness = settings_store->getLedBrightness()}}; queue_add_blocking(&control_queue, &ctrl_message); + drum.setDebounceDelay(settings_store->getDebounceDelay()); drum.setThresholds(settings_store->getTriggerThresholds()); drum.setThresholdScaleLevel(settings_store->getTriggerThresholdScaleLevel()); }; diff --git a/src/peripherals/Drum.cpp b/src/peripherals/Drum.cpp index 5ae0b54..b07b8a1 100644 --- a/src/peripherals/Drum.cpp +++ b/src/peripherals/Drum.cpp @@ -133,6 +133,8 @@ void Drum::updateInputState(Utils::InputState &input_state) { 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::setThresholdScaleLevel(const uint8_t threshold_scale_level) { diff --git a/src/utils/Menu.cpp b/src/utils/Menu.cpp index 08fc3b1..a67a587 100644 --- a/src/utils/Menu.cpp +++ b/src/utils/Menu.cpp @@ -9,6 +9,7 @@ const std::map Menu::descriptors = { {{"Mode", Menu::Descriptor::Action::GotoPageDeviceMode}, // {"Brightness", Menu::Descriptor::Action::GotoPageLedBrightness}, // {"Sensitvty", Menu::Descriptor::Action::GotoPageTriggerThreshold}, // + {"DebnceDly", Menu::Descriptor::Action::GotoPageTriggerThreshold}, // {"Reset", Menu::Descriptor::Action::GotoPageReset}, // {"BOOTSEL", Menu::Descriptor::Action::GotoPageBootsel}}, // 0}}, // @@ -64,7 +65,13 @@ const std::map Menu::descriptors = { {Menu::Descriptor::Type::Value, // "Sensitivity Scale Lvl", // {{"", 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::Descriptor::Type::Value, // @@ -197,6 +204,9 @@ uint16_t Menu::getCurrentSelection(Menu::Page page) { case Page::TriggerThresholdScaleLevel: return m_store->getTriggerThresholdScaleLevel(); break; + case Page::DebounceDelay: + return m_store->getDebounceDelay(); + break; case Page::LedBrightness: return m_store->getLedBrightness(); break; @@ -247,6 +257,9 @@ void Menu::performSelectionAction(Menu::Descriptor::Action action) { case Descriptor::Action::GotoPageLedBrightness: gotoPage(Page::LedBrightness); break; + case Descriptor::Action::GotoPageDebounceDelay: + gotoPage(Page::DebounceDelay); + break; case Descriptor::Action::GotoPageReset: gotoPage(Page::Reset); break; @@ -292,6 +305,9 @@ void Menu::performSelectionAction(Menu::Descriptor::Action action) { case Descriptor::Action::SetTriggerThresholdScaleLevel: gotoParent(); break; + case Descriptor::Action::SetDebounceDelay: + gotoParent(); + break; case Descriptor::Action::SetLedBrightness: gotoParent(); break; @@ -341,6 +357,9 @@ void Menu::performValueAction(Menu::Descriptor::Action action, uint16_t value) { case Descriptor::Action::SetTriggerThresholdScaleLevel: m_store->setTriggerThresholdScaleLevel(value); break; + case Descriptor::Action::SetDebounceDelay: + m_store->setDebounceDelay(value); + break; case Descriptor::Action::SetLedBrightness: m_store->setLedBrightness(value); break; diff --git a/src/utils/SettingsStore.cpp b/src/utils/SettingsStore.cpp index a5a5aa6..73764e0 100644 --- a/src/utils/SettingsStore.cpp +++ b/src/utils/SettingsStore.cpp @@ -16,6 +16,7 @@ SettingsStore::SettingsStore() Config::Default::drum_config.trigger_thresholds, Config::Default::drum_config.trigger_threshold_scale_level, Config::Default::led_config.brightness, + Config::Default::drum_config.debounce_delay_ms, {}}), m_dirty(true), m_scheduled_reboot(RebootType::None) { 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; } +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() { if (m_dirty) { multicore_lockout_start_blocking();