From b6706c7ac133c5002a59689e20c6c0bda0dbee4e Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 21 Jan 2022 15:03:26 -0600 Subject: [PATCH] Admin message shutdown feature (#1124) * Shutdown via proto admin message --- src/main.cpp | 29 +++++++++++++++++++++++++++-- src/main.h | 1 + src/plugins/AdminPlugin.cpp | 6 ++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index be651d204..b0f90c445 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -699,8 +699,9 @@ axpDebugOutput.setup(); #endif uint32_t rebootAtMsec; // If not zero we will reboot at this time (used to reboot shortly after the update completes) +uint32_t shutdownAtMsec; // If not zero we will shutdown at this time (used to shutdown from python or mobile client) -void rebootCheck() +void powerCommandsCheck() { if (rebootAtMsec && millis() > rebootAtMsec) { #ifndef NO_ESP32 @@ -710,6 +711,30 @@ void rebootCheck() DEBUG_MSG("FIXME implement reboot for this platform"); #endif } + +#if NRF52_SERIES + if (shutdownAtMsec) { + screen->startShutdownScreen(); + playBeep(); + ledOff(PIN_LED1); + ledOff(PIN_LED2); + } +#endif + + if (shutdownAtMsec && millis() > shutdownAtMsec) { + DEBUG_MSG("Shutting down from admin command\n"); +#ifdef TBEAM_V10 + if (axp192_found == true) { + setLed(false); + power->shutdown(); + } +#elif NRF52_SERIES + playShutdownMelody(); + power->shutdown(); +#else + DEBUG_MSG("FIXME implement shutdown for this platform"); +#endif + } } // If a thread does something that might need for it to be rescheduled ASAP it can set this flag @@ -730,7 +755,7 @@ void loop() #ifdef NRF52_SERIES nrf52Loop(); #endif - rebootCheck(); + powerCommandsCheck(); // For debugging // if (rIf) ((RadioLibInterface *)rIf)->isActivelyReceiving(); diff --git a/src/main.h b/src/main.h index 0c5cb349c..2c90f34e3 100644 --- a/src/main.h +++ b/src/main.h @@ -21,6 +21,7 @@ extern graphics::Screen *screen; const char *getDeviceName(); extern uint32_t rebootAtMsec; +extern uint32_t shutdownAtMsec; // If a thread does something that might need for it to be rescheduled ASAP it can set this flag // This will supress the current delay and instead try to run ASAP. diff --git a/src/plugins/AdminPlugin.cpp b/src/plugins/AdminPlugin.cpp index 01e54fadb..3886cb232 100644 --- a/src/plugins/AdminPlugin.cpp +++ b/src/plugins/AdminPlugin.cpp @@ -104,6 +104,12 @@ bool AdminPlugin::handleReceivedProtobuf(const MeshPacket &mp, AdminMessage *r) rebootAtMsec = (s < 0) ? 0 : (millis() + s * 1000); break; } + case AdminMessage_shutdown_seconds_tag: { + int32_t s = r->shutdown_seconds; + DEBUG_MSG("Shutdown in %d seconds\n", s); + shutdownAtMsec = (s < 0) ? 0 : (millis() + s * 1000); + break; + } #ifdef PORTDUINO case AdminMessage_exit_simulator_tag: