From ee68401ad026eceba42d7abae4e78f8e9b7a3dfb Mon Sep 17 00:00:00 2001 From: JQ Date: Thu, 19 Jun 2025 16:47:31 -0700 Subject: [PATCH 1/2] fixing button handling to allow both button types simultaneously --- examples/companion_radio/UITask.cpp | 33 ++++++++++++++++++++--------- examples/companion_radio/UITask.h | 5 ++++- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/examples/companion_radio/UITask.cpp b/examples/companion_radio/UITask.cpp index 01906f90..ec2ccd8b 100644 --- a/examples/companion_radio/UITask.cpp +++ b/examples/companion_radio/UITask.cpp @@ -58,23 +58,31 @@ void UITask::begin(DisplayDriver* display, NodePrefs* node_prefs) { buzzer.begin(); #endif - // Initialize button with appropriate configuration -#if defined(PIN_USER_BTN) || defined(PIN_USER_BTN_ANA) - #ifdef PIN_USER_BTN - _userButton = new Button(PIN_USER_BTN, USER_BTN_PRESSED); - #else - _userButton = new Button(PIN_USER_BTN_ANA, USER_BTN_PRESSED, true, 20); - #endif - + // Initialize digital button if available +#ifdef PIN_USER_BTN + _userButton = new Button(PIN_USER_BTN, USER_BTN_PRESSED); _userButton->begin(); - // Set up button callbacks + // Set up digital button callbacks _userButton->onShortPress([this]() { handleButtonShortPress(); }); _userButton->onDoublePress([this]() { handleButtonDoublePress(); }); _userButton->onTriplePress([this]() { handleButtonTriplePress(); }); _userButton->onLongPress([this]() { handleButtonLongPress(); }); _userButton->onAnyPress([this]() { handleButtonAnyPress(); }); #endif + + // Initialize analog button if available +#ifdef PIN_USER_BTN_ANA + _userButtonAnalog = new Button(PIN_USER_BTN_ANA, USER_BTN_PRESSED, true, 20); + _userButtonAnalog->begin(); + + // Set up analog button callbacks + _userButtonAnalog->onShortPress([this]() { handleButtonShortPress(); }); + _userButtonAnalog->onDoublePress([this]() { handleButtonDoublePress(); }); + _userButtonAnalog->onTriplePress([this]() { handleButtonTriplePress(); }); + _userButtonAnalog->onLongPress([this]() { handleButtonLongPress(); }); + _userButtonAnalog->onAnyPress([this]() { handleButtonAnyPress(); }); +#endif ui_started_at = millis(); } @@ -289,11 +297,16 @@ void UITask::shutdown(bool restart){ } void UITask::loop() { - #if defined(PIN_USER_BTN) || defined(PIN_USER_BTN_ANA) + #ifdef PIN_USER_BTN if (_userButton) { _userButton->update(); } #endif + #ifdef PIN_USER_BTN_ANA + if (_userButtonAnalog) { + _userButtonAnalog->update(); + } + #endif userLedHandler(); #ifdef PIN_BUZZER diff --git a/examples/companion_radio/UITask.h b/examples/companion_radio/UITask.h index 93a2ef89..2b64d686 100644 --- a/examples/companion_radio/UITask.h +++ b/examples/companion_radio/UITask.h @@ -40,9 +40,12 @@ class UITask { unsigned long ui_started_at; // Button handlers -#if defined(PIN_USER_BTN) || defined(PIN_USER_BTN_ANA) +#ifdef PIN_USER_BTN Button* _userButton = nullptr; #endif +#ifdef PIN_USER_BTN_ANA + Button* _userButtonAnalog = nullptr; +#endif void renderCurrScreen(); void userLedHandler(); From e6ba025f77e2e55e8f5f465f02055b9d2066930b Mon Sep 17 00:00:00 2001 From: JQ Date: Thu, 19 Jun 2025 21:52:57 -0700 Subject: [PATCH 2/2] add new quad press --- examples/companion_radio/UITask.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/companion_radio/UITask.cpp b/examples/companion_radio/UITask.cpp index ec9994b2..1eb5be8e 100644 --- a/examples/companion_radio/UITask.cpp +++ b/examples/companion_radio/UITask.cpp @@ -82,6 +82,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no _userButtonAnalog->onShortPress([this]() { handleButtonShortPress(); }); _userButtonAnalog->onDoublePress([this]() { handleButtonDoublePress(); }); _userButtonAnalog->onTriplePress([this]() { handleButtonTriplePress(); }); + _userButtonAnalog->onQuadruplePress([this]() { handleButtonQuadruplePress(); }); _userButtonAnalog->onLongPress([this]() { handleButtonLongPress(); }); _userButtonAnalog->onAnyPress([this]() { handleButtonAnyPress(); }); #endif