Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin message shutdown feature #1124

Merged
merged 4 commits into from Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/main.cpp
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -730,7 +755,7 @@ void loop()
#ifdef NRF52_SERIES
nrf52Loop();
#endif
rebootCheck();
powerCommandsCheck();

// For debugging
// if (rIf) ((RadioLibInterface *)rIf)->isActivelyReceiving();
Expand Down
1 change: 1 addition & 0 deletions src/main.h
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/AdminPlugin.cpp
Expand Up @@ -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:
Expand Down