From ea99b764ce97b4f284a3a46a2a1097cfc4f4d999 Mon Sep 17 00:00:00 2001 From: jpirnay Date: Mon, 27 Apr 2026 14:38:20 +0200 Subject: [PATCH] Review changes --- src/activities/home/FileBrowserActivity.cpp | 4 - src/activities/reader/EpubReaderActivity.cpp | 93 ++++------ src/activities/reader/EpubReaderActivity.h | 1 + .../reader/EpubReaderFootnotesActivity.cpp | 47 ++--- .../reader/EpubReaderFootnotesActivity.h | 1 + src/activities/reader/MdReaderActivity.cpp | 7 + src/activities/reader/MdReaderActivity.h | 2 + .../reader/StarredPagesActivity.cpp | 14 -- src/activities/reader/TxtReaderActivity.cpp | 1 + src/activities/reader/XtcReaderActivity.cpp | 8 +- .../XtcReaderChapterSelectionActivity.cpp | 13 ++ src/activities/util/BmpViewerActivity.cpp | 34 ++-- src/main.cpp | 160 +++++++++--------- 13 files changed, 172 insertions(+), 213 deletions(-) diff --git a/src/activities/home/FileBrowserActivity.cpp b/src/activities/home/FileBrowserActivity.cpp index 5f68645c..59f15216 100644 --- a/src/activities/home/FileBrowserActivity.cpp +++ b/src/activities/home/FileBrowserActivity.cpp @@ -16,10 +16,6 @@ #include "components/UITheme.h" #include "fontIds.h" -namespace { -constexpr unsigned long GO_HOME_MS = 1000; -} // namespace - void sortFileList(std::vector& strs) { std::sort(begin(strs), end(strs), [](const std::string& str1, const std::string& str2) { // Directories first diff --git a/src/activities/reader/EpubReaderActivity.cpp b/src/activities/reader/EpubReaderActivity.cpp index ecc003a5..130c6e64 100644 --- a/src/activities/reader/EpubReaderActivity.cpp +++ b/src/activities/reader/EpubReaderActivity.cpp @@ -219,12 +219,14 @@ void EpubReaderActivity::loop() { } if (inputDrainGuard.shouldDrain(mappedInput)) { + buttonEvents.drain(); return; } if (automaticPageTurnActive) { if (mappedInput.wasReleased(MappedInputManager::Button::Confirm) || mappedInput.wasReleased(MappedInputManager::Button::Back)) { + buttonEvents.drain(); automaticPageTurnActive = false; // updates chapter title space to indicate page turn disabled requestUpdate(); @@ -260,36 +262,7 @@ void EpubReaderActivity::loop() { return; } if (ev.type == ButtonEventManager::PressType::Short) { - const int currentPage = section ? section->currentPage + 1 : 0; - const int totalPages = section ? section->pageCount : 0; - float bookProgress = 0.0f; - if (epub->getBookSize() > 0 && section && section->pageCount > 0) { - const float chapterProgress = - static_cast(section->currentPage) / static_cast(section->pageCount); - bookProgress = epub->calculateProgress(currentSpineIndex, chapterProgress) * 100.0f; - } - const int bookProgressPercent = clampPercent(static_cast(bookProgress + 0.5f)); - const bool isCurrentPageStarred = section && bookmarkStore.has(static_cast(currentSpineIndex), - static_cast(section->currentPage)); - ReaderUtils::enforceExitFullRefresh(renderer); - startActivityForResult( - std::make_unique( - renderer, mappedInput, epub->getTitle(), currentPage, totalPages, bookProgressPercent, - SETTINGS.orientation, !currentPageFootnotes.empty(), bookEmbeddedStyleOverride, - bookImageRenderingOverride, bookFontFamilyOverride, bookFontSizeOverride, SETTINGS.textDarkness, - !bookmarkStore.isEmpty(), isCurrentPageStarred), - [this](const ActivityResult& result) { - // Always apply orientation/darkness change even if the menu was cancelled - const auto& menu = std::get(result.data); - applyOrientation(menu.orientation); - applyTextDarkness(menu.textDarkness); - toggleAutoPageTurn(menu.pageTurnOption); - applyBookReaderOverrides(menu.embeddedStyleOverride, menu.imageRenderingOverride, menu.fontFamilyOverride, - menu.fontSizeOverride); - if (!result.isCancelled) { - onReaderMenuConfirm(static_cast(menu.action)); - } - }); + openReaderMenu(); return; } } @@ -1741,6 +1714,36 @@ bool EpubReaderActivity::drawCurrentPageToBuffer(const std::string& filePath, Gf return true; } +void EpubReaderActivity::openReaderMenu() { + const int currentPage = section ? section->currentPage + 1 : 0; + const int totalPages = section ? section->pageCount : 0; + float bookProgress = 0.0f; + if (epub->getBookSize() > 0 && section && section->pageCount > 0) { + const float chapterProgress = static_cast(section->currentPage) / static_cast(section->pageCount); + bookProgress = epub->calculateProgress(currentSpineIndex, chapterProgress) * 100.0f; + } + const int bookProgressPercent = clampPercent(static_cast(bookProgress + 0.5f)); + const bool isCurrentPageStarred = section && bookmarkStore.has(static_cast(currentSpineIndex), + static_cast(section->currentPage)); + ReaderUtils::enforceExitFullRefresh(renderer); + startActivityForResult( + std::make_unique( + renderer, mappedInput, epub->getTitle(), currentPage, totalPages, bookProgressPercent, SETTINGS.orientation, + !currentPageFootnotes.empty(), bookEmbeddedStyleOverride, bookImageRenderingOverride, bookFontFamilyOverride, + bookFontSizeOverride, SETTINGS.textDarkness, !bookmarkStore.isEmpty(), isCurrentPageStarred), + [this](const ActivityResult& result) { + const auto& menu = std::get(result.data); + applyOrientation(menu.orientation); + applyTextDarkness(menu.textDarkness); + toggleAutoPageTurn(menu.pageTurnOption); + applyBookReaderOverrides(menu.embeddedStyleOverride, menu.imageRenderingOverride, menu.fontFamilyOverride, + menu.fontSizeOverride); + if (!result.isCancelled) { + onReaderMenuConfirm(static_cast(menu.action)); + } + }); +} + void EpubReaderActivity::onButtonAction(const CrossPointSettings::BUTTON_ACTION action) { using BA = CrossPointSettings::BUTTON_ACTION; switch (action) { @@ -1859,35 +1862,7 @@ void EpubReaderActivity::onButtonAction(const CrossPointSettings::BUTTON_ACTION break; case BA::BTN_READER_MENU: if (epub) { - const int currentPage = section ? section->currentPage + 1 : 0; - const int totalPages = section ? section->pageCount : 0; - float bookProgress = 0.0f; - if (epub->getBookSize() > 0 && section && section->pageCount > 0) { - const float chapterProgress = - static_cast(section->currentPage) / static_cast(section->pageCount); - bookProgress = epub->calculateProgress(currentSpineIndex, chapterProgress) * 100.0f; - } - const int bookProgressPercent = clampPercent(static_cast(bookProgress + 0.5f)); - const bool isCurrentPageStarred = section && bookmarkStore.has(static_cast(currentSpineIndex), - static_cast(section->currentPage)); - ReaderUtils::enforceExitFullRefresh(renderer); - startActivityForResult( - std::make_unique( - renderer, mappedInput, epub->getTitle(), currentPage, totalPages, bookProgressPercent, - SETTINGS.orientation, !currentPageFootnotes.empty(), bookEmbeddedStyleOverride, - bookImageRenderingOverride, bookFontFamilyOverride, bookFontSizeOverride, SETTINGS.textDarkness, - !bookmarkStore.isEmpty(), isCurrentPageStarred), - [this](const ActivityResult& result) { - const auto& menu = std::get(result.data); - applyOrientation(menu.orientation); - applyTextDarkness(menu.textDarkness); - toggleAutoPageTurn(menu.pageTurnOption); - applyBookReaderOverrides(menu.embeddedStyleOverride, menu.imageRenderingOverride, menu.fontFamilyOverride, - menu.fontSizeOverride); - if (!result.isCancelled) { - onReaderMenuConfirm(static_cast(menu.action)); - } - }); + openReaderMenu(); } break; case BA::BTN_KOREADER_SYNC: diff --git a/src/activities/reader/EpubReaderActivity.h b/src/activities/reader/EpubReaderActivity.h index 42c8e332..6f95fd0e 100644 --- a/src/activities/reader/EpubReaderActivity.h +++ b/src/activities/reader/EpubReaderActivity.h @@ -166,6 +166,7 @@ class EpubReaderActivity final : public Activity { void toggleAutoPageTurn(uint8_t selectedPageTurnOption); void applyBookReaderOverrides(int8_t embeddedStyleOverride, int8_t imageRenderingOverride, int8_t fontFamilyOverride, int8_t fontSizeOverride); + void openReaderMenu(); bool getEffectiveEmbeddedStyle() const; uint8_t getEffectiveImageRendering() const; int getEffectiveReaderFontId() const; diff --git a/src/activities/reader/EpubReaderFootnotesActivity.cpp b/src/activities/reader/EpubReaderFootnotesActivity.cpp index 7db0e5bc..c042b0e2 100644 --- a/src/activities/reader/EpubReaderFootnotesActivity.cpp +++ b/src/activities/reader/EpubReaderFootnotesActivity.cpp @@ -38,50 +38,33 @@ void EpubReaderFootnotesActivity::loop() { if ((ev.button == MappedInputManager::Button::PageBack || ev.button == MappedInputManager::Button::Left) && ev.type == ButtonEventManager::PressType::Short) { - if (!footnotes.empty()) { - selectedIndex = (selectedIndex - 1 + footnotes.size()) % footnotes.size(); - requestUpdate(); - } + advanceSelection(-1); return; } if ((ev.button == MappedInputManager::Button::PageForward || ev.button == MappedInputManager::Button::Right) && ev.type == ButtonEventManager::PressType::Short) { - if (!footnotes.empty()) { - selectedIndex = (selectedIndex + 1) % footnotes.size(); - requestUpdate(); - } + advanceSelection(1); return; } } - buttonNavigator.onNextRelease([this] { - if (!footnotes.empty()) { - selectedIndex = (selectedIndex + 1) % footnotes.size(); - requestUpdate(); - } - }); + buttonNavigator.onNextRelease([this] { advanceSelection(1); }); - buttonNavigator.onPreviousRelease([this] { - if (!footnotes.empty()) { - selectedIndex = (selectedIndex - 1 + footnotes.size()) % footnotes.size(); - requestUpdate(); - } - }); + buttonNavigator.onPreviousRelease([this] { advanceSelection(-1); }); - buttonNavigator.onNextContinuous([this] { - if (!footnotes.empty()) { - selectedIndex = (selectedIndex + 1) % footnotes.size(); - requestUpdate(); - } - }); + buttonNavigator.onNextContinuous([this] { advanceSelection(1); }); - buttonNavigator.onPreviousContinuous([this] { - if (!footnotes.empty()) { - selectedIndex = (selectedIndex - 1 + footnotes.size()) % footnotes.size(); - requestUpdate(); - } - }); + buttonNavigator.onPreviousContinuous([this] { advanceSelection(-1); }); +} + +void EpubReaderFootnotesActivity::advanceSelection(int delta) { + if (footnotes.empty()) { + return; + } + const int n = static_cast(footnotes.size()); + selectedIndex = ((selectedIndex + delta) % n + n) % n; + requestUpdate(); } void EpubReaderFootnotesActivity::render(RenderLock&&) { diff --git a/src/activities/reader/EpubReaderFootnotesActivity.h b/src/activities/reader/EpubReaderFootnotesActivity.h index 7336d038..19a9ee8e 100644 --- a/src/activities/reader/EpubReaderFootnotesActivity.h +++ b/src/activities/reader/EpubReaderFootnotesActivity.h @@ -21,6 +21,7 @@ class EpubReaderFootnotesActivity final : public Activity { void render(RenderLock&&) override; private: + void advanceSelection(int delta); const std::vector& footnotes; int selectedIndex = 0; int scrollOffset = 0; diff --git a/src/activities/reader/MdReaderActivity.cpp b/src/activities/reader/MdReaderActivity.cpp index 1446ea10..ccd5330d 100644 --- a/src/activities/reader/MdReaderActivity.cpp +++ b/src/activities/reader/MdReaderActivity.cpp @@ -38,6 +38,8 @@ static std::string flattenHeadingText(const MdParser::ParsedLine& parsed) { void MdReaderActivity::onEnter() { Activity::onEnter(); + inputDrainGuard.arm(); + if (!txt) { return; } @@ -221,6 +223,11 @@ void MdReaderActivity::onExit() { } void MdReaderActivity::loop() { + if (inputDrainGuard.shouldDrain(mappedInput)) { + buttonEvents.drain(); + return; + } + ButtonEventManager::ButtonEvent ev; while (buttonEvents.consumeEvent(ev)) { if (ev.button == MappedInputManager::Button::Back) { diff --git a/src/activities/reader/MdReaderActivity.h b/src/activities/reader/MdReaderActivity.h index c262e9c6..614364bc 100644 --- a/src/activities/reader/MdReaderActivity.h +++ b/src/activities/reader/MdReaderActivity.h @@ -6,6 +6,7 @@ #include #include "CrossPointSettings.h" +#include "ReaderUtils.h" #include "activities/Activity.h" struct MdHeading { @@ -72,6 +73,7 @@ class MdReaderActivity final : public Activity { void assignHeadingPageNumbers(); int getHeadingIndexForOffset(size_t offset) const; void jumpToHeading(bool next); + ReaderUtils::InputDrainGuard inputDrainGuard; // Word-wrap a parsed markdown line into one or more RenderedLines. // Returns true if all content was emitted, false if truncated by maxLines. diff --git a/src/activities/reader/StarredPagesActivity.cpp b/src/activities/reader/StarredPagesActivity.cpp index 7fa12e1a..1fcd8715 100644 --- a/src/activities/reader/StarredPagesActivity.cpp +++ b/src/activities/reader/StarredPagesActivity.cpp @@ -109,20 +109,6 @@ void StarredPagesActivity::loop() { deleteSelected(); return; } - - if (totalItems > 0 && ev.button == MappedInputManager::Button::PageBack && - ev.type == ButtonEventManager::PressType::Short) { - selectorIndex = ButtonNavigator::previousIndex(selectorIndex, totalItems); - requestUpdate(); - return; - } - - if (totalItems > 0 && ev.button == MappedInputManager::Button::PageForward && - ev.type == ButtonEventManager::PressType::Short) { - selectorIndex = ButtonNavigator::nextIndex(selectorIndex, totalItems); - requestUpdate(); - return; - } } if (totalItems == 0) return; diff --git a/src/activities/reader/TxtReaderActivity.cpp b/src/activities/reader/TxtReaderActivity.cpp index 2daeb920..a88d6549 100644 --- a/src/activities/reader/TxtReaderActivity.cpp +++ b/src/activities/reader/TxtReaderActivity.cpp @@ -137,6 +137,7 @@ void TxtReaderActivity::onExit() { void TxtReaderActivity::loop() { if (inputDrainGuard.shouldDrain(mappedInput)) { + buttonEvents.drain(); return; } diff --git a/src/activities/reader/XtcReaderActivity.cpp b/src/activities/reader/XtcReaderActivity.cpp index fe14339e..f384339b 100644 --- a/src/activities/reader/XtcReaderActivity.cpp +++ b/src/activities/reader/XtcReaderActivity.cpp @@ -22,10 +22,6 @@ #include "XtcReaderChapterSelectionActivity.h" #include "fontIds.h" -namespace { -constexpr unsigned long goHomeMs = 1000; -} // namespace - void XtcReaderActivity::onEnter() { Activity::onEnter(); @@ -61,6 +57,7 @@ void XtcReaderActivity::onExit() { void XtcReaderActivity::loop() { if (inputDrainGuard.shouldDrain(mappedInput)) { + buttonEvents.drain(); return; } @@ -146,9 +143,6 @@ void XtcReaderActivity::loop() { } } else if (nextTriggered) { currentPage++; - if (currentPage >= xtc->getPageCount()) { - currentPage = xtc->getPageCount(); // Allow showing "End of book" - } requestUpdate(); } } diff --git a/src/activities/reader/XtcReaderChapterSelectionActivity.cpp b/src/activities/reader/XtcReaderChapterSelectionActivity.cpp index 7efedfc6..5f78ba9f 100644 --- a/src/activities/reader/XtcReaderChapterSelectionActivity.cpp +++ b/src/activities/reader/XtcReaderChapterSelectionActivity.cpp @@ -5,6 +5,7 @@ #include +#include "ButtonEventManager.h" #include "MappedInputManager.h" #include "components/UITheme.h" #include "fontIds.h" @@ -47,6 +48,10 @@ void XtcReaderChapterSelectionActivity::onEnter() { void XtcReaderChapterSelectionActivity::onExit() { Activity::onExit(); } void XtcReaderChapterSelectionActivity::loop() { + if (!xtc) { + return; + } + const int pageItems = getPageItems(); const int totalItems = static_cast(xtc->getChapters().size()); @@ -82,11 +87,19 @@ void XtcReaderChapterSelectionActivity::loop() { } buttonNavigator.onNextRelease([this, totalItems] { + if (ButtonEventManager::hasDoubleAction(MappedInputManager::Button::Right) || + ButtonEventManager::hasDoubleAction(MappedInputManager::Button::PageForward)) { + return; + } selectorIndex = ButtonNavigator::nextIndex(selectorIndex, totalItems); requestUpdate(); }); buttonNavigator.onPreviousRelease([this, totalItems] { + if (ButtonEventManager::hasDoubleAction(MappedInputManager::Button::Left) || + ButtonEventManager::hasDoubleAction(MappedInputManager::Button::PageBack)) { + return; + } selectorIndex = ButtonNavigator::previousIndex(selectorIndex, totalItems); requestUpdate(); }); diff --git a/src/activities/util/BmpViewerActivity.cpp b/src/activities/util/BmpViewerActivity.cpp index a2cb1ee0..c8592e35 100644 --- a/src/activities/util/BmpViewerActivity.cpp +++ b/src/activities/util/BmpViewerActivity.cpp @@ -388,7 +388,7 @@ void BmpViewerActivity::loop() { // Keep CPU awake/polling so 1st click works Activity::loop(); - // Long press BACK (1s+) goes to home screen + const bool toggleSupported = isBmpFile(filePath) ? bmpHasGreyscale : true; ButtonEventManager::ButtonEvent ev; while (buttonEvents.consumeEvent(ev)) { if (ev.button == MappedInputManager::Button::Back) { @@ -401,27 +401,25 @@ void BmpViewerActivity::loop() { return; } } - } - // Confirm: toggle between 1-bit B&W and 4-level grayscale display. - // For decoded images this always applies; for BMPs it only makes sense when the bitmap - // actually carries greyscale data (1-bit BMPs have nothing to toggle). - const bool toggleSupported = isBmpFile(filePath) ? bmpHasGreyscale : true; - if (toggleSupported && mappedInput.wasReleased(MappedInputManager::Button::Confirm)) { - toggleDisplayMode(); - return; - } + if (ev.button == MappedInputManager::Button::Confirm && ev.type == ButtonEventManager::PressType::Short) { + if (toggleSupported) { + toggleDisplayMode(); + } + return; + } #ifdef ENABLE_IMAGE_DITHERING_EXTENSION - if (!isBmpFile(filePath) && grayscaleDisplay && mappedInput.wasReleased(MappedInputManager::Button::Left)) { - cycleDitherMode(); - return; - } + if (ev.button == MappedInputManager::Button::Left && ev.type == ButtonEventManager::PressType::Short && + !isBmpFile(filePath) && grayscaleDisplay) { + cycleDitherMode(); + return; + } #endif - // Next/Right button: set this image as the sleep screen - if (mappedInput.wasReleased(MappedInputManager::Button::Right)) { - setAsSleepScreen(); - return; + if (ev.button == MappedInputManager::Button::Right && ev.type == ButtonEventManager::PressType::Short) { + setAsSleepScreen(); + return; + } } } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 0523df4f..90f500c8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -388,90 +388,92 @@ void loop() { { using BA = CrossPointSettings::BUTTON_ACTION; using B = MappedInputManager::Button; + auto actionFor = [&](const ButtonEventManager::ButtonEvent& ev) -> uint8_t { + switch (ev.button) { + case B::Back: + switch (ev.type) { + case ButtonEventManager::PressType::Short: + return SETTINGS.btnShortBack; + case ButtonEventManager::PressType::Double: + return SETTINGS.btnDoubleBack; + case ButtonEventManager::PressType::Long: + return SETTINGS.btnLongBack; + } + break; + case B::Confirm: + switch (ev.type) { + case ButtonEventManager::PressType::Short: + return SETTINGS.btnShortConfirm; + case ButtonEventManager::PressType::Double: + return SETTINGS.btnDoubleConfirm; + case ButtonEventManager::PressType::Long: + return SETTINGS.btnLongConfirm; + } + break; + case B::Left: + switch (ev.type) { + case ButtonEventManager::PressType::Short: + return SETTINGS.btnShortLeft; + case ButtonEventManager::PressType::Double: + return SETTINGS.btnDoubleLeft; + case ButtonEventManager::PressType::Long: + return SETTINGS.btnLongLeft; + } + break; + case B::Right: + switch (ev.type) { + case ButtonEventManager::PressType::Short: + return SETTINGS.btnShortRight; + case ButtonEventManager::PressType::Double: + return SETTINGS.btnDoubleRight; + case ButtonEventManager::PressType::Long: + return SETTINGS.btnLongRight; + } + break; + case B::PageBack: + switch (ev.type) { + case ButtonEventManager::PressType::Short: + return SETTINGS.btnShortPageBack; + case ButtonEventManager::PressType::Double: + return SETTINGS.btnDoublePageBack; + case ButtonEventManager::PressType::Long: + return SETTINGS.btnLongPageBack; + } + break; + case B::PageForward: + switch (ev.type) { + case ButtonEventManager::PressType::Short: + return SETTINGS.btnShortPageForward; + case ButtonEventManager::PressType::Double: + return SETTINGS.btnDoublePageForward; + case ButtonEventManager::PressType::Long: + return SETTINGS.btnLongPageForward; + } + break; + case B::Power: + switch (ev.type) { + case ButtonEventManager::PressType::Short: + return SETTINGS.btnShortPower; + case ButtonEventManager::PressType::Double: + return SETTINGS.btnDoublePower; + case ButtonEventManager::PressType::Long: + return SETTINGS.btnLongPower; + } + break; + default: + break; // Up/Down have no FSMs — ButtonEventManager never emits these + } + return BA::BTN_DEFAULT; + }; ButtonEventManager::ButtonEvent ev; std::vector defaultEvents; defaultEvents.reserve(8); while (buttonEventManager.consumeEvent(ev)) { - auto actionFor = [&](B btn) -> uint8_t { - switch (btn) { - case B::Back: - switch (ev.type) { - case ButtonEventManager::PressType::Short: - return SETTINGS.btnShortBack; - case ButtonEventManager::PressType::Double: - return SETTINGS.btnDoubleBack; - case ButtonEventManager::PressType::Long: - return SETTINGS.btnLongBack; - } - break; - case B::Confirm: - switch (ev.type) { - case ButtonEventManager::PressType::Short: - return SETTINGS.btnShortConfirm; - case ButtonEventManager::PressType::Double: - return SETTINGS.btnDoubleConfirm; - case ButtonEventManager::PressType::Long: - return SETTINGS.btnLongConfirm; - } - break; - case B::Left: - switch (ev.type) { - case ButtonEventManager::PressType::Short: - return SETTINGS.btnShortLeft; - case ButtonEventManager::PressType::Double: - return SETTINGS.btnDoubleLeft; - case ButtonEventManager::PressType::Long: - return SETTINGS.btnLongLeft; - } - break; - case B::Right: - switch (ev.type) { - case ButtonEventManager::PressType::Short: - return SETTINGS.btnShortRight; - case ButtonEventManager::PressType::Double: - return SETTINGS.btnDoubleRight; - case ButtonEventManager::PressType::Long: - return SETTINGS.btnLongRight; - } - break; - case B::PageBack: - switch (ev.type) { - case ButtonEventManager::PressType::Short: - return SETTINGS.btnShortPageBack; - case ButtonEventManager::PressType::Double: - return SETTINGS.btnDoublePageBack; - case ButtonEventManager::PressType::Long: - return SETTINGS.btnLongPageBack; - } - break; - case B::PageForward: - switch (ev.type) { - case ButtonEventManager::PressType::Short: - return SETTINGS.btnShortPageForward; - case ButtonEventManager::PressType::Double: - return SETTINGS.btnDoublePageForward; - case ButtonEventManager::PressType::Long: - return SETTINGS.btnLongPageForward; - } - break; - case B::Power: - switch (ev.type) { - case ButtonEventManager::PressType::Short: - return SETTINGS.btnShortPower; - case ButtonEventManager::PressType::Double: - return SETTINGS.btnDoublePower; - case ButtonEventManager::PressType::Long: - return SETTINGS.btnLongPower; - } - break; - default: - break; // Up/Down have no FSMs — ButtonEventManager never emits these - } - return BA::BTN_DEFAULT; - }; - - const uint8_t action = actionFor(ev.button); + const uint8_t action = actionFor(ev); if (action == BA::BTN_DEFAULT) { + if (ev.type == ButtonEventManager::PressType::Double) { + continue; + } defaultEvents.push_back(ev); continue; }