RAK / NRF shutdown functionality on user button long press (#1113)

pull/1110/head^2
Ben Meadors 2022-01-19 17:10:02 -06:00 zatwierdzone przez GitHub
rodzic 4e3fda87a1
commit 9309824874
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 35 dodań i 2 usunięć

Wyświetl plik

@ -13,4 +13,5 @@ enum class Cmd {
STOP_BLUETOOTH_PIN_SCREEN,
STOP_BOOT_SCREEN,
PRINT,
START_SHUTDOWN_SCREEN,
};

Wyświetl plik

@ -219,6 +219,14 @@ static void drawFrameBluetooth(OLEDDisplay *display, OLEDDisplayUiState *state,
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)
{
display->setTextAlignment(TEXT_ALIGN_CENTER);
@ -881,6 +889,9 @@ int32_t Screen::runOnce()
handlePrint(cmd.print_text);
free(cmd.print_text);
break;
case Cmd::START_SHUTDOWN_SCREEN:
handleShutdownScreen();
break;
default:
DEBUG_MSG("BUG: invalid cmd\n");
}
@ -1047,6 +1058,18 @@ void Screen::handleStartBluetoothPinScreen(uint32_t pin)
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()
{
DEBUG_MSG("showing firmware screen\n");

Wyświetl plik

@ -151,6 +151,12 @@ class Screen : public concurrency::OSThread
enqueueCmd(cmd);
}
void startShutdownScreen()
{
ScreenCmd cmd;
cmd.cmd = Cmd::START_SHUTDOWN_SCREEN;
enqueueCmd(cmd);
}
/// Stops showing the 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 handlePrint(const char *text);
void handleStartFirmwareUpdateScreen();
void handleShutdownScreen();
/// Rebuilds our list of frames (screens) to default ones.
void setFrames();

Wyświetl plik

@ -300,8 +300,9 @@ class ButtonThread : public OSThread
static void userButtonPressedLong()
{
// DEBUG_MSG("Long press!\n");
#ifndef NRF52_SERIES
screen->adjustBrightness();
#endif
// If user button is held down for 5 seconds, shutdown the device.
if (millis() - longPressTime > 5 * 1000) {
#ifdef TBEAM_V10
@ -313,6 +314,7 @@ class ButtonThread : public OSThread
// Do actual shutdown when button released, otherwise the button release
// may wake the board immediatedly.
if (!shutdown_on_long_stop) {
screen->startShutdownScreen();
DEBUG_MSG("Shutdown from long press");
playBeep();
ledOff(PIN_LED1);
@ -354,6 +356,7 @@ class ButtonThread : public OSThread
longPressTime = 0;
if (shutdown_on_long_stop) {
playShutdownMelody();
delay(3000);
power->shutdown();
}
}