From 1328859d1566d9b0e2c253324ea25c07f214a087 Mon Sep 17 00:00:00 2001 From: nick Date: Thu, 11 Jun 2026 01:37:29 -0600 Subject: [PATCH] dashboard: draw fuel value on bar --- .../esp32-s3-dashboard/dashboard_config.h | 2 +- .../esp32-s3-dashboard/esp32-s3-dashboard.ino | 61 ++++++++++++++++--- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/firmware/esp32-s3-dashboard/dashboard_config.h b/firmware/esp32-s3-dashboard/dashboard_config.h index 0cd2c93..0c47277 100644 --- a/firmware/esp32-s3-dashboard/dashboard_config.h +++ b/firmware/esp32-s3-dashboard/dashboard_config.h @@ -1,6 +1,6 @@ #pragma once -static const char *DASHBOARD_VERSION = "0.1.49-vehicle-meter-fit"; +static const char *DASHBOARD_VERSION = "0.1.50-fuel-bar-value-draw"; // Update these if your Cargo ESP AP credentials are different. static const char *CARGO_WIFI_SSID = "OverlandController"; diff --git a/firmware/esp32-s3-dashboard/esp32-s3-dashboard.ino b/firmware/esp32-s3-dashboard/esp32-s3-dashboard.ino index 0ece415..e625615 100644 --- a/firmware/esp32-s3-dashboard/esp32-s3-dashboard.ino +++ b/firmware/esp32-s3-dashboard/esp32-s3-dashboard.ino @@ -608,6 +608,52 @@ static void update_system_status_label() + +static void fuel_bar_draw_value_cb(lv_event_t *e) +{ + lv_obj_draw_part_dsc_t *dsc = lv_event_get_draw_part_dsc(e); + if (dsc == nullptr || dsc->part != LV_PART_INDICATOR) { + return; + } + + lv_obj_t *bar = lv_event_get_target(e); + + lv_draw_label_dsc_t label_dsc; + lv_draw_label_dsc_init(&label_dsc); + label_dsc.font = &lv_font_montserrat_26; + + char buf[10]; + lv_snprintf(buf, sizeof(buf), "%d%%", (int)lv_bar_get_value(bar)); + + lv_point_t txt_size; + lv_txt_get_size( + &txt_size, + buf, + label_dsc.font, + label_dsc.letter_space, + label_dsc.line_space, + LV_COORD_MAX, + label_dsc.flag + ); + + lv_area_t txt_area; + + if (lv_area_get_width(dsc->draw_area) > txt_size.x + 20) { + txt_area.x2 = dsc->draw_area->x2 - 6; + txt_area.x1 = txt_area.x2 - txt_size.x + 1; + label_dsc.color = lv_color_hex(0xFFFFFF); + } else { + txt_area.x1 = dsc->draw_area->x2 + 8; + txt_area.x2 = txt_area.x1 + txt_size.x - 1; + label_dsc.color = lv_color_hex(0xFFFFFF); + } + + txt_area.y1 = dsc->draw_area->y1 + (lv_area_get_height(dsc->draw_area) - txt_size.y) / 2; + txt_area.y2 = txt_area.y1 + txt_size.y - 1; + + lv_draw_label(dsc->draw_ctx, &label_dsc, &txt_area, buf, NULL); +} + static void update_temp_tile_alert_style(int index, bool alert) { if (index < 0 || index >= 2 || temp_tile_objs[index] == nullptr) { @@ -1178,11 +1224,12 @@ static void create_overland_overview_screen() lv_label_set_text(fuel_title, "Fuel"); lv_obj_set_style_text_color(fuel_title, lv_color_hex(0xDDE3EA), 0); lv_obj_set_style_text_font(fuel_title, &lv_font_montserrat_26, 0); - lv_obj_align(fuel_title, LV_ALIGN_BOTTOM_LEFT, 14, -18); + lv_obj_align(fuel_title, LV_ALIGN_BOTTOM_LEFT, 10, -18); vehicle_fuel_bar = lv_bar_create(vehicle_card); - lv_obj_set_size(vehicle_fuel_bar, 154, 20); - lv_obj_align(vehicle_fuel_bar, LV_ALIGN_BOTTOM_LEFT, 76, -21); + lv_obj_add_event_cb(vehicle_fuel_bar, fuel_bar_draw_value_cb, LV_EVENT_DRAW_PART_END, NULL); + lv_obj_set_size(vehicle_fuel_bar, 190, 22); + lv_obj_align(vehicle_fuel_bar, LV_ALIGN_BOTTOM_LEFT, 64, -21); lv_bar_set_range(vehicle_fuel_bar, 0, 100); lv_bar_set_value(vehicle_fuel_bar, 72, LV_ANIM_OFF); lv_obj_set_style_radius(vehicle_fuel_bar, 3, 0); @@ -1200,14 +1247,12 @@ static void create_overland_overview_screen() lv_obj_set_style_bg_color(tick, lv_color_hex(0x7D8996), 0); lv_obj_set_style_border_width(tick, 0, 0); lv_obj_set_style_radius(tick, 0, 0); - lv_obj_align(tick, LV_ALIGN_BOTTOM_LEFT, 76 + (i * 38), -18); + lv_obj_align(tick, LV_ALIGN_BOTTOM_LEFT, 64 + (i * 47), -18); } vehicle_fuel_value_label = lv_label_create(vehicle_card); - lv_label_set_text(vehicle_fuel_value_label, "72%"); - lv_obj_set_style_text_color(vehicle_fuel_value_label, lv_color_hex(0xFFFFFF), 0); - lv_obj_set_style_text_font(vehicle_fuel_value_label, &lv_font_montserrat_30, 0); - lv_obj_align(vehicle_fuel_value_label, LV_ALIGN_BOTTOM_RIGHT, -12, -15); + lv_label_set_text(vehicle_fuel_value_label, ""); + lv_obj_add_flag(vehicle_fuel_value_label, LV_OBJ_FLAG_HIDDEN); for (int i = 0; i < 6; i++) { relay_buttons[i] = lv_btn_create(relay_card);