diff options
| author | JF <jf@codingfield.com> | 2020-09-27 20:04:17 +0200 |
|---|---|---|
| committer | Gitea <gitea@fake.local> | 2020-09-27 20:04:17 +0200 |
| commit | efd0c9eff7000c71825221d3094e7bb709465fc2 (patch) | |
| tree | d0e73cf9c19260328a729eb3ccc398ce8536b329 /src/Components/Battery | |
| parent | 079d437016e2bdbd2161fb6b3f11f9d9e346709a (diff) | |
| parent | 5d3a9744938b38c064379c3f78ace5a7dd87926f (diff) | |
Merge branch 'batteryInformationService' of JF/PineTime into develop
Diffstat (limited to 'src/Components/Battery')
| -rw-r--r-- | src/Components/Battery/BatteryController.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
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 <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); |
