diff --git a/examples/companion_radio/AbstractUITask.h b/examples/companion_radio/AbstractUITask.h index 0eee45aef3..5413b8017e 100644 --- a/examples/companion_radio/AbstractUITask.h +++ b/examples/companion_radio/AbstractUITask.h @@ -27,12 +27,16 @@ class AbstractUITask { mesh::MainBoard* _board; BaseSerialInterface* _serial; bool _connected; + bool _wants_shutdown = false; + bool _restart_on_shutdown = false; AbstractUITask(mesh::MainBoard* board, BaseSerialInterface* serial) : _board(board), _serial(serial) { _connected = false; } public: + bool wantsShutdown() const { return _wants_shutdown; } + bool isRestart() const { return _restart_on_shutdown; } void setHasConnection(bool connected) { _connected = connected; } bool hasConnection() const { return _connected; } uint16_t getBattMilliVolts() const { return _board->getBattMilliVolts(); } diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index ef9b6bfca4..965b9bb0bc 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -256,6 +256,23 @@ void loop() { #endif } +#ifdef DISPLAY_CLASS + if (ui_task.wantsShutdown() && !the_mesh.hasPendingWork()) { + if (display.isEink()) { + display.startFrame(); + display.setTextSize(2); + display.setColor(DisplayDriver::LIGHT); + display.drawTextCentered(display.width() / 2, 28, "Powered off."); + display.endFrame(); + } else { + display.turnOff(); + } + radio_driver.powerOff(); + if (ui_task.isRestart()) board.reboot(); + else board.powerOff(); + } +#endif + #if defined(ESP32) && defined(WIFI_SSID) // Safely attempt to reconnect every 10 seconds if flagged if (wifi_needs_reconnect && (millis() - last_wifi_reconnect_attempt > 10000)) { diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 7c84201941..3d772aceac 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -404,7 +404,7 @@ class HomeScreen : public UIScreen { display.setColor(DisplayDriver::GREEN); display.setTextSize(1); if (_shutdown_init) { - display.drawTextCentered(display.width() / 2, 34, "hibernating..."); + display.drawTextCentered(display.width() / 2, 34, "Shutting down..."); } else { display.drawXbm((display.width() - 32) / 2, 18, power_icon, 32, 32); display.drawTextCentered(display.width() / 2, 64 - 11, "hibernate:" PRESS_LABEL); @@ -697,9 +697,14 @@ void UITask::shutdown(bool restart){ if (restart) { _board->reboot(); } else { - _display->turnOff(); - radio_driver.powerOff(); - _board->powerOff(); + if (_display != NULL) { + _display->startFrame(); + _display->setTextSize(1); + _display->setColor(DisplayDriver::LIGHT); + _display->drawTextCentered(_display->width() / 2, 20, "Shutting down..."); + _display->endFrame(); + } + _wants_shutdown = true; } } @@ -837,8 +842,8 @@ void UITask::loop() { _display->startFrame(); _display->setTextSize(2); _display->setColor(DisplayDriver::RED); - _display->drawTextCentered(_display->width() / 2, 20, "Low Battery."); - _display->drawTextCentered(_display->width() / 2, 40, "Shutting Down!"); + _display->drawTextCentered(_display->width() / 2, 20, "Low battery!"); + _display->drawTextCentered(_display->width() / 2, 40, "Shutting down!"); _display->endFrame(); if (_display->isEink() == false) { delay(3000); } } diff --git a/examples/companion_radio/ui-orig/UITask.cpp b/examples/companion_radio/ui-orig/UITask.cpp index 5529046775..7447a63679 100644 --- a/examples/companion_radio/ui-orig/UITask.cpp +++ b/examples/companion_radio/ui-orig/UITask.cpp @@ -307,8 +307,7 @@ void UITask::shutdown(bool restart){ if (restart) { _board->reboot(); } else { - radio_driver.powerOff(); - _board->powerOff(); + _wants_shutdown = true; } } diff --git a/examples/companion_radio/ui-tiny/UITask.cpp b/examples/companion_radio/ui-tiny/UITask.cpp index 0119475e77..8977c296bc 100644 --- a/examples/companion_radio/ui-tiny/UITask.cpp +++ b/examples/companion_radio/ui-tiny/UITask.cpp @@ -364,7 +364,7 @@ class HomeScreen : public UIScreen { display.setColor(DisplayDriver::GREEN); display.setTextSize(1); if (_shutdown_init) { - display.drawTextCentered(display.width() / 2, 20, "hibernating..."); + display.drawTextCentered(display.width() / 2, 20, "Shutting down..."); } else { display.drawXbm((display.width() - 32) / 2, 8, power_icon, 32, 32); // display.drawTextCentered(display.width() / 2, 40 - 11, "hibernate:" PRESS_LABEL); @@ -566,9 +566,7 @@ void UITask::shutdown(bool restart){ if (restart) { _board->reboot(); } else { - _display->turnOff(); - radio_driver.powerOff(); - _board->powerOff(); + _wants_shutdown = true; } } diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index c24e297cd3..473e58dd7e 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -1310,5 +1310,5 @@ bool MyMesh::hasPendingWork() const { #if defined(WITH_BRIDGE) if (bridge.isRunning()) return true; // bridge needs WiFi radio, can't sleep #endif - return _mgr->getOutboundTotal() > 0; + return _mgr->getOutboundTotal() > 0 || dirty_contacts_expiry != 0; } diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 2ce056f521..2b2fe78ba4 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -137,8 +137,15 @@ void loop() { if (userBtnDownAt == 0) { userBtnDownAt = millis(); } else if ((unsigned long)(millis() - userBtnDownAt) >= USER_BTN_HOLD_OFF_MILLIS) { - Serial.println("Powering off..."); - board.powerOff(); // does not return + if (!the_mesh.hasPendingWork()) { + board.powerOff(); // does not return + } else { + static bool notified = false; + if (!notified) { + Serial.println("Shutting down!"); + notified = true; + } + } } } else { userBtnDownAt = 0;