From 5c40378805577fb520511196fa087ec173435720 Mon Sep 17 00:00:00 2001 From: geeksville Date: Tue, 25 Aug 2020 13:00:55 -0700 Subject: [PATCH] fix #336 don't send battery status on nodes without batteries --- src/PowerStatus.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/PowerStatus.h b/src/PowerStatus.h index f875f4f73d..c9bb89a05a 100644 --- a/src/PowerStatus.h +++ b/src/PowerStatus.h @@ -22,9 +22,9 @@ class PowerStatus : public Status /// Whether we have a battery connected OptionalBool hasBattery = OptUnknown; /// Battery voltage in mV, valid if haveBattery is true - int batteryVoltageMv; + int batteryVoltageMv = 0; /// Battery charge percentage, either read directly or estimated - int8_t batteryChargePercent; + int8_t batteryChargePercent = 0; /// Whether USB is connected OptionalBool hasUSB = OptUnknown; /// Whether we are charging the battery @@ -33,7 +33,7 @@ class PowerStatus : public Status public: PowerStatus() { statusType = STATUS_TYPE_POWER; } PowerStatus(OptionalBool hasBattery, OptionalBool hasUSB, OptionalBool isCharging, int batteryVoltageMv = -1, - int8_t batteryChargePercent = -1) + int8_t batteryChargePercent = 0) : Status() { this->hasBattery = hasBattery; @@ -58,7 +58,10 @@ class PowerStatus : public Status int getBatteryVoltageMv() const { return batteryVoltageMv; } - uint8_t getBatteryChargePercent() const { return batteryChargePercent; } + /** + * Note: 0% battery means 'unknown/this board doesn't have a battery installed' + */ + uint8_t getBatteryChargePercent() const { return getHasBattery() ? batteryChargePercent : 0; } bool matches(const PowerStatus *newStatus) const {