dashboard: repair battery page link errors

This commit is contained in:
2026-06-18 23:01:48 -06:00
parent 439841e5c8
commit 45f5272a94
2 changed files with 106 additions and 1 deletions
@@ -1,6 +1,6 @@
#pragma once
static const char *DASHBOARD_VERSION = "0.1.89-async-swipe-page-switch";
static const char *DASHBOARD_VERSION = "0.1.90-repair-battery-page-link";
// Update these if your Cargo ESP AP credentials are different.
//static const char *CARGO_WIFI_SSID = "OverlandController";
@@ -593,6 +593,111 @@ static void dashboard_root_event_cb(lv_event_t *event)
}
static String battery_detail_signed(float value, int decimals, const char *suffix)
{
String text;
if (value > 0.0) text += "+";
text += String(value, decimals);
text += suffix;
return text;
}
static void battery_detail_value_label(lv_obj_t *parent, const char *title, lv_obj_t **value, int x, int y)
{
lv_obj_t *card = create_card(parent, "", 285, 118, LV_ALIGN_TOP_LEFT, x, y);
lv_obj_t *title_label = lv_label_create(card);
lv_label_set_text(title_label, title);
lv_obj_set_style_text_color(title_label, lv_color_hex(0xB8C0C8), 0);
lv_obj_set_style_text_font(title_label, &lv_font_montserrat_26, 0);
lv_obj_align(title_label, LV_ALIGN_TOP_LEFT, 16, 12);
*value = lv_label_create(card);
lv_label_set_text(*value, "--");
lv_obj_set_style_text_color(*value, lv_color_hex(0xFFFFFF), 0);
lv_obj_set_style_text_font(*value, &lv_font_montserrat_30, 0);
lv_obj_set_width(*value, 250);
lv_obj_set_style_text_align(*value, LV_TEXT_ALIGN_LEFT, 0);
lv_obj_align(*value, LV_ALIGN_TOP_LEFT, 16, 58);
}
static void update_battery_detail_widgets()
{
if (battery_detail_soc_label == nullptr) return;
String soc = status_model.soc >= 0 ? String(status_model.soc) + "%" : "--%";
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 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";
set_label_text_if_changed(battery_detail_soc_label, last_battery_detail_soc_text, soc);
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);
set_label_text_if_changed(battery_detail_remaining_label, last_battery_detail_remaining_text, remaining);
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);
}
static void create_battery_detail_screen()
{
lv_obj_t *screen = lv_scr_act();
lv_obj_clean(screen);
current_dashboard_screen = SCREEN_BATTERY_DETAIL;
lv_obj_set_style_bg_color(screen, lv_color_hex(0x101418), 0);
lv_obj_add_event_cb(screen, dashboard_root_event_cb, LV_EVENT_GESTURE, nullptr);
lv_obj_t *system_card = create_card(screen, "", 960, 48, LV_ALIGN_TOP_MID, 0, 12);
lv_obj_t *title = lv_label_create(system_card);
lv_label_set_text(title, "BATTERY DETAIL");
lv_obj_set_style_text_color(title, lv_color_hex(0xFFFFFF), 0);
lv_obj_set_style_text_font(title, &lv_font_montserrat_26, 0);
lv_obj_align(title, LV_ALIGN_LEFT_MID, 22, 0);
lv_obj_t *hint = lv_label_create(system_card);
lv_label_set_text(hint, "Swipe left for main");
lv_obj_set_style_text_color(hint, lv_color_hex(0xB8C0C8), 0);
lv_obj_set_style_text_font(hint, &lv_font_montserrat_26, 0);
lv_obj_align(hint, LV_ALIGN_RIGHT_MID, -18, 0);
lv_obj_t *soc_card = create_card(screen, "", 300, 500, LV_ALIGN_TOP_LEFT, 32, 78);
battery_detail_soc_label = lv_label_create(soc_card);
lv_label_set_text(battery_detail_soc_label, "--%");
lv_obj_set_style_text_color(battery_detail_soc_label, lv_color_hex(0xFFFFFF), 0);
lv_obj_set_style_text_font(battery_detail_soc_label, &lv_font_montserrat_48, 0);
lv_obj_set_width(battery_detail_soc_label, 260);
lv_obj_set_style_text_align(battery_detail_soc_label, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_align(battery_detail_soc_label, LV_ALIGN_CENTER, 0, -20);
battery_detail_value_label(screen, "Voltage", &battery_detail_voltage_label, 356, 78);
battery_detail_value_label(screen, "Current", &battery_detail_current_label, 670, 78);
battery_detail_value_label(screen, "Power", &battery_detail_power_label, 356, 220);
battery_detail_value_label(screen, "Remaining", &battery_detail_remaining_label, 670, 220);
battery_detail_value_label(screen, "Capacity", &battery_detail_capacity_label, 356, 362);
battery_detail_value_label(screen, "Battery Temp", &battery_detail_temp_label, 670, 362);
battery_detail_value_label(screen, "Cell Delta", &battery_detail_delta_label, 356, 504);
update_battery_detail_widgets();
}
static void show_dashboard_screen(DashboardScreen screen)
{
if (screen == current_dashboard_screen) return;
if (screen == SCREEN_BATTERY_DETAIL) {
create_battery_detail_screen();
} else {
create_overland_overview_screen();
}
}
static void layout_relay_buttons()
{
int visible_count = relay_count;