summaryrefslogtreecommitdiff
path: root/src/components/battery
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/battery')
-rw-r--r--src/components/battery/BatteryController.cpp9
-rw-r--r--src/components/battery/BatteryController.h5
2 files changed, 9 insertions, 5 deletions
diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp
index ca0db79f..49a17da1 100644
--- a/src/components/battery/BatteryController.cpp
+++ b/src/components/battery/BatteryController.cpp
@@ -96,12 +96,11 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) {
lastPercentRemaining = percentRemaining;
percentRemaining = newPercent;
systemTask->PushMessage(System::Messages::BatteryPercentageUpdated);
- }
- // warn at 20% battery (wrt. rescaling above)
- constexpr uint8_t lowBatteryThreshold {20};
- if (!isPowerPresent && lastPercentRemaining >= lowBatteryThreshold && percentRemaining < lowBatteryThreshold) {
- systemTask->PushMessage(System::Messages::LowBattery);
+ // warn at 20% battery (wrt. rescaling above)
+ if (!isPowerPresent && BatteryIsLow() && lastPercentRemaining > lowBatteryThreshold) {
+ systemTask->PushMessage(System::Messages::LowBattery);
+ }
}
nrfx_saadc_uninit();
diff --git a/src/components/battery/BatteryController.h b/src/components/battery/BatteryController.h
index 53eb7d19..df592232 100644
--- a/src/components/battery/BatteryController.h
+++ b/src/components/battery/BatteryController.h
@@ -17,6 +17,9 @@ namespace Pinetime {
uint8_t PercentRemaining() const {
return percentRemaining;
}
+ bool BatteryIsLow() const {
+ return percentRemaining <= lowBatteryThreshold;
+ }
uint16_t Voltage() const {
return voltage;
@@ -51,6 +54,8 @@ namespace Pinetime {
void SaadcEventHandler(nrfx_saadc_evt_t const* p_event);
static void AdcCallbackStatic(nrfx_saadc_evt_t const* event);
+ static constexpr uint8_t lowBatteryThreshold {20};
+
bool isReading = false;
Pinetime::System::SystemTask* systemTask = nullptr;