Skip to content

companion_radio: keep OLED on while externally powered 🤖🤖#2643

Open
disq wants to merge 1 commit into
meshcore-dev:devfrom
disq:companion-display-keep-on-when-powered
Open

companion_radio: keep OLED on while externally powered 🤖🤖#2643
disq wants to merge 1 commit into
meshcore-dev:devfrom
disq:companion-display-keep-on-when-powered

Conversation

@disq
Copy link
Copy Markdown

@disq disq commented May 28, 2026

Summary

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. This PR makes the OLED stay on while externally powered, and starts the auto-off countdown from the moment power is removed (not from when it was applied).

Approach

Inside the _display->isOn() block of each companion UI flavour's loop(), refresh _auto_off whenever board.isExternalPowered() returns true:

```cpp
#if AUTO_OFF_MILLIS > 0
if (board.isExternalPowered()) {
_auto_off = millis() + AUTO_OFF_MILLIS;
}
if (millis() > _auto_off) {
_display->turnOff();
}
#endif
```

While USB-powered, _auto_off is pushed forward every tick so the existing turn-off branch never fires. The instant isExternalPowered() goes false, the refresh stops and the timer counts down naturally — giving a full fresh AUTO_OFF_MILLIS window before the screen blanks. No instantaneous-blank-on-unplug.

Applied to all three companion_radio UI flavours: ui-new, ui-tiny, ui-orig.

Safety

  • MeshCore.h defines virtual bool isExternalPowered() { return false; } as the base-class default. Boards without an override compile to identical pre-change behaviour.
  • NRF52Board overrides it only when NRF52_POWER_MANAGEMENT is defined (RAK3401, RAK4631, etc.).
  • Existing battery-only deployments and any board that doesn't (yet) report external-power state are completely unaffected.

Why not also simple_repeater / simple_room_server / simple_sensor

Those examples target set-and-forget battery-powered deployments by convention. Easy follow-up if maintainers want the same behaviour there.

Testing

Verified on RAK3401 + companion_radio_ble:

  • USB-powered: OLED stays on indefinitely past AUTO_OFF_MILLIS (15 s default).
  • Unplug USB: OLED stays on for a fresh 15 s window from the unplug moment, then blanks as expected.
  • Battery-only operation (no USB ever attached): existing behaviour — blanks 15 s after last button press.

🤖 Generated with Claude Code

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.

Instead of just gating the turnOff() call on isExternalPowered() (which
caused the display to blank instantly the moment power was removed,
because the timer had silently expired while powered), refresh
_auto_off every loop iteration that's externally powered. That way the
timer naturally counts a fresh AUTO_OFF_MILLIS window from the moment
USB is unplugged.

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) <noreply@anthropic.com>
@disq disq changed the title companion_radio: keep OLED on while externally powered companion_radio: keep OLED on while externally powered 🤖🤖 May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant