Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/companion_radio/AbstractUITask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down
17 changes: 17 additions & 0 deletions examples/companion_radio/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
17 changes: 11 additions & 6 deletions examples/companion_radio/ui-new/UITask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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); }
}
Expand Down
3 changes: 1 addition & 2 deletions examples/companion_radio/ui-orig/UITask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ void UITask::shutdown(bool restart){
if (restart) {
_board->reboot();
} else {
radio_driver.powerOff();
_board->powerOff();
_wants_shutdown = true;
}
}

Expand Down
6 changes: 2 additions & 4 deletions examples/companion_radio/ui-tiny/UITask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -566,9 +566,7 @@ void UITask::shutdown(bool restart){
if (restart) {
_board->reboot();
} else {
_display->turnOff();
radio_driver.powerOff();
_board->powerOff();
_wants_shutdown = true;
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/simple_repeater/MyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
11 changes: 9 additions & 2 deletions examples/simple_repeater/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down