diff --git a/main/ui/battery.c b/main/ui/battery.c index 96a1e89..804b98d 100644 --- a/main/ui/battery.c +++ b/main/ui/battery.c @@ -12,14 +12,34 @@ static void battery_update(lv_obj_t *label) { bsp_pmic_chg_t chg = BSP_PMIC_CHG_DISCHARGING; bsp_pmic_get_charge_status(&chg); - char buf[16]; + const char *battery_icon; + lv_color_t color; + if (pct >= 76) { + battery_icon = LV_SYMBOL_BATTERY_FULL; + color = yes_color(); + } else if (pct >= 40) { + battery_icon = LV_SYMBOL_BATTERY_3; + color = main_color(); + } else if (pct >= 20) { + battery_icon = LV_SYMBOL_BATTERY_2; + color = highlight_color(); + } else if (pct >= 5) { + battery_icon = LV_SYMBOL_BATTERY_1; + color = error_color(); + } else { + battery_icon = LV_SYMBOL_BATTERY_EMPTY; + color = error_color(); + } + + char buf[32]; if (chg == BSP_PMIC_CHG_CHARGING) { - snprintf(buf, sizeof(buf), "%u%% " LV_SYMBOL_CHARGE, pct); + snprintf(buf, sizeof(buf), "%s%s %u%%", battery_icon, LV_SYMBOL_CHARGE, pct); + color = yes_color(); } else { - snprintf(buf, sizeof(buf), "%u%%", pct); + snprintf(buf, sizeof(buf), "%s %u%%", battery_icon, pct); } lv_label_set_text(label, buf); - lv_obj_set_style_text_color(label, pct > 20 ? yes_color() : error_color(), 0); + lv_obj_set_style_text_color(label, color, 0); } static void battery_timer_cb(lv_timer_t *t) { diff --git a/main/ui/battery.h b/main/ui/battery.h index 07f29f2..a4ff2ef 100644 --- a/main/ui/battery.h +++ b/main/ui/battery.h @@ -5,7 +5,10 @@ /** * Create a battery percentage label with auto-refresh timer. - * Color is green above 20%, red otherwise. Shows a charge symbol when charging. + * Displays a battery-level icon (LV_SYMBOL_BATTERY_*) alongside the charge + * percentage. Colour reflects charge state: green (>=76%), white (>=40%), + * orange (>=20%), red (<20%). When charging, LV_SYMBOL_CHARGE is appended + * to the battery icon and the whole label turns green. * Returns NULL if PMIC is unavailable. The refresh timer is automatically * deleted when the label is destroyed. *