From 05501db78e0f03c248ff9c57782a7a8c57d6b2e8 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Tue, 10 Jun 2025 18:57:23 -0500 Subject: [PATCH] Make Elecrow M* top button a back button --- src/graphics/Screen.cpp | 2 ++ src/graphics/draw/NotificationRenderer.cpp | 4 ++-- src/main.cpp | 18 ++++++++++++++++++ src/platform/nrf52/architecture.h | 12 ++++++------ variants/ELECROW-ThinkNode-M1/variant.h | 3 +++ variants/ELECROW-ThinkNode-M2/variant.h | 1 + variants/link32_s3_v1/variant.h | 2 +- variants/seeed_wio_tracker_L1/variant.h | 6 +++--- variants/unphone/variant.h | 6 +++--- 9 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 731c7ea1b..3c31a15fd 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1437,6 +1437,8 @@ int Screen::handleInputEvent(const InputEvent *event) }); } } else if (event->inputEvent == INPUT_BROKER_BACK) { + showPrevFrame(); + } else if (event->inputEvent == INPUT_BROKER_CANCEL) { setOn(false); } } diff --git a/src/graphics/draw/NotificationRenderer.cpp b/src/graphics/draw/NotificationRenderer.cpp index f3935b9a4..60a42d9a5 100644 --- a/src/graphics/draw/NotificationRenderer.cpp +++ b/src/graphics/draw/NotificationRenderer.cpp @@ -113,7 +113,7 @@ void NotificationRenderer::drawAlertBannerOverlay(OLEDDisplay *display, OLEDDisp } else if (inEvent == INPUT_BROKER_SELECT) { alertBannerCallback(curSelected); alertBannerMessage[0] = '\0'; - } else if (inEvent == INPUT_BROKER_BACK && alertBannerUntil != 0) { + } else if ((inEvent == INPUT_BROKER_CANCEL || inEvent == INPUT_BROKER_BACK) && alertBannerUntil != 0) { alertBannerMessage[0] = '\0'; } if (curSelected == -1) @@ -132,7 +132,7 @@ void NotificationRenderer::drawAlertBannerOverlay(OLEDDisplay *display, OLEDDisp } } else { // not in an alert with a callback // TODO: check that at least a second has passed since the alert started - if (inEvent == INPUT_BROKER_SELECT || inEvent == INPUT_BROKER_BACK) { + if (inEvent == INPUT_BROKER_SELECT || inEvent == INPUT_BROKER_BACK || inEvent == INPUT_BROKER_CANCEL) { alertBannerMessage[0] = '\0'; // end the alert early } } diff --git a/src/main.cpp b/src/main.cpp index c91cef2b9..4fd0da808 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -113,6 +113,10 @@ ButtonThread *UserButtonThread = nullptr; ButtonThread *BackButtonThread = nullptr; #endif +#if defined(CANCEL_BUTTON_PIN) +ButtonThread *CancelButtonThread = nullptr; +#endif + #endif #include "AmbientLightingThread.h" @@ -923,6 +927,20 @@ void setup() INPUT_BROKER_NONE, INPUT_BROKER_BACK); #endif +#if defined(CANCEL_BUTTON_PIN) + // Buttons. Moved here cause we need NodeDB to be initialized + CancelButtonThread = new ButtonThread("CancelButton"); + CancelButtonThread->initButton( + CANCEL_BUTTON_PIN, CANCEL_BUTTON_ACTIVE_LOW, CANCEL_BUTTON_ACTIVE_PULLUP, pullup_sense, + []() { + CancelButtonThread->userButton.tick(); + runASAP = true; + BaseType_t higherWake = 0; + mainDelay.interruptFromISR(&higherWake); + }, + INPUT_BROKER_CANCEL, INPUT_BROKER_SHUTDOWN, 4000); +#endif + #if defined(BACK_BUTTON_PIN) // Buttons. Moved here cause we need NodeDB to be initialized BackButtonThread = new ButtonThread("BackButton"); diff --git a/src/platform/nrf52/architecture.h b/src/platform/nrf52/architecture.h index 5c0bee44f..168b8403d 100644 --- a/src/platform/nrf52/architecture.h +++ b/src/platform/nrf52/architecture.h @@ -119,13 +119,13 @@ #define BUTTON_PIN PIN_BUTTON1 #endif -#ifdef PIN_BUTTON2 -#define BACK_BUTTON_PIN PIN_BUTTON2 -#ifndef BACK_BUTTON_ACTIVE_LOW -#define BACK_BUTTON_ACTIVE_LOW true +#if defined(PIN_BUTTON2) && !defined(BACK_BUTTON_PIN) +#define CANCEL_BUTTON_PIN PIN_BUTTON2 +#ifndef CANCEL_BUTTON_ACTIVE_LOW +#define CANCEL_BUTTON_ACTIVE_LOW true #endif -#ifndef BACK_BUTTON_ACTIVE_PULLUP -#define BACK_BUTTON_ACTIVE_PULLUP true +#ifndef CANCEL_BUTTON_ACTIVE_PULLUP +#define CANCEL_BUTTON_ACTIVE_PULLUP true #endif #endif diff --git a/variants/ELECROW-ThinkNode-M1/variant.h b/variants/ELECROW-ThinkNode-M1/variant.h index 2e91e378d..126162158 100644 --- a/variants/ELECROW-ThinkNode-M1/variant.h +++ b/variants/ELECROW-ThinkNode-M1/variant.h @@ -63,6 +63,9 @@ extern "C" { * Buttons */ #define PIN_BUTTON2 (32 + 10) +#define BACK_BUTTON_PIN PIN_BUTTON2 +#define BACK_BUTTON_ACTIVE_LOW true +#define BACK_BUTTON_ACTIVE_PULLUP true #define PIN_BUTTON1 (32 + 7) // #define PIN_BUTTON1 (0 + 11) diff --git a/variants/ELECROW-ThinkNode-M2/variant.h b/variants/ELECROW-ThinkNode-M2/variant.h index 32c1e15b3..016c5b306 100644 --- a/variants/ELECROW-ThinkNode-M2/variant.h +++ b/variants/ELECROW-ThinkNode-M2/variant.h @@ -3,6 +3,7 @@ #define PIN_BUTTON1 47 // 功能键 #define PIN_BUTTON2 4 // 电源键 +#define BACK_BUTTON_PIN PIN_BUTTON2 #define BACK_BUTTON_ACTIVE_LOW false #define BACK_BUTTON_ACTIVE_PULLUP false diff --git a/variants/link32_s3_v1/variant.h b/variants/link32_s3_v1/variant.h index 23cabe233..b4e0fd5e5 100644 --- a/variants/link32_s3_v1/variant.h +++ b/variants/link32_s3_v1/variant.h @@ -6,7 +6,7 @@ #define USE_SSD1306 #define BUTTON_PIN 0 // Button pin for this board -#define BACK_BUTTON_PIN 36 +#define CANCEL_BUTTON_PIN 36 #define HAS_NEOPIXEL // If defined, we will use the neopixel library #define NEOPIXEL_DATA 35 // Neopixel pin for this board diff --git a/variants/seeed_wio_tracker_L1/variant.h b/variants/seeed_wio_tracker_L1/variant.h index b5d334eb6..d84bac9fe 100644 --- a/variants/seeed_wio_tracker_L1/variant.h +++ b/variants/seeed_wio_tracker_L1/variant.h @@ -33,10 +33,10 @@ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ // Button Configuration // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ -#define BACK_BUTTON_PIN D13 // This is the Program Button +#define CANCEL_BUTTON_PIN D13 // This is the Program Button // #define BUTTON_NEED_PULLUP 1 -#define BACK_BUTTON_ACTIVE_LOW true -#define BACK_BUTTON_ACTIVE_PULLUP false +#define CANCEL_BUTTON_ACTIVE_LOW true +#define CANCEL_BUTTON_ACTIVE_PULLUP false // #define BUTTON_PIN_TOUCH 13 // Touch button // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ diff --git a/variants/unphone/variant.h b/variants/unphone/variant.h index 422f0c4a9..e21d397e4 100644 --- a/variants/unphone/variant.h +++ b/variants/unphone/variant.h @@ -57,9 +57,9 @@ #define LED_PIN 13 // the red part of the RGB LED #define LED_STATE_ON 0 // State when LED is lit -#define BUTTON_PIN 21 // Button 3 - square - top button in landscape mode -#define BUTTON_NEED_PULLUP // we do need a helping hand up -#define BACK_BUTTON_PIN 45 // Button 1 - triangle - bottom button in landscape mode +#define BUTTON_PIN 21 // Button 3 - square - top button in landscape mode +#define BUTTON_NEED_PULLUP // we do need a helping hand up +#define CANCEL_BUTTON_PIN 45 // Button 1 - triangle - bottom button in landscape mode #define I2C_SDA 3 // I2C pins for this board #define I2C_SCL 4