Fixed routine computing the battery charge level so that the returned charge value cannot be greater than 100%

This commit is contained in:
Silvano Seva 2022-06-28 12:24:35 +02:00
parent 40337e7c97
commit fed368a4db
1 changed files with 4 additions and 1 deletions

View File

@ -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
}