diff --git a/examples/companion_radio/Button.cpp b/examples/companion_radio/Button.cpp index 09172404..00ae39ff 100644 --- a/examples/companion_radio/Button.cpp +++ b/examples/companion_radio/Button.cpp @@ -60,10 +60,10 @@ void Button::update() { _state = IDLE; } - // Handle long press + // Handle long press while button is held if (_state == PRESSED && (now - _pressTime) > BUTTON_LONG_PRESS_TIME_MS) { triggerEvent(LONG_PRESS); - _state = IDLE; // Prevent multiple long press events + _state = IDLE; // Prevent multiple press events _clickCount = 0; } } @@ -97,7 +97,7 @@ void Button::handleStateChange() { } else { // Long press already handled in update() _state = IDLE; - _clickCount = 0; // Reset click count after long press + _clickCount = 0; } } } diff --git a/examples/companion_radio/Button.h b/examples/companion_radio/Button.h index 74e5b3f7..82e953ab 100644 --- a/examples/companion_radio/Button.h +++ b/examples/companion_radio/Button.h @@ -6,7 +6,7 @@ // Button timing configuration #define BUTTON_DEBOUNCE_TIME_MS 50 // Debounce time in ms #define BUTTON_CLICK_TIMEOUT_MS 500 // Max time between clicks for multi-click -#define BUTTON_LONG_PRESS_TIME_MS 5000 // Time to trigger long press (5 seconds) +#define BUTTON_LONG_PRESS_TIME_MS 3000 // Time to trigger long press (3 seconds) #define BUTTON_READ_INTERVAL_MS 10 // How often to read the button class Button { @@ -33,7 +33,7 @@ public: void onDoublePress(EventCallback callback) { _onDoublePress = callback; } void onTriplePress(EventCallback callback) { _onTriplePress = callback; } void onLongPress(EventCallback callback) { _onLongPress = callback; } - void onAnyPress(EventCallback callback) { _onAnyPress = callback; } // New method + void onAnyPress(EventCallback callback) { _onAnyPress = callback; } // State getters bool isPressed() const { return _currentState == _activeState; } diff --git a/examples/companion_radio/UITask.cpp b/examples/companion_radio/UITask.cpp index 7b2a6c52..39364e42 100644 --- a/examples/companion_radio/UITask.cpp +++ b/examples/companion_radio/UITask.cpp @@ -308,11 +308,13 @@ void UITask::loop() { void UITask::handleButtonAnyPress() { MESH_DEBUG_PRINTLN("UITask: any press triggered"); + // called on any button press before other events, to wake up the display quickly + // do not refresh the display here, as it may block the button handler if (_display != NULL) { - if (!_display->isOn()) { + _displayWasOn = _display->isOn(); // Track display state before any action + if (!_displayWasOn) { _display->turnOn(); } - _need_refresh = true; _auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer } } @@ -320,12 +322,17 @@ void UITask::handleButtonAnyPress() { void UITask::handleButtonShortPress() { MESH_DEBUG_PRINTLN("UITask: short press triggered"); if (_display != NULL) { - if (_display->isOn()) { - // If display is on and showing message preview, clear it + // Only clear message preview if display was already on before button press + if (_displayWasOn) { + // If display was on and showing message preview, clear it if (_origin[0] && _msg[0]) { clearMsgPreview(); + } else { + // Otherwise, refresh the display + _need_refresh = true; } } + // Note: Display turn-on and auto-off timer extension are handled by handleButtonAnyPress } } diff --git a/examples/companion_radio/UITask.h b/examples/companion_radio/UITask.h index a4bf6103..9546aaf0 100644 --- a/examples/companion_radio/UITask.h +++ b/examples/companion_radio/UITask.h @@ -35,6 +35,7 @@ class UITask { char _msg[80]; int _msgcount; bool _need_refresh = true; + bool _displayWasOn = false; // Track display state before button press // Button handlers #if defined(PIN_USER_BTN) || defined(PIN_USER_BTN_ANA) diff --git a/variants/t114/platformio.ini b/variants/t114/platformio.ini index 9e72bbd6..37e31e6f 100644 --- a/variants/t114/platformio.ini +++ b/variants/t114/platformio.ini @@ -79,8 +79,7 @@ build_flags = build_src_filter = ${Heltec_t114.build_src_filter} + + - +<../examples/companion_radio/main.cpp> - +<../examples/companion_radio/UITask.cpp> + +<../examples/companion_radio> + + +