InfiniTime.git

commit 8b0d888952bb3cfbf587ab20d5096f2e578a6107

Author: Finlay Davidson <finlay.davidson@coderclass.nl>

batt: Improve discharge curve values

Values calculated using multiple tests on 3 PineTimes

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


diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp
index ead3e43b4765aa08a16d6e304ee8b9b8d830ea17..4d860490bda78e09c7d1f5e36d6d4356e0ef9960 100644
--- a/src/components/battery/BatteryController.cpp
+++ b/src/components/battery/BatteryController.cpp
@@ -61,14 +61,8 @@   APP_ERROR_CHECK(nrfx_saadc_buffer_convert(&saadc_value, 1));
 }
 
 void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) {
-  static const Utility::LinearApproximation<uint16_t, uint8_t, 6> aprox {{{
-    {3500, 0},  // Minimum voltage before shutdown (depends on the battery)
-    {3600, 10}, // Keen point that corresponds to 10%
-    {3700, 25},
-    {3750, 50},
-    {3900, 75},
-    {4180, 100} // Maximum voltage during charging is 4.21V
-  }}};
+  static const Utility::LinearApproximation<uint16_t, uint8_t, 6> approx {
+    {{{3500, 0}, {3616, 3}, {3723, 22}, {3776, 48}, {3979, 79}, {4180, 100}}}};
 
   if (p_event->type == NRFX_SAADC_EVT_DONE) {
 
@@ -83,7 +77,8 @@     voltage = p_event->data.done.p_buffer[0] * (8 * 600) / 1024;
 
     uint8_t newPercent = 100;
     if (!isFull) {
-      newPercent = std::min(aprox.GetValue(voltage), isCharging ? uint8_t {99} : uint8_t {100});
+      // max. voltage while charging is higher than when discharging
+      newPercent = std::min(approx.GetValue(voltage), isCharging ? uint8_t {99} : uint8_t {100});
     }
 
     if (isPowerPresent) {