summaryrefslogtreecommitdiff
path: root/src/components/battery/BatteryController.cpp
diff options
context:
space:
mode:
authorJF002 <JF002@users.noreply.github.com>2021-01-20 20:41:55 +0000
committerGitHub <noreply@github.com>2021-01-20 20:41:55 +0000
commitbe48f5275aeb289fd451ca1c06b7a12587b2e204 (patch)
tree23263e149f8d2343651672dae9f95e99bed106b8 /src/components/battery/BatteryController.cpp
parent6d8513938764fe1f9818d562bf1a45498aa87a30 (diff)
parentb31c0e7e4571a2aef46672d49eedab0f31b820f4 (diff)
Merge pull request #168 from Panky-codes/fix-erratic-battery
Fix erratic battery
Diffstat (limited to 'src/components/battery/BatteryController.cpp')
-rw-r--r--src/components/battery/BatteryController.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp
index 3e3d65b4..aaa245e4 100644
--- a/src/components/battery/BatteryController.cpp
+++ b/src/components/battery/BatteryController.cpp
@@ -34,9 +34,11 @@ void Battery::Update() {
// see https://forum.pine64.org/showthread.php?tid=8147
voltage = (value * 2.0f) / (1024/3.0f);
- percentRemaining = ((voltage - 3.55f)*100.0f)*3.9f;
- percentRemaining = std::max(percentRemaining, 0.0f);
- percentRemaining = std::min(percentRemaining, 100.0f);
+ int percentRemaining = ((voltage - 3.55f)*100.0f)*3.9f;
+ percentRemaining = std::max(percentRemaining, 0);
+ percentRemaining = std::min(percentRemaining, 100);
+
+ percentRemainingBuffer.insert(percentRemaining);
// NRF_LOG_INFO("BATTERY " NRF_LOG_FLOAT_MARKER " %% - " NRF_LOG_FLOAT_MARKER " v", NRF_LOG_FLOAT(percentRemaining), NRF_LOG_FLOAT(voltage));
// NRF_LOG_INFO("POWER Charging : %d - Power : %d", isCharging, isPowerPresent);