From fed368a4dbc32ae95bac4400752354c591fda5dc Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Tue, 28 Jun 2022 12:24:35 +0200 Subject: [PATCH] Fixed routine computing the battery charge level so that the returned charge value cannot be greater than 100% --- openrtx/src/core/battery.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/openrtx/src/core/battery.c b/openrtx/src/core/battery.c index a842c624..6bfbc4ae 100644 --- a/openrtx/src/core/battery.c +++ b/openrtx/src/core/battery.c @@ -73,7 +73,10 @@ uint8_t battery_getCharge(uint16_t vbat) uint32_t range = bat_v_max - bat_v_min; uint32_t result = ((diff << 8) / range) * 100; result += 128; - return result >> 8; + result >>= 8; + if(result > 100) result = 100; + + return result; #endif }