From bb781ff10a91a3cf9d335e4cbeb5a7ba3b1697f6 Mon Sep 17 00:00:00 2001 From: Kemal Hadimli Date: Thu, 28 May 2026 20:02:50 +0100 Subject: [PATCH] companion_radio: opt-in KEEP_DISPLAY_ON_USB to keep OLED on while powered MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AUTO_OFF_MILLIS is a power-save feature aimed at battery use. When the board reports isExternalPowered() == true (USB or other DC source), blanking the screen serves no purpose — there's nothing to conserve. But OLEDs are vulnerable to burn-in with static content, so this behaviour is gated behind a new build flag KEEP_DISPLAY_ON_USB. Default is unchanged from upstream — the display blanks after AUTO_OFF_MILLIS on USB or battery. Variants that ship with an LCD instead of an OLED (e.g. heltec_t096) can opt in by adding -D KEEP_DISPLAY_ON_USB to their env, gaining always-on-while-powered without exposing OLED users to burn-in risk. When the flag is enabled, the implementation refreshes _auto_off every loop iteration while externally powered, so the timer naturally counts a fresh AUTO_OFF_MILLIS window from the moment power is removed — no instantaneous-blank-on-unplug. Applied to all three companion_radio UI flavours (ui-new, ui-tiny, ui-orig). Boards without an isExternalPowered() override use the base-class default in MeshCore.h (returns false), so battery-powered behaviour is unchanged everywhere. Co-Authored-By: Claude Opus 4.7 (1M context) --- examples/companion_radio/ui-new/UITask.cpp | 9 +++++++++ examples/companion_radio/ui-orig/UITask.cpp | 9 +++++++++ examples/companion_radio/ui-tiny/UITask.cpp | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 6f363d7f96..ee12ca740d 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -809,6 +809,15 @@ void UITask::loop() { _display->endFrame(); } #if AUTO_OFF_MILLIS > 0 +#ifdef KEEP_DISPLAY_ON_USB + // Opt-in: refresh the auto-off deadline while externally powered, so the + // timer counts from the moment external power is removed. Off by default + // because OLED panels burn in quickly; only enable for LCD targets or + // where the display is replaceable. + if (board.isExternalPowered()) { + _auto_off = millis() + AUTO_OFF_MILLIS; + } +#endif if (millis() > _auto_off) { _display->turnOff(); } diff --git a/examples/companion_radio/ui-orig/UITask.cpp b/examples/companion_radio/ui-orig/UITask.cpp index 12a374d91d..5529046775 100644 --- a/examples/companion_radio/ui-orig/UITask.cpp +++ b/examples/companion_radio/ui-orig/UITask.cpp @@ -342,6 +342,15 @@ void UITask::loop() { _next_refresh = millis() + 1000; // refresh every second } +#ifdef KEEP_DISPLAY_ON_USB + // Opt-in: refresh the auto-off deadline while externally powered, so the + // timer counts from the moment external power is removed. Off by default + // because OLED panels burn in quickly; only enable for LCD targets or + // where the display is replaceable. + if (board.isExternalPowered()) { + _auto_off = millis() + AUTO_OFF_MILLIS; + } +#endif if (millis() > _auto_off) { _display->turnOff(); } diff --git a/examples/companion_radio/ui-tiny/UITask.cpp b/examples/companion_radio/ui-tiny/UITask.cpp index 417024426d..45a07a02ef 100644 --- a/examples/companion_radio/ui-tiny/UITask.cpp +++ b/examples/companion_radio/ui-tiny/UITask.cpp @@ -704,6 +704,15 @@ void UITask::loop() { _display->endFrame(); } #if AUTO_OFF_MILLIS > 0 +#ifdef KEEP_DISPLAY_ON_USB + // Opt-in: refresh the auto-off deadline while externally powered, so the + // timer counts from the moment external power is removed. Off by default + // because OLED panels burn in quickly; only enable for LCD targets or + // where the display is replaceable. + if (board.isExternalPowered()) { + _auto_off = millis() + AUTO_OFF_MILLIS; + } +#endif if (millis() > _auto_off) { _display->turnOff(); }