summaryrefslogtreecommitdiff
path: root/src/Components/Battery
diff options
context:
space:
mode:
Diffstat (limited to 'src/Components/Battery')
-rw-r--r--src/Components/Battery/BatteryController.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/Components/Battery/BatteryController.cpp b/src/Components/Battery/BatteryController.cpp
index 198ce5a..571efae 100644
--- a/src/Components/Battery/BatteryController.cpp
+++ b/src/Components/Battery/BatteryController.cpp
@@ -1,6 +1,7 @@
#include <drivers/include/nrfx_saadc.h>
#include <hal/nrf_gpio.h>
#include <libraries/log/nrf_log.h>
+#include <algorithm>
#include "BatteryController.h"
using namespace Pinetime::Controllers;
@@ -34,7 +35,9 @@ void Battery::Update() {
// see https://forum.pine64.org/showthread.php?tid=8147
voltage = (value * 2.0f) / (1024/3.0f);
- percentRemaining = ((voltage - 3.55)*100)*3.9;
+ percentRemaining = ((voltage - 3.55f)*100.0f)*3.9f;
+ percentRemaining = std::max(percentRemaining, 0.0f);
+ percentRemaining = std::min(percentRemaining, 100.0f);
// 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);