Re-tool button shutdown to better correspond to tones

This commit is contained in:
Jonathan Bennett 2025-07-20 15:33:02 -05:00
parent 2a9f9e97a9
commit 7713a72ba2
3 changed files with 25 additions and 26 deletions

View File

@ -53,23 +53,21 @@ bool ButtonThread::initButton(const ButtonConfig &config)
}, },
this); this);
if (config.longPress != INPUT_BROKER_NONE) { _longPress = config.longPress;
_longPress = config.longPress; userButton.attachLongPressStart(
userButton.attachLongPressStart( [](void *callerThread) -> void {
[](void *callerThread) -> void { ButtonThread *thread = (ButtonThread *)callerThread;
ButtonThread *thread = (ButtonThread *)callerThread; // if (millis() > 30000) // hold off 30s after boot
// if (millis() > 30000) // hold off 30s after boot thread->btnEvent = BUTTON_EVENT_LONG_PRESSED;
thread->btnEvent = BUTTON_EVENT_LONG_PRESSED; },
}, this);
this); userButton.attachLongPressStop(
userButton.attachLongPressStop( [](void *callerThread) -> void {
[](void *callerThread) -> void { ButtonThread *thread = (ButtonThread *)callerThread;
ButtonThread *thread = (ButtonThread *)callerThread; // if (millis() > 30000) // hold off 30s after boot
// if (millis() > 30000) // hold off 30s after boot thread->btnEvent = BUTTON_EVENT_LONG_RELEASED;
thread->btnEvent = BUTTON_EVENT_LONG_RELEASED; },
}, this);
this);
}
if (config.doublePress != INPUT_BROKER_NONE) { if (config.doublePress != INPUT_BROKER_NONE) {
_doublePress = config.doublePress; _doublePress = config.doublePress;
@ -202,11 +200,11 @@ int32_t ButtonThread::runOnce()
break; break;
} }
if (_longPress != INPUT_BROKER_NONE) {
// Forward long press to InputBroker (but NOT as DOWN/SELECT, just forward a "button long press" event) // Forward long press to InputBroker (but NOT as DOWN/SELECT, just forward a "button long press" event)
evt.inputEvent = _longPress; evt.inputEvent = _longPress;
this->notifyObservers(&evt); this->notifyObservers(&evt);
}
// Reset combination tracking // Reset combination tracking
waitingForLongPress = false; waitingForLongPress = false;
@ -253,7 +251,7 @@ int32_t ButtonThread::runOnce()
// may wake the board immediatedly. // may wake the board immediatedly.
case BUTTON_EVENT_LONG_RELEASED: { 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 && if (millis() > 30000 && _longLongPress != INPUT_BROKER_NONE &&
(millis() - buttonPressStartTime) >= _longLongPressTime) { (millis() - buttonPressStartTime) >= _longLongPressTime) {
evt.inputEvent = _longLongPress; evt.inputEvent = _longLongPress;

View File

@ -18,7 +18,7 @@ struct ButtonConfig {
uint16_t longPressTime = 500; uint16_t longPressTime = 500;
input_broker_event doublePress = INPUT_BROKER_NONE; input_broker_event doublePress = INPUT_BROKER_NONE;
input_broker_event longLongPress = 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 triplePress = INPUT_BROKER_NONE;
input_broker_event shortLong = INPUT_BROKER_NONE; input_broker_event shortLong = INPUT_BROKER_NONE;
bool touchQuirk = false; bool touchQuirk = false;

View File

@ -1042,8 +1042,9 @@ void setup()
mainDelay.interruptFromISR(&higherWake); mainDelay.interruptFromISR(&higherWake);
}; };
userConfigNoScreen.singlePress = INPUT_BROKER_USER_PRESS; userConfigNoScreen.singlePress = INPUT_BROKER_USER_PRESS;
userConfigNoScreen.longPress = INPUT_BROKER_SHUTDOWN; userConfigNoScreen.longPress = INPUT_BROKER_NONE;
userConfigNoScreen.longPressTime = 5000; userConfigNoScreen.longPressTime = 500;
userConfigNoScreen.longLongPress = INPUT_BROKER_SHUTDOWN;
userConfigNoScreen.doublePress = INPUT_BROKER_SEND_PING; userConfigNoScreen.doublePress = INPUT_BROKER_SEND_PING;
userConfigNoScreen.triplePress = INPUT_BROKER_GPS_TOGGLE; userConfigNoScreen.triplePress = INPUT_BROKER_GPS_TOGGLE;
UserButtonThread->initButton(userConfigNoScreen); UserButtonThread->initButton(userConfigNoScreen);