dashboard: force battery detail state calculation

This commit is contained in:
2026-06-19 00:55:10 -06:00
parent ef8e02a6a4
commit fefb7a911a
2 changed files with 27 additions and 3 deletions
@@ -647,16 +647,39 @@ static void update_battery_detail_widgets()
{
if (battery_detail_soc_label == nullptr) return;
const float amps = status_model.current;
String soc = status_model.soc >= 0 ? String(status_model.soc) + "%" : "--%";
String battery_state;
if (amps <= -0.05f) {
battery_state = "DISCHARGING";
} else if (amps >= 0.05f) {
battery_state = "CHARGING";
} else {
battery_state = "IDLE";
}
String voltage = String(status_model.voltage, 2) + " V";
String current = battery_detail_signed(status_model.current, 2, " A");
String power = battery_detail_signed(status_model.voltage * status_model.current, 0, " W");
String current = battery_detail_signed(amps, 2, " A");
String power = battery_detail_signed(status_model.voltage * amps, 0, " W");
String remaining = String(status_model.remaining_ah, 1) + " Ah";
String capacity = String(status_model.capacity_ah, 1) + " Ah";
String temp = String(status_model.battery_temp_f, 1) + "°F";
String delta = status_model.cell_delta_mv >= 0 ? String(status_model.cell_delta_mv) + " mV" : "-- mV";
String estimate;
if (amps <= -0.05f && status_model.remaining_ah > 0.0f) {
estimate = "ETR " + format_hours(status_model.remaining_ah / fabs(amps));
} else if (amps >= 0.05f && status_model.capacity_ah > 0.0f) {
float ah_to_full = max(0.0f, status_model.capacity_ah - status_model.remaining_ah);
estimate = "Full " + format_hours(ah_to_full / amps);
} else {
estimate = "Idle";
}
set_label_text_if_changed(battery_detail_soc_label, last_battery_detail_soc_text, soc);
set_label_text_if_changed(battery_detail_status_label, last_battery_detail_status_text, battery_state);
set_label_text_if_changed(battery_detail_voltage_label, last_battery_detail_voltage_text, voltage);
set_label_text_if_changed(battery_detail_current_label, last_battery_detail_current_text, current);
set_label_text_if_changed(battery_detail_power_label, last_battery_detail_power_text, power);
@@ -664,6 +687,7 @@ static void update_battery_detail_widgets()
set_label_text_if_changed(battery_detail_capacity_label, last_battery_detail_capacity_text, capacity);
set_label_text_if_changed(battery_detail_temp_label, last_battery_detail_temp_text, temp);
set_label_text_if_changed(battery_detail_delta_label, last_battery_detail_delta_text, delta);
set_label_text_if_changed(battery_detail_estimate_label, last_battery_detail_estimate_text, estimate);
}
static void clear_battery_detail_refs()