Make Elecrow M* top button a back button

This commit is contained in:
Jonathan Bennett 2025-06-10 18:57:23 -05:00
parent 8590b7a8ce
commit 05501db78e
9 changed files with 39 additions and 15 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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