From 5d3a9744938b38c064379c3f78ace5a7dd87926f Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 27 Sep 2020 20:02:47 +0200 Subject: Add BatteryInformationService to expose the battery level to BLE host. --- src/Components/Battery/BatteryController.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/Components/Battery') diff --git a/src/Components/Battery/BatteryController.cpp b/src/Components/Battery/BatteryController.cpp index 198ce5aa..571efae6 100644 --- a/src/Components/Battery/BatteryController.cpp +++ b/src/Components/Battery/BatteryController.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #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); -- cgit v1.2.3-70-g09d2