diff --git a/src/input/ButtonThread.cpp b/src/input/ButtonThread.cpp index 9f53b06f4..63fd8b0d7 100644 --- a/src/input/ButtonThread.cpp +++ b/src/input/ButtonThread.cpp @@ -37,6 +37,9 @@ bool ButtonThread::initButton(const ButtonConfig &config) _activeLow = config.activeLow; _touchQuirk = config.touchQuirk; _intRoutine = config.intRoutine; + _pressHandler = config.onPress; + _releaseHandler = config.onRelease; + _suppressLeadUp = config.suppressLeadUpSound; _longLongPress = config.longLongPress; userButton = OneButton(config.pinNumber, config.activeLow, config.activePullup); @@ -133,6 +136,8 @@ int32_t ButtonThread::runOnce() // Detect start of button press if (buttonCurrentlyPressed && !buttonWasPressed) { + if (_pressHandler) + _pressHandler(); buttonPressStartTime = millis(); leadUpPlayed = false; leadUpSequenceActive = false; @@ -140,7 +145,7 @@ int32_t ButtonThread::runOnce() } // Progressive lead-up sound system - if (buttonCurrentlyPressed && (millis() - buttonPressStartTime) >= BUTTON_LEADUP_MS) { + if (!_suppressLeadUp && buttonCurrentlyPressed && (millis() - buttonPressStartTime) >= BUTTON_LEADUP_MS) { // Start the progressive sequence if not already active if (!leadUpSequenceActive) { @@ -160,6 +165,8 @@ int32_t ButtonThread::runOnce() // Reset when button is released if (!buttonCurrentlyPressed && buttonWasPressed) { + if (_releaseHandler) + _releaseHandler(); leadUpSequenceActive = false; resetLeadUpSequence(); } diff --git a/src/input/ButtonThread.h b/src/input/ButtonThread.h index 7de38341c..e724c3596 100644 --- a/src/input/ButtonThread.h +++ b/src/input/ButtonThread.h @@ -13,6 +13,9 @@ struct ButtonConfig { bool activePullup = true; uint32_t pullupSense = 0; voidFuncPtr intRoutine = nullptr; + voidFuncPtr onPress = nullptr; // Optional edge callbacks + voidFuncPtr onRelease = nullptr; // Optional edge callbacks + bool suppressLeadUpSound = false; input_broker_event singlePress = INPUT_BROKER_NONE; input_broker_event longPress = INPUT_BROKER_NONE; uint16_t longPressTime = 500; @@ -94,6 +97,9 @@ class ButtonThread : public Observable, public concurrency:: input_broker_event _shortLong = INPUT_BROKER_NONE; voidFuncPtr _intRoutine = nullptr; + voidFuncPtr _pressHandler = nullptr; + voidFuncPtr _releaseHandler = nullptr; + bool _suppressLeadUp = false; uint16_t _longPressTime = 500; uint16_t _longLongPressTime = 3900; int _pinNum = 0; diff --git a/src/main.cpp b/src/main.cpp index 77b23c232..97bb21475 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -107,6 +107,10 @@ NRF52Bluetooth *nrf52Bluetooth = nullptr; #if defined(BUTTON_PIN_TOUCH) ButtonThread *TouchButtonThread = nullptr; +#if defined(TTGO_T_ECHO_PLUS) && defined(PIN_EINK_EN) +static bool touchBacklightWasOn = false; +static bool touchBacklightActive = false; +#endif #endif #if defined(BUTTON_PIN) || defined(ARCH_PORTDUINO) @@ -1043,6 +1047,24 @@ void setup() }; touchConfig.singlePress = INPUT_BROKER_NONE; touchConfig.longPress = INPUT_BROKER_BACK; +#if defined(TTGO_T_ECHO_PLUS) && defined(PIN_EINK_EN) + // On T-Echo Plus the touch pad should only drive the backlight, not UI navigation/sounds + touchConfig.longPress = INPUT_BROKER_NONE; + touchConfig.suppressLeadUpSound = true; + touchConfig.onPress = []() { + touchBacklightWasOn = uiconfig.screen_brightness == 1; + if (!touchBacklightWasOn) { + digitalWrite(PIN_EINK_EN, HIGH); + } + touchBacklightActive = true; + }; + touchConfig.onRelease = []() { + if (touchBacklightActive && !touchBacklightWasOn) { + digitalWrite(PIN_EINK_EN, LOW); + } + touchBacklightActive = false; + }; +#endif TouchButtonThread->initButton(touchConfig); #endif