From d86d289d76ead0069479d42e36fd8df650c25ec0 Mon Sep 17 00:00:00 2001 From: MickiusMousius <137600636+MickiusMousius@users.noreply.github.com> Date: Tue, 12 Dec 2023 16:18:27 +1030 Subject: [PATCH] Fix: Correct incorrect indexing of the lookup table --- app/module/drivers/sensor/battery/battery_common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/module/drivers/sensor/battery/battery_common.c b/app/module/drivers/sensor/battery/battery_common.c index 73b60e9c..b582e317 100644 --- a/app/module/drivers/sensor/battery/battery_common.c +++ b/app/module/drivers/sensor/battery/battery_common.c @@ -50,7 +50,7 @@ uint8_t lithium_ion_mv_to_pct(int16_t batt_mv) { return 100; } - for (int i = 0; i < ARRAY_SIZE(battery_lookup); i++) { + for (int i = 1; i < ARRAY_SIZE(battery_lookup); i++) { struct lookup_point one = battery_lookup[i - 1]; struct lookup_point two = battery_lookup[i]; if (batt_mv >= two.millivolts) { @@ -62,4 +62,4 @@ uint8_t lithium_ion_mv_to_pct(int16_t batt_mv) { } return 0; -} \ No newline at end of file +}