Onebutton Menu Support

This commit is contained in:
Jonathan Bennett 2025-06-06 22:33:04 -05:00
parent f4c5e31f3d
commit 652033a0b4
6 changed files with 36 additions and 16 deletions

View File

@ -36,7 +36,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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 <http://www.gnu.org/licenses/>.
#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<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT)) {
showNextFrame();
} else if (event->inputEvent ==
static_cast<char>(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT)) {
static_cast<char>(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 {

View File

@ -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

View File

@ -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();

View File

@ -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;

View File

@ -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"