From 3ce1cf404ed66bbdfdd8687605b46cd429f7c0bd Mon Sep 17 00:00:00 2001 From: taco Date: Tue, 2 Jun 2026 00:55:25 +1000 Subject: [PATCH] NRF52: disable autoshutdown if powered, add auto-shutdown warning for oled --- examples/companion_radio/ui-new/UITask.cpp | 28 ++++++++++----------- examples/companion_radio/ui-tiny/UITask.cpp | 17 ++++++++++--- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index ee12ca74..0cebc100 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -832,22 +832,20 @@ void UITask::loop() { if (millis() > next_batt_chck) { 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 defined(THINKNODE_M1) || defined(LILYGO_TECHO) - if (_display != NULL) { - _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->endFrame(); + if(!board.isExternalPowered()) { + if (_display != NULL) { + _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->endFrame(); + #if !defined(THINKNODE_M1) && !defined(LILYGO_TECHO) // TODO: refactor eink variants to use EINK_DISPLAY macros to gate this properly + delay(3000); + #endif + } + shutdown(); } - #endif - - shutdown(); - } next_batt_chck = millis() + 8000; } diff --git a/examples/companion_radio/ui-tiny/UITask.cpp b/examples/companion_radio/ui-tiny/UITask.cpp index 45a07a02..125c4f7b 100644 --- a/examples/companion_radio/ui-tiny/UITask.cpp +++ b/examples/companion_radio/ui-tiny/UITask.cpp @@ -727,14 +727,23 @@ void UITask::loop() { if (millis() > next_batt_chck) { _cached_batt_mv = getBattMilliVolts(); if (_cached_batt_mv > 0 && _cached_batt_mv < AUTO_SHUTDOWN_MILLIVOLTS) { - - shutdown(); - + if(!board.isExternalPowered()) { + if (_display != NULL) { + _display->startFrame(); + _display->setTextSize(2); + _display->drawTextCentered(_display->width() / 2, 6, "Low battery!"); + _display->setTextSize(1); + _display->drawTextCentered(_display->width() / 2, 18, "Shutting down!"); + _display->endFrame(); + delay(3000); // TODO: refactor eink variants to use EINK_DISPLAY macros to gate this properly + } + shutdown(); + } } next_batt_chck = millis() + 8000; } #else - if (_display != NULL && _display->isOn() && millis >= next_batt_chck) { + if (_display != NULL && _display->isOn() && millis() >= next_batt_chck) { _cached_batt_mv = getBattMilliVolts(); next_batt_chck = millis() + 8000; }