From 2c54366b5776cc7f6c8e8206758a84f5ed835c57 Mon Sep 17 00:00:00 2001 From: amarofarinha <151563493+amarofarinha@users.noreply.github.com> Date: Mon, 25 Nov 2024 10:03:23 +0000 Subject: [PATCH 1/2] bugfix - Scaled Remaining Capacity underflows --- Software/Software.ino | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Software/Software.ino b/Software/Software.ino index 2074f191..dcf0d752 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -901,8 +901,13 @@ void update_calculated_values() { calc_max_capacity = (datalayer.battery.status.remaining_capacity_Wh * 10000 / datalayer.battery.status.real_soc); calc_reserved_capacity = calc_max_capacity * datalayer.battery.settings.min_percentage / 10000; // remove % capacity reserved in min_percentage to total_capacity_Wh - datalayer.battery.status.reported_remaining_capacity_Wh = - datalayer.battery.status.remaining_capacity_Wh - calc_reserved_capacity; + if (datalayer.battery.status.remaining_capacity_Wh > calc_reserved_capacity) { + datalayer.battery.status.reported_remaining_capacity_Wh = + datalayer.battery.status.remaining_capacity_Wh - calc_reserved_capacity; + } else { + datalayer.battery.status.reported_remaining_capacity_Wh = 0; + } + } else { datalayer.battery.status.reported_remaining_capacity_Wh = datalayer.battery.status.remaining_capacity_Wh; } From 198c5a63f40cce94765b8b710f9b0ceb9791b241 Mon Sep 17 00:00:00 2001 From: amarofarinha <151563493+amarofarinha@users.noreply.github.com> Date: Mon, 25 Nov 2024 10:13:05 +0000 Subject: [PATCH 2/2] include DOUBLE_BATTERY setup in the fix --- Software/Software.ino | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Software/Software.ino b/Software/Software.ino index dcf0d752..dd0a545a 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -923,8 +923,12 @@ void update_calculated_values() { (datalayer.battery2.status.remaining_capacity_Wh * 10000 / datalayer.battery2.status.real_soc); calc_reserved_capacity = calc_max_capacity * datalayer.battery2.settings.min_percentage / 10000; // remove % capacity reserved in min_percentage to total_capacity_Wh - datalayer.battery2.status.reported_remaining_capacity_Wh = - datalayer.battery2.status.remaining_capacity_Wh - calc_reserved_capacity; + if (datalayer.battery2.status.remaining_capacity_Wh > calc_reserved_capacity) { + datalayer.battery2.status.reported_remaining_capacity_Wh = + datalayer.battery2.status.remaining_capacity_Wh - calc_reserved_capacity; + } else { + datalayer.battery2.status.reported_remaining_capacity_Wh = 0; + } } else { datalayer.battery2.status.reported_remaining_capacity_Wh = datalayer.battery2.status.remaining_capacity_Wh; }