From 7713a72ba298f2c2acc3d3f990ca9be38be62200 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 20 Jul 2025 15:33:02 -0500 Subject: [PATCH] Re-tool button shutdown to better correspond to tones --- src/input/ButtonThread.cpp | 44 ++++++++++++++++++-------------------- src/input/ButtonThread.h | 2 +- src/main.cpp | 5 +++-- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/input/ButtonThread.cpp b/src/input/ButtonThread.cpp index ad667f003..233bbefe0 100644 --- a/src/input/ButtonThread.cpp +++ b/src/input/ButtonThread.cpp @@ -53,23 +53,21 @@ bool ButtonThread::initButton(const ButtonConfig &config) }, this); - if (config.longPress != INPUT_BROKER_NONE) { - _longPress = config.longPress; - userButton.attachLongPressStart( - [](void *callerThread) -> void { - ButtonThread *thread = (ButtonThread *)callerThread; - // if (millis() > 30000) // hold off 30s after boot - thread->btnEvent = BUTTON_EVENT_LONG_PRESSED; - }, - this); - userButton.attachLongPressStop( - [](void *callerThread) -> void { - ButtonThread *thread = (ButtonThread *)callerThread; - // if (millis() > 30000) // hold off 30s after boot - thread->btnEvent = BUTTON_EVENT_LONG_RELEASED; - }, - this); - } + _longPress = config.longPress; + userButton.attachLongPressStart( + [](void *callerThread) -> void { + ButtonThread *thread = (ButtonThread *)callerThread; + // if (millis() > 30000) // hold off 30s after boot + thread->btnEvent = BUTTON_EVENT_LONG_PRESSED; + }, + this); + userButton.attachLongPressStop( + [](void *callerThread) -> void { + ButtonThread *thread = (ButtonThread *)callerThread; + // if (millis() > 30000) // hold off 30s after boot + thread->btnEvent = BUTTON_EVENT_LONG_RELEASED; + }, + this); if (config.doublePress != INPUT_BROKER_NONE) { _doublePress = config.doublePress; @@ -202,11 +200,11 @@ int32_t ButtonThread::runOnce() break; } - - // Forward long press to InputBroker (but NOT as DOWN/SELECT, just forward a "button long press" event) - evt.inputEvent = _longPress; - this->notifyObservers(&evt); - + if (_longPress != INPUT_BROKER_NONE) { + // Forward long press to InputBroker (but NOT as DOWN/SELECT, just forward a "button long press" event) + evt.inputEvent = _longPress; + this->notifyObservers(&evt); + } // Reset combination tracking waitingForLongPress = false; @@ -253,7 +251,7 @@ int32_t ButtonThread::runOnce() // may wake the board immediatedly. case BUTTON_EVENT_LONG_RELEASED: { - LOG_INFO("LONG PRESS RELEASE"); + LOG_INFO("LONG PRESS RELEASE AFTER %u MILLIS", millis() - buttonPressStartTime); if (millis() > 30000 && _longLongPress != INPUT_BROKER_NONE && (millis() - buttonPressStartTime) >= _longLongPressTime) { evt.inputEvent = _longLongPress; diff --git a/src/input/ButtonThread.h b/src/input/ButtonThread.h index 2358e609d..bbc8da2a7 100644 --- a/src/input/ButtonThread.h +++ b/src/input/ButtonThread.h @@ -18,7 +18,7 @@ struct ButtonConfig { uint16_t longPressTime = 500; input_broker_event doublePress = INPUT_BROKER_NONE; input_broker_event longLongPress = INPUT_BROKER_NONE; - uint16_t longLongPressTime = 5000; + uint16_t longLongPressTime = 3900; input_broker_event triplePress = INPUT_BROKER_NONE; input_broker_event shortLong = INPUT_BROKER_NONE; bool touchQuirk = false; diff --git a/src/main.cpp b/src/main.cpp index c37001307..2e2adfd46 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1042,8 +1042,9 @@ void setup() mainDelay.interruptFromISR(&higherWake); }; userConfigNoScreen.singlePress = INPUT_BROKER_USER_PRESS; - userConfigNoScreen.longPress = INPUT_BROKER_SHUTDOWN; - userConfigNoScreen.longPressTime = 5000; + userConfigNoScreen.longPress = INPUT_BROKER_NONE; + userConfigNoScreen.longPressTime = 500; + userConfigNoScreen.longLongPress = INPUT_BROKER_SHUTDOWN; userConfigNoScreen.doublePress = INPUT_BROKER_SEND_PING; userConfigNoScreen.triplePress = INPUT_BROKER_GPS_TOGGLE; UserButtonThread->initButton(userConfigNoScreen);