dashboard: simplify battery soc gauge

This commit is contained in:
2026-06-09 23:59:20 -06:00
parent bb1b96c648
commit 7aa6a9dc33
2 changed files with 17 additions and 74 deletions
@@ -1,6 +1,6 @@
#pragma once #pragma once
static const char *DASHBOARD_VERSION = "0.1.2-battery-soc-gauge"; static const char *DASHBOARD_VERSION = "0.1.3-simple-battery-gauge";
// Update these if your Cargo ESP AP credentials are different. // Update these if your Cargo ESP AP credentials are different.
static const char *CARGO_WIFI_SSID = "OverlandController"; static const char *CARGO_WIFI_SSID = "OverlandController";
@@ -19,8 +19,6 @@ static lv_obj_t *battery_charge_pulse_arc = nullptr;
static lv_obj_t *battery_voltage_label = nullptr; static lv_obj_t *battery_voltage_label = nullptr;
static lv_obj_t *battery_current_label = nullptr; static lv_obj_t *battery_current_label = nullptr;
static lv_obj_t *battery_soc_label = nullptr; static lv_obj_t *battery_soc_label = nullptr;
static lv_obj_t *battery_capacity_label = nullptr;
static lv_obj_t *battery_health_label = nullptr;
static lv_obj_t *inside_temp_label = nullptr; static lv_obj_t *inside_temp_label = nullptr;
static lv_obj_t *outside_temp_label = nullptr; static lv_obj_t *outside_temp_label = nullptr;
static lv_obj_t *system_status_label = nullptr; static lv_obj_t *system_status_label = nullptr;
@@ -49,8 +47,6 @@ static bool pending_relay_previous_state = false;
static String last_battery_voltage_text; static String last_battery_voltage_text;
static String last_battery_current_text; static String last_battery_current_text;
static String last_battery_soc_text; static String last_battery_soc_text;
static String last_battery_capacity_text;
static String last_battery_health_text;
static String last_inside_temp_text; static String last_inside_temp_text;
static String last_outside_temp_text; static String last_outside_temp_text;
static String last_system_status_text; static String last_system_status_text;
@@ -126,27 +122,10 @@ static void update_battery_soc_gauge()
static void update_battery_charge_animation() static void update_battery_charge_animation()
{ {
if (battery_charge_pulse_arc == nullptr || status_model.current <= 0.05) { // Intentionally disabled for now.
return; // Repeated style changes on the RGB panel caused artifacts/freezes during WiFi/API updates.
}
static unsigned long last_pulse_ms = 0;
static bool pulse_high = false;
if (millis() - last_pulse_ms < 450) {
return;
}
last_pulse_ms = millis();
pulse_high = !pulse_high;
lvgl_port_lock(-1);
lv_obj_set_style_arc_width(battery_charge_pulse_arc, pulse_high ? 20 : 12, LV_PART_INDICATOR);
lv_obj_set_style_arc_opa(battery_charge_pulse_arc, pulse_high ? LV_OPA_80 : LV_OPA_30, LV_PART_INDICATOR);
lvgl_port_unlock();
} }
static void set_label_text_if_changed(lv_obj_t *label, String &last_text, const String &text) static void set_label_text_if_changed(lv_obj_t *label, String &last_text, const String &text)
{ {
if (label == nullptr || last_text == text) { if (label == nullptr || last_text == text) {
@@ -359,32 +338,12 @@ static void update_overview_widgets()
String soc_text; String soc_text;
soc_text += status_model.soc >= 0 ? String(status_model.soc) : "--"; soc_text += status_model.soc >= 0 ? String(status_model.soc) : "--";
soc_text += "% SOC"; soc_text += "%";
String capacity_text;
capacity_text += String(status_model.remaining_ah, 1);
capacity_text += " / ";
capacity_text += String(status_model.capacity_ah, 0);
capacity_text += " Ah";
String health_text;
health_text += "BMS ";
health_text += status_model.bms_connected ? "online" : "offline";
health_text += " | ";
health_text += String(status_model.battery_temp_f, 1);
health_text += " F";
if (status_model.cell_delta_mv >= 0) {
health_text += "\nCell delta ";
health_text += String(status_model.cell_delta_mv);
health_text += " mV";
}
update_battery_soc_gauge(); update_battery_soc_gauge();
set_label_text_if_changed(battery_voltage_label, last_battery_voltage_text, voltage_text); set_label_text_if_changed(battery_voltage_label, last_battery_voltage_text, voltage_text);
update_battery_current_label(current_text, status_model.current); update_battery_current_label(current_text, status_model.current);
set_label_text_if_changed(battery_soc_label, last_battery_soc_text, soc_text); set_label_text_if_changed(battery_soc_label, last_battery_soc_text, soc_text);
set_label_text_if_changed(battery_capacity_label, last_battery_capacity_text, capacity_text);
set_label_text_if_changed(battery_health_label, last_battery_health_text, health_text);
set_label_text_if_changed(system_status_label, last_system_status_text, last_system_status_text); set_label_text_if_changed(system_status_label, last_system_status_text, last_system_status_text);
} }
@@ -579,8 +538,8 @@ static void create_overland_overview_screen()
lv_obj_t *system_card = create_card(screen, "System", 620, 175, LV_ALIGN_BOTTOM_LEFT, 32, -50); lv_obj_t *system_card = create_card(screen, "System", 620, 175, LV_ALIGN_BOTTOM_LEFT, 32, -50);
battery_charge_pulse_arc = lv_arc_create(battery_card); battery_charge_pulse_arc = lv_arc_create(battery_card);
lv_obj_set_size(battery_charge_pulse_arc, 172, 172); lv_obj_set_size(battery_charge_pulse_arc, 180, 180);
lv_obj_align(battery_charge_pulse_arc, LV_ALIGN_TOP_MID, 0, 30); lv_obj_align(battery_charge_pulse_arc, LV_ALIGN_TOP_MID, 0, 34);
lv_arc_set_range(battery_charge_pulse_arc, 0, 100); lv_arc_set_range(battery_charge_pulse_arc, 0, 100);
lv_arc_set_value(battery_charge_pulse_arc, 0); lv_arc_set_value(battery_charge_pulse_arc, 0);
lv_arc_set_rotation(battery_charge_pulse_arc, 135); lv_arc_set_rotation(battery_charge_pulse_arc, 135);
@@ -589,13 +548,13 @@ static void create_overland_overview_screen()
lv_obj_clear_flag(battery_charge_pulse_arc, LV_OBJ_FLAG_CLICKABLE); lv_obj_clear_flag(battery_charge_pulse_arc, LV_OBJ_FLAG_CLICKABLE);
lv_obj_set_style_arc_opa(battery_charge_pulse_arc, LV_OPA_TRANSP, LV_PART_MAIN); lv_obj_set_style_arc_opa(battery_charge_pulse_arc, LV_OPA_TRANSP, LV_PART_MAIN);
lv_obj_set_style_arc_color(battery_charge_pulse_arc, lv_color_hex(0x32D583), LV_PART_INDICATOR); lv_obj_set_style_arc_color(battery_charge_pulse_arc, lv_color_hex(0x32D583), LV_PART_INDICATOR);
lv_obj_set_style_arc_width(battery_charge_pulse_arc, 14, LV_PART_INDICATOR); lv_obj_set_style_arc_width(battery_charge_pulse_arc, 18, LV_PART_INDICATOR);
lv_obj_set_style_arc_opa(battery_charge_pulse_arc, LV_OPA_30, LV_PART_INDICATOR); lv_obj_set_style_arc_opa(battery_charge_pulse_arc, LV_OPA_30, LV_PART_INDICATOR);
lv_obj_add_flag(battery_charge_pulse_arc, LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(battery_charge_pulse_arc, LV_OBJ_FLAG_HIDDEN);
battery_soc_arc = lv_arc_create(battery_card); battery_soc_arc = lv_arc_create(battery_card);
lv_obj_set_size(battery_soc_arc, 158, 158); lv_obj_set_size(battery_soc_arc, 166, 166);
lv_obj_align(battery_soc_arc, LV_ALIGN_TOP_MID, 0, 37); lv_obj_align(battery_soc_arc, LV_ALIGN_TOP_MID, 0, 41);
lv_arc_set_range(battery_soc_arc, 0, 100); lv_arc_set_range(battery_soc_arc, 0, 100);
lv_arc_set_value(battery_soc_arc, 0); lv_arc_set_value(battery_soc_arc, 0);
lv_arc_set_rotation(battery_soc_arc, 135); lv_arc_set_rotation(battery_soc_arc, 135);
@@ -603,47 +562,32 @@ static void create_overland_overview_screen()
lv_obj_remove_style(battery_soc_arc, NULL, LV_PART_KNOB); lv_obj_remove_style(battery_soc_arc, NULL, LV_PART_KNOB);
lv_obj_clear_flag(battery_soc_arc, LV_OBJ_FLAG_CLICKABLE); lv_obj_clear_flag(battery_soc_arc, LV_OBJ_FLAG_CLICKABLE);
lv_obj_set_style_arc_color(battery_soc_arc, lv_color_hex(0x3A4652), LV_PART_MAIN); lv_obj_set_style_arc_color(battery_soc_arc, lv_color_hex(0x3A4652), LV_PART_MAIN);
lv_obj_set_style_arc_width(battery_soc_arc, 13, LV_PART_MAIN); lv_obj_set_style_arc_width(battery_soc_arc, 14, LV_PART_MAIN);
lv_obj_set_style_arc_color(battery_soc_arc, lv_color_hex(0x84CAFF), LV_PART_INDICATOR); lv_obj_set_style_arc_color(battery_soc_arc, lv_color_hex(0x84CAFF), LV_PART_INDICATOR);
lv_obj_set_style_arc_width(battery_soc_arc, 13, LV_PART_INDICATOR); lv_obj_set_style_arc_width(battery_soc_arc, 14, LV_PART_INDICATOR);
battery_voltage_label = lv_label_create(battery_card); battery_voltage_label = lv_label_create(battery_card);
lv_label_set_text(battery_voltage_label, "-- V"); lv_label_set_text(battery_voltage_label, "-- V");
lv_obj_set_style_text_color(battery_voltage_label, lv_color_hex(0xFFFFFF), 0); lv_obj_set_style_text_color(battery_voltage_label, lv_color_hex(0xFFFFFF), 0);
lv_obj_set_style_text_font(battery_voltage_label, &lv_font_montserrat_30, 0); lv_obj_set_style_text_font(battery_voltage_label, &lv_font_montserrat_30, 0);
lv_obj_set_width(battery_voltage_label, 180); lv_obj_set_width(battery_voltage_label, 190);
lv_obj_set_style_text_align(battery_voltage_label, LV_TEXT_ALIGN_CENTER, 0); lv_obj_set_style_text_align(battery_voltage_label, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_align(battery_voltage_label, LV_ALIGN_TOP_MID, 0, 83); lv_obj_align(battery_voltage_label, LV_ALIGN_TOP_MID, 0, 90);
battery_current_label = lv_label_create(battery_card); battery_current_label = lv_label_create(battery_card);
lv_label_set_text(battery_current_label, ""); lv_label_set_text(battery_current_label, "");
lv_obj_set_style_text_color(battery_current_label, lv_color_hex(0xB8C0C8), 0); lv_obj_set_style_text_color(battery_current_label, lv_color_hex(0xB8C0C8), 0);
lv_obj_set_width(battery_current_label, 170); lv_obj_set_width(battery_current_label, 180);
lv_obj_set_style_text_align(battery_current_label, LV_TEXT_ALIGN_CENTER, 0); lv_obj_set_style_text_align(battery_current_label, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_align(battery_current_label, LV_ALIGN_TOP_MID, 0, 122); lv_obj_align(battery_current_label, LV_ALIGN_TOP_MID, 0, 132);
lv_obj_add_flag(battery_current_label, LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(battery_current_label, LV_OBJ_FLAG_HIDDEN);
battery_soc_label = lv_label_create(battery_card); battery_soc_label = lv_label_create(battery_card);
lv_label_set_text(battery_soc_label, "--% SOC"); lv_label_set_text(battery_soc_label, "--%");
lv_obj_set_style_text_color(battery_soc_label, lv_color_hex(0xB8C0C8), 0); lv_obj_set_style_text_color(battery_soc_label, lv_color_hex(0xB8C0C8), 0);
lv_obj_set_width(battery_soc_label, 180); lv_obj_set_width(battery_soc_label, 180);
lv_obj_set_style_text_align(battery_soc_label, LV_TEXT_ALIGN_CENTER, 0); lv_obj_set_style_text_align(battery_soc_label, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_align(battery_soc_label, LV_ALIGN_TOP_MID, 0, 155); lv_obj_align(battery_soc_label, LV_ALIGN_TOP_MID, 0, 198);
battery_capacity_label = lv_label_create(battery_card);
lv_label_set_text(battery_capacity_label, "-- / -- Ah");
lv_obj_set_style_text_color(battery_capacity_label, lv_color_hex(0xDDE3EA), 0);
lv_obj_set_width(battery_capacity_label, 260);
lv_obj_set_style_text_align(battery_capacity_label, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_align(battery_capacity_label, LV_ALIGN_TOP_MID, 0, 190);
battery_health_label = lv_label_create(battery_card);
lv_label_set_text(battery_health_label, "Waiting for BMS...");
lv_obj_set_style_text_color(battery_health_label, lv_color_hex(0xB8C0C8), 0);
lv_obj_set_width(battery_health_label, 260);
lv_label_set_long_mode(battery_health_label, LV_LABEL_LONG_WRAP);
lv_obj_set_style_text_align(battery_health_label, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_align(battery_health_label, LV_ALIGN_TOP_MID, 0, 214);
inside_temp_label = lv_label_create(temp_card); inside_temp_label = lv_label_create(temp_card);
lv_label_set_text(inside_temp_label, "Inside\n--"); lv_label_set_text(inside_temp_label, "Inside\n--");
@@ -738,7 +682,6 @@ void loop()
update_system_status_label(); update_system_status_label();
process_pending_relay_command(); process_pending_relay_command();
poll_status_api(); poll_status_api();
update_battery_charge_animation();
delay(250); delay(250);
} }