From 7f5184281d6d8a48161b664d3b053ae2da7a20c6 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Mon, 11 May 2026 16:09:33 -0500 Subject: [PATCH] Make power status logging less chatty and track battery presence transitions (#10453) --- src/Power.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Power.cpp b/src/Power.cpp index 1ea3a64c2..f752e9461 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -878,7 +878,16 @@ void Power::readPowerStatus() // Notify any status instances that are observing us const PowerStatus powerStatus2 = PowerStatus(hasBattery, usbPowered, isChargingNow, batteryVoltageMv, batteryChargePercent); - if (millis() > lastLogTime + 50 * 1000) { + + // Log battery-presence transitions once; skip OptUnknown so we don't lie before the first probe. + static OptionalBool prevHasBattery = OptUnknown; + if (hasBattery != OptUnknown && hasBattery != prevHasBattery) { + LOG_INFO("Power: battery hardware %s", hasBattery == OptTrue ? "detected" : "absent (USB-only)"); + prevHasBattery = hasBattery; + } + + // Periodic telemetry only emits when a battery is actually present (otherwise values are constant -1/0). + if (hasBattery == OptTrue && !Throttle::isWithinTimespanMs(lastLogTime, 50 * 1000)) { LOG_DEBUG("Battery: usbPower=%d, isCharging=%d, batMv=%d, batPct=%d", powerStatus2.getHasUSB(), powerStatus2.getIsCharging(), powerStatus2.getBatteryVoltageMv(), powerStatus2.getBatteryChargePercent()); lastLogTime = millis();