mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-17 10:32:07 +00:00
RAK / NRF shutdown functionality on user button long press (#1113)
This commit is contained in:
parent
4e3fda87a1
commit
9309824874
@ -13,4 +13,5 @@ enum class Cmd {
|
|||||||
STOP_BLUETOOTH_PIN_SCREEN,
|
STOP_BLUETOOTH_PIN_SCREEN,
|
||||||
STOP_BOOT_SCREEN,
|
STOP_BOOT_SCREEN,
|
||||||
PRINT,
|
PRINT,
|
||||||
|
START_SHUTDOWN_SCREEN,
|
||||||
};
|
};
|
@ -219,6 +219,14 @@ static void drawFrameBluetooth(OLEDDisplay *display, OLEDDisplayUiState *state,
|
|||||||
display->drawString(64 + x, 48 + y, buf);
|
display->drawString(64 + x, 48 + y, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void drawFrameShutdown(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
|
||||||
|
{
|
||||||
|
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||||
|
|
||||||
|
display->setFont(FONT_MEDIUM);
|
||||||
|
display->drawString(64 + x, 26 + y, "Shutting down...");
|
||||||
|
}
|
||||||
|
|
||||||
static void drawFrameFirmware(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
|
static void drawFrameFirmware(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
|
||||||
{
|
{
|
||||||
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||||
@ -881,6 +889,9 @@ int32_t Screen::runOnce()
|
|||||||
handlePrint(cmd.print_text);
|
handlePrint(cmd.print_text);
|
||||||
free(cmd.print_text);
|
free(cmd.print_text);
|
||||||
break;
|
break;
|
||||||
|
case Cmd::START_SHUTDOWN_SCREEN:
|
||||||
|
handleShutdownScreen();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
DEBUG_MSG("BUG: invalid cmd\n");
|
DEBUG_MSG("BUG: invalid cmd\n");
|
||||||
}
|
}
|
||||||
@ -1047,6 +1058,18 @@ void Screen::handleStartBluetoothPinScreen(uint32_t pin)
|
|||||||
setFastFramerate();
|
setFastFramerate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Screen::handleShutdownScreen()
|
||||||
|
{
|
||||||
|
DEBUG_MSG("showing shutdown screen\n");
|
||||||
|
showingNormalScreen = false;
|
||||||
|
|
||||||
|
static FrameCallback shutdownFrames[] = {drawFrameShutdown};
|
||||||
|
|
||||||
|
ui.disableAllIndicators();
|
||||||
|
ui.setFrames(shutdownFrames, 1);
|
||||||
|
setFastFramerate();
|
||||||
|
}
|
||||||
|
|
||||||
void Screen::handleStartFirmwareUpdateScreen()
|
void Screen::handleStartFirmwareUpdateScreen()
|
||||||
{
|
{
|
||||||
DEBUG_MSG("showing firmware screen\n");
|
DEBUG_MSG("showing firmware screen\n");
|
||||||
|
@ -151,6 +151,12 @@ class Screen : public concurrency::OSThread
|
|||||||
enqueueCmd(cmd);
|
enqueueCmd(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void startShutdownScreen()
|
||||||
|
{
|
||||||
|
ScreenCmd cmd;
|
||||||
|
cmd.cmd = Cmd::START_SHUTDOWN_SCREEN;
|
||||||
|
enqueueCmd(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
/// Stops showing the bluetooth PIN screen.
|
/// Stops showing the bluetooth PIN screen.
|
||||||
void stopBluetoothPinScreen() { enqueueCmd(ScreenCmd{.cmd = Cmd::STOP_BLUETOOTH_PIN_SCREEN}); }
|
void stopBluetoothPinScreen() { enqueueCmd(ScreenCmd{.cmd = Cmd::STOP_BLUETOOTH_PIN_SCREEN}); }
|
||||||
@ -262,7 +268,7 @@ class Screen : public concurrency::OSThread
|
|||||||
void handleStartBluetoothPinScreen(uint32_t pin);
|
void handleStartBluetoothPinScreen(uint32_t pin);
|
||||||
void handlePrint(const char *text);
|
void handlePrint(const char *text);
|
||||||
void handleStartFirmwareUpdateScreen();
|
void handleStartFirmwareUpdateScreen();
|
||||||
|
void handleShutdownScreen();
|
||||||
/// Rebuilds our list of frames (screens) to default ones.
|
/// Rebuilds our list of frames (screens) to default ones.
|
||||||
void setFrames();
|
void setFrames();
|
||||||
|
|
||||||
|
@ -300,8 +300,9 @@ class ButtonThread : public OSThread
|
|||||||
static void userButtonPressedLong()
|
static void userButtonPressedLong()
|
||||||
{
|
{
|
||||||
// DEBUG_MSG("Long press!\n");
|
// DEBUG_MSG("Long press!\n");
|
||||||
|
#ifndef NRF52_SERIES
|
||||||
screen->adjustBrightness();
|
screen->adjustBrightness();
|
||||||
|
#endif
|
||||||
// If user button is held down for 5 seconds, shutdown the device.
|
// If user button is held down for 5 seconds, shutdown the device.
|
||||||
if (millis() - longPressTime > 5 * 1000) {
|
if (millis() - longPressTime > 5 * 1000) {
|
||||||
#ifdef TBEAM_V10
|
#ifdef TBEAM_V10
|
||||||
@ -313,6 +314,7 @@ class ButtonThread : public OSThread
|
|||||||
// Do actual shutdown when button released, otherwise the button release
|
// Do actual shutdown when button released, otherwise the button release
|
||||||
// may wake the board immediatedly.
|
// may wake the board immediatedly.
|
||||||
if (!shutdown_on_long_stop) {
|
if (!shutdown_on_long_stop) {
|
||||||
|
screen->startShutdownScreen();
|
||||||
DEBUG_MSG("Shutdown from long press");
|
DEBUG_MSG("Shutdown from long press");
|
||||||
playBeep();
|
playBeep();
|
||||||
ledOff(PIN_LED1);
|
ledOff(PIN_LED1);
|
||||||
@ -354,6 +356,7 @@ class ButtonThread : public OSThread
|
|||||||
longPressTime = 0;
|
longPressTime = 0;
|
||||||
if (shutdown_on_long_stop) {
|
if (shutdown_on_long_stop) {
|
||||||
playShutdownMelody();
|
playShutdownMelody();
|
||||||
|
delay(3000);
|
||||||
power->shutdown();
|
power->shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user