cosmetic: battery related stuff

This commit is contained in:
Mikkeli Matlock
2026-02-16 14:39:21 +09:00
parent a25e4b2cb3
commit 7165f56464
7 changed files with 40 additions and 7 deletions

View File

@@ -19,6 +19,7 @@
/* Top bar */
static lv_obj_t *lbl_ip;
static lv_obj_t *lbl_batt;
static lv_obj_t *lbl_batt_v;
static lv_obj_t *bar_batt_top;
static lv_obj_t *lbl_ws;
@@ -160,6 +161,13 @@ static void create_top_bar(lv_obj_t *parent)
lv_obj_align(lbl_ws, LV_ALIGN_LEFT_MID, 140, 0);
lv_label_set_text(lbl_ws, "WS:---");
/* Battery voltage — left of bar */
lbl_batt_v = lv_label_create(bar_cont);
lv_obj_set_style_text_color(lbl_batt_v, lv_color_white(), 0);
lv_obj_set_style_text_font(lbl_batt_v, &InziuIosevka_Slab_CC_12px, 0);
lv_obj_align(lbl_batt_v, LV_ALIGN_RIGHT_MID, -72, 0);
lv_label_set_text(lbl_batt_v, "-.--V");
/* Battery bar (24x10) — right */
bar_batt_top = lv_bar_create(bar_cont);
lv_obj_set_size(bar_batt_top, 24, 10);
@@ -169,6 +177,17 @@ static void create_top_bar(lv_obj_t *parent)
lv_obj_add_style(bar_batt_top, &style_bar_batt_bg, LV_PART_MAIN);
lv_obj_add_style(bar_batt_top, &style_bar_batt_ind, LV_PART_INDICATOR);
/* Battery positive terminal nub */
lv_obj_t *batt_nub = lv_obj_create(bar_cont);
lv_obj_set_size(batt_nub, 2, 4);
lv_obj_align(batt_nub, LV_ALIGN_RIGHT_MID, -37, 0);
lv_obj_set_style_bg_color(batt_nub, lv_color_white(), 0);
lv_obj_set_style_bg_opa(batt_nub, LV_OPA_COVER, 0);
lv_obj_set_style_border_width(batt_nub, 0, 0);
lv_obj_set_style_radius(batt_nub, 0, 0);
lv_obj_set_style_pad_all(batt_nub, 0, 0);
lv_obj_clear_flag(batt_nub, LV_OBJ_FLAG_SCROLLABLE);
/* Battery text — right of bar */
lbl_batt = lv_label_create(bar_cont);
lv_obj_set_style_text_color(lbl_batt, lv_color_white(), 0);
@@ -371,15 +390,19 @@ void dashboard_ui_update_stats(const pi_stats_t *stats)
lv_label_set_text(lbl_net, net_buf);
}
void dashboard_ui_update_local(float temp, float humidity, uint8_t battery)
void dashboard_ui_update_local(float temp, float humidity, uint8_t battery, bool charging, float voltage)
{
char buf[32];
snprintf(buf, sizeof(buf), "T: %.1f H: %.0f%%", temp, humidity);
lv_label_set_text(lbl_local, buf);
/* Update top bar battery voltage */
snprintf(buf, sizeof(buf), "%.2fV", voltage);
lv_label_set_text(lbl_batt_v, buf);
/* Update top bar battery text + bar */
snprintf(buf, sizeof(buf), "%d%%", battery);
snprintf(buf, sizeof(buf), charging ? "%d%%C" : "%d%%", battery);
lv_label_set_text(lbl_batt, buf);
lv_bar_set_value(bar_batt_top, battery, LV_ANIM_OFF);
}

View File

@@ -21,7 +21,7 @@ void dashboard_ui_update_stats(const pi_stats_t *stats);
/**
* Update local sensor readings. LVGL lock must be held by caller.
*/
void dashboard_ui_update_local(float temp, float humidity, uint8_t battery);
void dashboard_ui_update_local(float temp, float humidity, uint8_t battery, bool charging, float voltage);
/**
* Update clock and date display. LVGL lock must be held by caller.