Skip to content

Commit

Permalink
Merge pull request #637 from amarofarinha/main
Browse files Browse the repository at this point in the history
bugfix - Scaled Remaining Capacity underflows
  • Loading branch information
amarofarinha authored Nov 25, 2024
2 parents 0460b18 + 198c5a6 commit 35a0f0b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Software/Software.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -918,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;
}
Expand Down

0 comments on commit 35a0f0b

Please sign in to comment.