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
33 changes: 28 additions & 5 deletions examples/companion_radio/ui-new/UITask.cpp
Original file line number Diff line number Diff line change
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, "Power off in 5 seconds...");
_display->endFrame();
}
_wants_shutdown = true;
}
}

Expand Down Expand Up @@ -830,8 +835,26 @@ void UITask::loop() {

#ifdef AUTO_SHUTDOWN_MILLIVOLTS
if (millis() > next_batt_chck) {
uint16_t milliVolts = getBattMilliVolts();
if (milliVolts > 0 && milliVolts < AUTO_SHUTDOWN_MILLIVOLTS) {
uint32_t now = millis();
if (!_board->isBattReadSafe(now)) {
// TX just completed — voltage hasn't recovered yet; retry after settle window.
next_batt_chck = now + POST_TX_BATT_SETTLE_MS + 50;
} else {
uint16_t milliVolts = getBattMilliVolts();
if (milliVolts > 0 && milliVolts < AUTO_SHUTDOWN_MILLIVOLTS) {

// show low battery shutdown alert
// we should only do this for eink displays, which will persist after power loss
if (_display != NULL && _display->isEInk()) {
_display->startFrame();
_display->setTextSize(2);
_display->setColor(DisplayDriver::RED);
_display->drawTextCentered(_display->width() / 2, 20, "Low Battery.");
_display->drawTextCentered(_display->width() / 2, 40, "Power off in 5 sec.");
_display->endFrame();
}

shutdown();

// show low battery shutdown alert
// we should only do this for eink displays, which will persist after power loss
Expand Down
10 changes: 8 additions & 2 deletions examples/companion_radio/ui-orig/UITask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,14 @@ void UITask::shutdown(bool restart){
if (restart) {
_board->reboot();
} else {
radio_driver.powerOff();
_board->powerOff();
if (_display != NULL) {
_display->startFrame();
_display->setTextSize(1);
_display->setColor(DisplayDriver::LIGHT);
_display->drawTextCentered(_display->width() / 2, 20, "Power off in 5 seconds...");
_display->endFrame();
}
_wants_shutdown = true;
}
}

Expand Down
13 changes: 9 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, "Power off in 5 sec.");
} 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,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, "Power off in 5 sec.");
_display->endFrame();
}
_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 @@ -141,8 +141,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("Power off in 5 seconds...");
notified = true;
}
}
}
} else {
userBtnDownAt = 0;
Expand Down
1 change: 1 addition & 0 deletions src/helpers/ui/DisplayDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class DisplayDriver {
int width() const { return _w; }
int height() const { return _h; }

virtual bool isEInk() const { return false; }
virtual bool isOn() = 0;
virtual void turnOn() = 0;
virtual void turnOff() = 0;
Expand Down
1 change: 1 addition & 0 deletions src/helpers/ui/E213Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class E213Display : public DisplayDriver {
}
}
bool begin();
bool isEInk() const override { return true; }
bool isOn() override { return _isOn; }
void turnOn() override;
void turnOff() override;
Expand Down
1 change: 1 addition & 0 deletions src/helpers/ui/E290Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class E290Display : public DisplayDriver {
E290Display(RefCountedDigitalPin* periph_power = NULL) : DisplayDriver(296, 128), _periph_power(periph_power) {}

bool begin();
bool isEInk() const override { return true; }
bool isOn() override { return _isOn; }
void turnOn() override;
void turnOff() override;
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/ui/GxEPDDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class GxEPDDisplay : public DisplayDriver {
#endif

bool begin();

bool isEInk() const override { return true; }
bool isOn() override {return _isOn;};
void turnOn() override;
void turnOff() override;
Expand Down