Improve RGB LED state handling on power source change

Add acknowledgment check for RGB LED state change.

Signed-off-by: Niel Nielsen <nieldk@gmail.com>
This commit is contained in:
Niel Nielsen authored and GitHub committed 2026-09-12 10:31:32 +02:00
1 parent 23d6f67dc8
commit ac7a3f3c5a
1 file changed
+9 -5
+9 -5
View File
@@ -67,12 +67,16 @@ void rgb_indicator_update(void) {
if (on_battery == last_state) {
return; // edge-triggered: only write RGB when the state changes
}
last_state = on_battery;
if (on_battery) {
RgbLedSet(0, 8, 0); // dim green: alive, on battery
} else {
RgbLedSet(0, 0, 0); // on USB: off (cable already signals power)
// Commit last_state only if the controller actually ACKed. On a cold boot the
// I2C RGB controller can still be powering up when the first write fires; if we
// latched last_state regardless, a NAK here would leave the LED dark until the
// next state change (which never comes on battery). Retrying next cycle costs
// one I2C poke and self-heals once the controller is ready.
bool ok = on_battery ? RgbLedSet(0, 8, 0) // dim green: alive, on battery
: RgbLedSet(0, 0, 0); // on USB: off (cable already signals power)
if (ok) {
last_state = on_battery;
}
}