InfiniTime.git

commit 59ee0ad1aae99476c69c908dc9bce8626e695c94

Author: minacode <minamoto9@web.de>

add percentage rescaling

 src/components/battery/BatteryController.cpp | 8 +++++++-


diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp
index 95a3079281e7174afd64ba18ea9945fe736d19c4..ca0db79f675d72db93350ee42640470dde506afc 100644
--- a/src/components/battery/BatteryController.cpp
+++ b/src/components/battery/BatteryController.cpp
@@ -85,6 +85,11 @@     uint8_t newPercent = 100;
     if (!isFull) {
       newPercent = std::min(aprox.GetValue(voltage), isCharging ? uint8_t {99} : uint8_t {100});
     }
+    // quick hack for better values
+    // rescale the percentages between 35 and 100
+    constexpr uint8_t realMin = 35;
+    newPercent = std::max(newPercent, realMin);
+    newPercent = (newPercent - realMin) * 100 / (100 - realMin);
 
     if ((isPowerPresent && newPercent > percentRemaining) || (!isPowerPresent && newPercent < percentRemaining) || firstMeasurement) {
       firstMeasurement = false;
@@ -93,7 +98,8 @@       percentRemaining = newPercent;
       systemTask->PushMessage(System::Messages::BatteryPercentageUpdated);
     }
 
-    constexpr uint8_t lowBatteryThreshold {50};
+    // warn at 20% battery (wrt. rescaling above)
+    constexpr uint8_t lowBatteryThreshold {20};
     if (!isPowerPresent && lastPercentRemaining >= lowBatteryThreshold && percentRemaining < lowBatteryThreshold) {
       systemTask->PushMessage(System::Messages::LowBattery);
     }