InfiniTime.git

commit 557a328409b9a4d4617606c8b04679ebee885b1f

Author: minacode <minamoto9@web.de>

changed to bool

 src/components/battery/BatteryController.cpp | 9 +++++++--
 src/components/battery/BatteryController.h | 2 +-


diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp
index 79829360449b4b76386daffcfe13996f2b1baac1..cdcc766a13639a0855fd695439f30852d555b028 100644
--- a/src/components/battery/BatteryController.cpp
+++ b/src/components/battery/BatteryController.cpp
@@ -86,15 +86,20 @@     if (!isFull) {
       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 3a7d73cee4415b76f2b7a7a6d3e5d261434a9dc3..627ca7d41da417144dd9368b9bb7fe18da0b64f1 100644
--- a/src/components/battery/BatteryController.h
+++ b/src/components/battery/BatteryController.h
@@ -42,7 +42,7 @@
       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;