diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp index 79829360..cdcc766a 100644 --- a/src/components/battery/BatteryController.cpp +++ b/src/components/battery/BatteryController.cpp @@ -86,15 +86,20 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) { newPercent = std::min(aprox.GetValue(voltage), isCharging ? uint8_t {99} : uint8_t {100}); } + if (isPowerPresent) { + batteryLowNotified = false; + } + if ((isPowerPresent && newPercent > percentRemaining) || (!isPowerPresent && newPercent < percentRemaining) || firstMeasurement) { firstMeasurement = false; - lastPercentRemaining = percentRemaining; percentRemaining = newPercent; systemTask->PushMessage(System::Messages::BatteryPercentageUpdated); + // warn about low battery when not charging and below threshold - if (!isPowerPresent && BatteryIsLow() && lastPercentRemaining > lowBatteryThreshold) { + if (BatteryIsLow() && !isPowerPresent && !batteryLowNotified) { systemTask->PushMessage(System::Messages::LowBattery); + batteryLowNotified = true; } } diff --git a/src/components/battery/BatteryController.h b/src/components/battery/BatteryController.h index 3a7d73ce..627ca7d4 100644 --- a/src/components/battery/BatteryController.h +++ b/src/components/battery/BatteryController.h @@ -42,7 +42,7 @@ namespace Pinetime { static constexpr nrf_saadc_input_t batteryVoltageAdcInput = NRF_SAADC_INPUT_AIN7; uint16_t voltage = 0; uint8_t percentRemaining = 0; - uint8_t lastPercentRemaining = 0; + bool batteryLowNotified = false; bool isFull = false; bool isCharging = false;