From 7fcc403c6508892bc44e23a5b540f8cba32bd11f Mon Sep 17 00:00:00 2001 From: Subinita Ray Date: Wed, 29 Apr 2026 19:26:02 +0530 Subject: [PATCH 1/5] battery: replace text-only percentage with icon family Replace the plain percentage string in battery_update() with a FontAwesome battery-level icon that reflects the charge state: battery-full (76-100%), battery-half (40-75%), battery-quarter (20-39%), battery-empty (0-19%), and a bolt glyph when charging. Colour thresholds updated to match the four bands. Add five new macro definitions to icons_24.h and icons_16.h for the battery icon family (U+F240, U+F242, U+F243, U+F244, U+F0E7). Also port the four existing icon macros into icons_16.h so callers that include only the 16px header have the full symbol set. Generation commands in both headers updated to include the new codepoints. --- main/ui/assets/icons_16.h | 15 ++++++++++++++- main/ui/assets/icons_24.h | 9 ++++++++- main/ui/battery.c | 24 ++++++++++++++++++++---- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/main/ui/assets/icons_16.h b/main/ui/assets/icons_16.h index 44cee28..6a353d5 100644 --- a/main/ui/assets/icons_16.h +++ b/main/ui/assets/icons_16.h @@ -6,7 +6,7 @@ * Generation command: * lv_font_conv --bpp 4 --size 16 --no-compress --stride 1 --align 1 * --font "Font Awesome 7 Free-Solid-900.otf" - * --range 0xE0B4,0xF029,0xF126,0xF577 + * --range 0xE0B4,0xF029,0xF126,0xF577,0xF240,0xF242,0xF243,0xF244,0xF0E7 * --format lvgl -o icons_16.c */ @@ -18,4 +18,17 @@ // Declare the icon font (defined in icons_16.c) LV_FONT_DECLARE(icons_16); +// Icon symbol definitions (UTF-8 encoded) +#define ICON_DERIVATION "\xEF\x84\xA6" // FontAwesome U+F126 = code-branch +#define ICON_FINGERPRINT "\xEF\x95\xB7" // FontAwesome U+F577 = fingerprint +#define ICON_BITCOIN "\xEE\x82\xB4" // FontAwesome U+E0B4 = Bitcoin +#define ICON_QR_CODE "\xEF\x80\xA9" // FontAwesome U+F029 = QR code + +// Battery icon family (FontAwesome 7 Free Solid) +#define ICON_BATTERY_FULL "\xEF\x89\x80" // FontAwesome U+F240 = battery-full +#define ICON_BATTERY_HALF "\xEF\x89\x82" // FontAwesome U+F242 = battery-half +#define ICON_BATTERY_QUARTER "\xEF\x89\x83" // FontAwesome U+F243 = battery-quarter +#define ICON_BATTERY_EMPTY "\xEF\x89\x84" // FontAwesome U+F244 = battery-empty +#define ICON_BATTERY_CHARGING_BOLT "\xEF\x83\xA7" // FontAwesome U+F0E7 = bolt + #endif // ICONS_16_H diff --git a/main/ui/assets/icons_24.h b/main/ui/assets/icons_24.h index 0627cde..90de3e9 100644 --- a/main/ui/assets/icons_24.h +++ b/main/ui/assets/icons_24.h @@ -4,7 +4,7 @@ * Size: 24px, Bpp: 4 * * Generation command (online converter): - * Range: 0xF126, 0xF577, 0xE0B4, 0xF029 + * Range: 0xF126, 0xF577, 0xE0B4, 0xF029, 0xF240, 0xF242, 0xF243, 0xF244, 0xF0E7 */ #ifndef ICONS_24_H @@ -21,4 +21,11 @@ LV_FONT_DECLARE(icons_24); #define ICON_BITCOIN "\xEE\x82\xB4" // FontAwesome U+E0B4 = Bitcoin #define ICON_QR_CODE "\xEF\x80\xA9" // FontAwesome U+F029 = QR code +// Battery icon family (FontAwesome 7 Free Solid) +#define ICON_BATTERY_FULL "\xEF\x89\x80" // FontAwesome U+F240 = battery-full +#define ICON_BATTERY_HALF "\xEF\x89\x82" // FontAwesome U+F242 = battery-half +#define ICON_BATTERY_QUARTER "\xEF\x89\x83" // FontAwesome U+F243 = battery-quarter +#define ICON_BATTERY_EMPTY "\xEF\x89\x84" // FontAwesome U+F244 = battery-empty +#define ICON_BATTERY_CHARGING_BOLT "\xEF\x83\xA7" // FontAwesome U+F0E7 = bolt + #endif // ICONS_24_H diff --git a/main/ui/battery.c b/main/ui/battery.c index 96a1e89..681df55 100644 --- a/main/ui/battery.c +++ b/main/ui/battery.c @@ -1,4 +1,5 @@ #include "battery.h" +#include "assets/icons_24.h" #include "theme.h" #include #include @@ -12,14 +13,29 @@ 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 *icon; + lv_color_t color; if (chg == BSP_PMIC_CHG_CHARGING) { - snprintf(buf, sizeof(buf), "%u%% " LV_SYMBOL_CHARGE, pct); + icon = ICON_BATTERY_CHARGING_BOLT; + color = yes_color(); + } else if (pct >= 76) { + icon = ICON_BATTERY_FULL; + color = yes_color(); + } else if (pct >= 40) { + icon = ICON_BATTERY_HALF; + color = main_color(); + } else if (pct >= 20) { + icon = ICON_BATTERY_QUARTER; + color = highlight_color(); } else { - snprintf(buf, sizeof(buf), "%u%%", pct); + icon = ICON_BATTERY_EMPTY; + color = error_color(); } + + char buf[32]; + snprintf(buf, sizeof(buf), "%s %u%%", 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) { From 587c59195049e5d9b73f4597d04105f5f4ddd224 Mon Sep 17 00:00:00 2001 From: Subinita Ray Date: Thu, 30 Apr 2026 09:47:29 +0530 Subject: [PATCH 2/5] battery: switch to LVGL built-in battery symbols MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the FontAwesome battery glyphs with LVGL's built-in symbol set (LV_SYMBOL_BATTERY_FULL/3/2/1/EMPTY) so no lv_font_conv regeneration is needed and the icon source stays consistent with the project's preferred LVGL-first priority. Five charge bands: full (>=76%, green), three-quarter (>=40%, white), half (>=20%, orange), quarter (>=5%, red), empty (<5%, red). When charging, LV_SYMBOL_CHARGE is prepended to the battery-level icon so the user sees both the charging indicator and the current charge state simultaneously — e.g. "⚡🔋 84%". The whole label turns green while charging. Reverts all icons_24.h and icons_16.h changes from the previous commit — this PR now only touches battery.c and battery.h. --- main/ui/assets/icons_16.h | 15 +-------------- main/ui/assets/icons_24.h | 9 +-------- main/ui/battery.c | 26 +++++++++++++++----------- main/ui/battery.h | 5 ++++- 4 files changed, 21 insertions(+), 34 deletions(-) diff --git a/main/ui/assets/icons_16.h b/main/ui/assets/icons_16.h index 6a353d5..44cee28 100644 --- a/main/ui/assets/icons_16.h +++ b/main/ui/assets/icons_16.h @@ -6,7 +6,7 @@ * Generation command: * lv_font_conv --bpp 4 --size 16 --no-compress --stride 1 --align 1 * --font "Font Awesome 7 Free-Solid-900.otf" - * --range 0xE0B4,0xF029,0xF126,0xF577,0xF240,0xF242,0xF243,0xF244,0xF0E7 + * --range 0xE0B4,0xF029,0xF126,0xF577 * --format lvgl -o icons_16.c */ @@ -18,17 +18,4 @@ // Declare the icon font (defined in icons_16.c) LV_FONT_DECLARE(icons_16); -// Icon symbol definitions (UTF-8 encoded) -#define ICON_DERIVATION "\xEF\x84\xA6" // FontAwesome U+F126 = code-branch -#define ICON_FINGERPRINT "\xEF\x95\xB7" // FontAwesome U+F577 = fingerprint -#define ICON_BITCOIN "\xEE\x82\xB4" // FontAwesome U+E0B4 = Bitcoin -#define ICON_QR_CODE "\xEF\x80\xA9" // FontAwesome U+F029 = QR code - -// Battery icon family (FontAwesome 7 Free Solid) -#define ICON_BATTERY_FULL "\xEF\x89\x80" // FontAwesome U+F240 = battery-full -#define ICON_BATTERY_HALF "\xEF\x89\x82" // FontAwesome U+F242 = battery-half -#define ICON_BATTERY_QUARTER "\xEF\x89\x83" // FontAwesome U+F243 = battery-quarter -#define ICON_BATTERY_EMPTY "\xEF\x89\x84" // FontAwesome U+F244 = battery-empty -#define ICON_BATTERY_CHARGING_BOLT "\xEF\x83\xA7" // FontAwesome U+F0E7 = bolt - #endif // ICONS_16_H diff --git a/main/ui/assets/icons_24.h b/main/ui/assets/icons_24.h index 90de3e9..0627cde 100644 --- a/main/ui/assets/icons_24.h +++ b/main/ui/assets/icons_24.h @@ -4,7 +4,7 @@ * Size: 24px, Bpp: 4 * * Generation command (online converter): - * Range: 0xF126, 0xF577, 0xE0B4, 0xF029, 0xF240, 0xF242, 0xF243, 0xF244, 0xF0E7 + * Range: 0xF126, 0xF577, 0xE0B4, 0xF029 */ #ifndef ICONS_24_H @@ -21,11 +21,4 @@ LV_FONT_DECLARE(icons_24); #define ICON_BITCOIN "\xEE\x82\xB4" // FontAwesome U+E0B4 = Bitcoin #define ICON_QR_CODE "\xEF\x80\xA9" // FontAwesome U+F029 = QR code -// Battery icon family (FontAwesome 7 Free Solid) -#define ICON_BATTERY_FULL "\xEF\x89\x80" // FontAwesome U+F240 = battery-full -#define ICON_BATTERY_HALF "\xEF\x89\x82" // FontAwesome U+F242 = battery-half -#define ICON_BATTERY_QUARTER "\xEF\x89\x83" // FontAwesome U+F243 = battery-quarter -#define ICON_BATTERY_EMPTY "\xEF\x89\x84" // FontAwesome U+F244 = battery-empty -#define ICON_BATTERY_CHARGING_BOLT "\xEF\x83\xA7" // FontAwesome U+F0E7 = bolt - #endif // ICONS_24_H diff --git a/main/ui/battery.c b/main/ui/battery.c index 681df55..203b731 100644 --- a/main/ui/battery.c +++ b/main/ui/battery.c @@ -1,5 +1,4 @@ #include "battery.h" -#include "assets/icons_24.h" #include "theme.h" #include #include @@ -13,27 +12,32 @@ static void battery_update(lv_obj_t *label) { bsp_pmic_chg_t chg = BSP_PMIC_CHG_DISCHARGING; bsp_pmic_get_charge_status(&chg); - const char *icon; + const char *battery_icon; lv_color_t color; - if (chg == BSP_PMIC_CHG_CHARGING) { - icon = ICON_BATTERY_CHARGING_BOLT; - color = yes_color(); - } else if (pct >= 76) { - icon = ICON_BATTERY_FULL; + if (pct >= 76) { + battery_icon = LV_SYMBOL_BATTERY_FULL; color = yes_color(); } else if (pct >= 40) { - icon = ICON_BATTERY_HALF; + battery_icon = LV_SYMBOL_BATTERY_3; color = main_color(); } else if (pct >= 20) { - icon = ICON_BATTERY_QUARTER; + battery_icon = LV_SYMBOL_BATTERY_2; color = highlight_color(); + } else if (pct >= 5) { + battery_icon = LV_SYMBOL_BATTERY_1; + color = error_color(); } else { - icon = ICON_BATTERY_EMPTY; + battery_icon = LV_SYMBOL_BATTERY_EMPTY; color = error_color(); } char buf[32]; - snprintf(buf, sizeof(buf), "%s %u%%", icon, pct); + if (chg == BSP_PMIC_CHG_CHARGING) { + snprintf(buf, sizeof(buf), "%s%s %u%%", LV_SYMBOL_CHARGE, battery_icon, pct); + color = yes_color(); + } else { + snprintf(buf, sizeof(buf), "%s %u%%", battery_icon, pct); + } lv_label_set_text(label, buf); lv_obj_set_style_text_color(label, color, 0); } diff --git a/main/ui/battery.h b/main/ui/battery.h index 07f29f2..c3df06e 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 prepended + * 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. * From 7601aa1e60128f2392362f49f5243df75a6765ce Mon Sep 17 00:00:00 2001 From: Subinita Ray <188707694+subinita01@users.noreply.github.com> Date: Thu, 30 Apr 2026 10:01:11 +0530 Subject: [PATCH 3/5] battery icon update pr From e4f79a1c2be723a71fc14d6b12df2a3eb1aac536 Mon Sep 17 00:00:00 2001 From: Subinita Ray Date: Thu, 30 Apr 2026 10:04:08 +0530 Subject: [PATCH 4/5] battery: show battery icon before charge symbol when charging --- main/ui/battery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/ui/battery.c b/main/ui/battery.c index 203b731..804b98d 100644 --- a/main/ui/battery.c +++ b/main/ui/battery.c @@ -33,7 +33,7 @@ static void battery_update(lv_obj_t *label) { char buf[32]; if (chg == BSP_PMIC_CHG_CHARGING) { - snprintf(buf, sizeof(buf), "%s%s %u%%", LV_SYMBOL_CHARGE, battery_icon, pct); + snprintf(buf, sizeof(buf), "%s%s %u%%", battery_icon, LV_SYMBOL_CHARGE, pct); color = yes_color(); } else { snprintf(buf, sizeof(buf), "%s %u%%", battery_icon, pct); From eb4844e3be76b951d8569f011f003f99a6295564 Mon Sep 17 00:00:00 2001 From: Subinita Ray Date: Thu, 30 Apr 2026 10:07:43 +0530 Subject: [PATCH 5/5] battery: fix docstring, charge symbol is appended not prepended --- main/ui/battery.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/ui/battery.h b/main/ui/battery.h index c3df06e..a4ff2ef 100644 --- a/main/ui/battery.h +++ b/main/ui/battery.h @@ -7,7 +7,7 @@ * Create a battery percentage label with auto-refresh timer. * 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 prepended + * 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.