fix #336 don't send battery status on nodes without batteries

This commit is contained in:
geeksville 2020-08-25 13:00:55 -07:00
parent 780b7e3628
commit 5c40378805

View File

@ -22,9 +22,9 @@ class PowerStatus : public Status
/// Whether we have a battery connected /// Whether we have a battery connected
OptionalBool hasBattery = OptUnknown; OptionalBool hasBattery = OptUnknown;
/// Battery voltage in mV, valid if haveBattery is true /// Battery voltage in mV, valid if haveBattery is true
int batteryVoltageMv; int batteryVoltageMv = 0;
/// Battery charge percentage, either read directly or estimated /// Battery charge percentage, either read directly or estimated
int8_t batteryChargePercent; int8_t batteryChargePercent = 0;
/// Whether USB is connected /// Whether USB is connected
OptionalBool hasUSB = OptUnknown; OptionalBool hasUSB = OptUnknown;
/// Whether we are charging the battery /// Whether we are charging the battery
@ -33,7 +33,7 @@ class PowerStatus : public Status
public: public:
PowerStatus() { statusType = STATUS_TYPE_POWER; } PowerStatus() { statusType = STATUS_TYPE_POWER; }
PowerStatus(OptionalBool hasBattery, OptionalBool hasUSB, OptionalBool isCharging, int batteryVoltageMv = -1, PowerStatus(OptionalBool hasBattery, OptionalBool hasUSB, OptionalBool isCharging, int batteryVoltageMv = -1,
int8_t batteryChargePercent = -1) int8_t batteryChargePercent = 0)
: Status() : Status()
{ {
this->hasBattery = hasBattery; this->hasBattery = hasBattery;
@ -58,7 +58,10 @@ class PowerStatus : public Status
int getBatteryVoltageMv() const { return batteryVoltageMv; } 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 bool matches(const PowerStatus *newStatus) const
{ {