Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions main/ui/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion main/ui/battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down