diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 25cd25663..4fcb2b1a1 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -36,7 +36,6 @@ along with this program. If not, see . #if !MESHTASTIC_EXCLUDE_GPS #include "GPS.h" #endif -#include "ButtonThread.h" #include "FSCommon.h" #include "MeshService.h" #include "NodeDB.h" @@ -48,6 +47,7 @@ along with this program. If not, see . #include "graphics/SharedUIDisplay.h" #include "graphics/emotes.h" #include "graphics/images.h" +#include "input/ButtonThread.h" #include "input/ScanAndSelect.h" #include "input/TouchScreenImpl1.h" #include "main.h" @@ -1781,6 +1781,13 @@ int Screen::handleUIFrameEvent(const UIFrameEvent *event) int Screen::handleInputEvent(const InputEvent *event) { + + if (NotificationRenderer::isOverlayBannerShowing()) { + NotificationRenderer::inEvent = event->inputEvent; + setFrames(); + ui->update(); + return 0; + } #if defined(DISPLAY_CLOCK_FRAME) // For the T-Watch, intercept touches to the 'toggle digital/analog watch face' button uint8_t watchFaceFrame = error_code ? 1 : 0; @@ -1794,12 +1801,7 @@ int Screen::handleInputEvent(const InputEvent *event) return 0; } #endif - if (NotificationRenderer::isOverlayBannerShowing()) { - NotificationRenderer::inEvent = event->inputEvent; - setFrames(); - ui->update(); - return 0; - } + // Use left or right input from a keyboard to move between frames, // so long as a mesh module isn't using these events for some other purpose if (showingNormalScreen) { @@ -1829,7 +1831,8 @@ int Screen::handleInputEvent(const InputEvent *event) } else if (event->inputEvent == static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT)) { showNextFrame(); } else if (event->inputEvent == - static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT)) { + static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT) || + event->inputEvent == INPUT_BROKER_MSG_BUTTON_DOUBLE_PRESSED) { #if HAS_TFT if (this->ui->getUiState()->currentFrame == framesetInfo.positions.memory) { showOverlayBanner("Switch to MUI?\nYES\nNO", 30000, 2, [](int selected) -> void { diff --git a/src/graphics/draw/NotificationRenderer.cpp b/src/graphics/draw/NotificationRenderer.cpp index d9baaaee2..9bde377b2 100644 --- a/src/graphics/draw/NotificationRenderer.cpp +++ b/src/graphics/draw/NotificationRenderer.cpp @@ -59,7 +59,7 @@ void NotificationRenderer::drawAlertBannerOverlay(OLEDDisplay *display, OLEDDisp // Exit if no message is active or duration has passed if (!isOverlayBannerShowing()) return; - LOG_DEBUG("event: %u, curSelected: %d", inEvent, curSelected); + // === Layout Configuration === constexpr uint16_t padding = 5; // Padding around text inside the box constexpr uint16_t vPadding = 2; // Padding around text inside the box @@ -105,9 +105,11 @@ void NotificationRenderer::drawAlertBannerOverlay(OLEDDisplay *display, OLEDDisp // respond to input if (inEvent == meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_UP) { curSelected--; - } else if (inEvent == meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_DOWN) { + } else if (inEvent == meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_DOWN || + inEvent == INPUT_BROKER_MSG_BUTTON_PRESSED) { curSelected++; - } else if (inEvent == meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT) { + } else if (inEvent == meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT || + inEvent == INPUT_BROKER_MSG_BUTTON_DOUBLE_PRESSED) { alertBannerCallback(curSelected); alertBannerMessage[0] = '\0'; } @@ -172,8 +174,6 @@ void NotificationRenderer::drawAlertBannerOverlay(OLEDDisplay *display, OLEDDisp // === Draw each line centered in the box === int16_t lineY = boxTop + vPadding; - LOG_DEBUG("firstOptionToShow: %u, firstOption: %u", firstOptionToShow, firstOption); - // for (int i = 0; i < lineCount; i++) { // is this line selected? // if so, start the buffer with -> and strncpy to the 4th location diff --git a/src/ButtonThread.cpp b/src/input/ButtonThread.cpp similarity index 97% rename from src/ButtonThread.cpp rename to src/input/ButtonThread.cpp index 574301249..074b4b4b7 100644 --- a/src/ButtonThread.cpp +++ b/src/input/ButtonThread.cpp @@ -266,7 +266,7 @@ int32_t ButtonThread::runOnce() #if HAS_SCREEN switch (btnEvent) { case BUTTON_EVENT_PRESSED: { - LOG_BUTTON("press!"); + LOG_WARN("press!"); // Play boop sound for every button press playBoop(); @@ -283,8 +283,24 @@ int32_t ButtonThread::runOnce() break; } + case BUTTON_EVENT_DOUBLE_PRESSED: { + LOG_WARN("press!"); + + // Play boop sound for every button press + playBoop(); + + // Forward single press to InputBroker (but NOT as DOWN/SELECT, just forward a "button press" event) + if (inputBroker) { + InputEvent evt = {"button", INPUT_BROKER_MSG_BUTTON_DOUBLE_PRESSED, 0, 0, 0}; + inputBroker->injectInputEvent(&evt); + } + + waitingForLongPress = false; + + break; + } case BUTTON_EVENT_LONG_PRESSED: { - LOG_BUTTON("Long press!"); + LOG_WARN("Long press!"); // Play beep sound playBeep(); diff --git a/src/ButtonThread.h b/src/input/ButtonThread.h similarity index 100% rename from src/ButtonThread.h rename to src/input/ButtonThread.h diff --git a/src/input/InputBroker.h b/src/input/InputBroker.h index 6948390d2..316ea60a7 100644 --- a/src/input/InputBroker.h +++ b/src/input/InputBroker.h @@ -23,6 +23,7 @@ #define INPUT_BROKER_MSG_EMOTE_LIST 0x8F #define INPUT_BROKER_MSG_BUTTON_PRESSED 0xe1 #define INPUT_BROKER_MSG_BUTTON_LONG_PRESSED 0xe2 +#define INPUT_BROKER_MSG_BUTTON_DOUBLE_PRESSED 0xe3 typedef struct _InputEvent { const char *source; diff --git a/src/main.cpp b/src/main.cpp index 6c6269056..6744addfd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -99,7 +99,7 @@ NRF52Bluetooth *nrf52Bluetooth = nullptr; #endif #if HAS_BUTTON || defined(ARCH_PORTDUINO) -#include "ButtonThread.h" +#include "input/ButtonThread.h" #endif #include "AmbientLightingThread.h"