Fix dashboard layout so labels no longer cover the chart.

Carve exclusive regions for gauges, info, and trend; tighten spacing and polish arc/bar animation plus tap/long-press feedback.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-17 16:35:43 +08:00
parent 482be39c01
commit b9f2d83277
2 changed files with 177 additions and 64 deletions

View File

@@ -15,10 +15,10 @@ ESP32 Cheap Yellow Display(ESP32-2432S028R)+ DHT11 + LVGL 温湿度仪表盘
## 功能
- 横屏温湿度圆弧仪表 + 数字读数
- EMA 平滑、min/max、舒适度、体感温度 / 露点
- 温湿度趋势折线
- 点按屏幕切换背光亮度(4 档)
- 横屏网格布局:双圆弧仪表 + 底部左信息 / 右趋势图(分区不重叠)
- EMA 平滑、min/max、舒适度条、体感 / 露点分行显示
- 圆弧与舒适度条缓动动画;趋势折线 SHIFT 更新
- 短按切换背光(4 档,顶部提示);长按 ≥0.7s 重置 min/max
- 偶发 DHT 读失败容错(连续失败才报错)
- 常亮运行(无自动熄屏 / 休眠)
@@ -121,3 +121,4 @@ git reset --hard v1.1-case-snaps
| 2026-10-17 | 打标签 `v1.0-case-closed` 作为可回滚稳定版 |
| 2026-10-17 | 外壳 v1.1:外圆角 R3.5、四侧悬臂卡扣、定位柱、卡扣试打样件 |
| 2026-10-17 | 打标签 `v1.1-case-snaps`(及分支 `keep/v1.1-case-snaps`)作为可回滚稳定版 |
| 2026-10-17 | UI 重排:修文字压图表;表盘/底栏分区;动画与短按/长按交互 |

View File

@@ -27,6 +27,19 @@
#define HISTORY_LEN 48
#define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8))
/* Layout grid — every region has exclusive space, no overlaps */
#define UI_M 6
#define UI_G 6
#define UI_HDR_H 28
#define UI_GAUGE_H 120
#define UI_GAUGE_W 151
#define UI_ARC 90
#define UI_BOT_Y (UI_HDR_H + UI_G + UI_GAUGE_H + UI_G) /* 160 */
#define UI_BOT_H (SCREEN_HEIGHT - UI_BOT_Y - UI_M) /* 74 */
#define UI_BOT_W (SCREEN_WIDTH - 2 * UI_M) /* 308 */
#define UI_INFO_W 124
#define UI_CHART_W (UI_BOT_W - 12 - UI_INFO_W - UI_G) /* ~160 */
static const lv_color_t COL_BG = lv_color_hex(0x0A1018);
static const lv_color_t COL_PANEL = lv_color_hex(0x121C2A);
static const lv_color_t COL_EDGE = lv_color_hex(0x1E2C40);
@@ -41,6 +54,7 @@ static const lv_color_t COL_OK = lv_color_hex(0x4CAF7A);
static const lv_color_t COL_WARN = lv_color_hex(0xE6B84D);
static const lv_color_t COL_BAD = lv_color_hex(0xE05A5A);
static const lv_color_t COL_ARC_BG = lv_color_hex(0x243247);
static const lv_color_t COL_CHART_BG = lv_color_hex(0x0E1622);
SPIClass touchscreenSPI = SPIClass(VSPI);
XPT2046_Touchscreen touchscreen(XPT2046_CS, XPT2046_IRQ);
@@ -56,8 +70,10 @@ static lv_obj_t *lbl_temp_range;
static lv_obj_t *lbl_hum_range;
static lv_obj_t *lbl_comfort;
static lv_obj_t *lbl_feels;
static lv_obj_t *lbl_dew;
static lv_obj_t *lbl_status;
static lv_obj_t *lbl_uptime;
static lv_obj_t *lbl_hint;
static lv_obj_t *led_status;
static lv_obj_t *bar_comfort;
static lv_obj_t *chart;
@@ -76,6 +92,7 @@ static uint8_t fail_streak = 0;
static bool sensor_ok = false;
static uint8_t bright_level = 2;
static const uint8_t BRIGHT_PWM[4] = {40, 90, 160, 255};
static uint32_t hint_until_ms = 0;
static void set_backlight(uint8_t level) {
bright_level = level & 0x03;
@@ -116,9 +133,9 @@ static lv_color_t temp_color(float t) {
static const char *comfort_text(float t, float h) {
if (isnan(t) || isnan(h)) return "NO DATA";
if (t < 16 || t > 30 || h < 30 || h > 75) return "UNCOMFORTABLE";
if (t >= 20 && t <= 26 && h >= 40 && h <= 60) return "COMFORTABLE";
return "ACCEPTABLE";
if (t < 16 || t > 30 || h < 30 || h > 75) return "UNCOMFY";
if (t >= 20 && t <= 26 && h >= 40 && h <= 60) return "COMFY";
return "OK";
}
static lv_color_t comfort_color(float t, float h) {
@@ -136,6 +153,26 @@ static int comfort_score(float t, float h) {
return constrain(score, 0, 100);
}
static void show_hint(const char *text, uint32_t ms) {
lv_label_set_text(lbl_hint, text);
lv_obj_remove_flag(lbl_hint, LV_OBJ_FLAG_HIDDEN);
hint_until_ms = millis() + ms;
}
static void reset_minmax(void) {
if (!isnan(disp_temp)) {
min_temp = max_temp = disp_temp;
} else {
min_temp = max_temp = NAN;
}
if (!isnan(disp_hum)) {
min_hum = max_hum = disp_hum;
} else {
min_hum = max_hum = NAN;
}
show_hint("min/max reset", 1200);
}
static void touchscreen_read(lv_indev_t *indev, lv_indev_data_t *data) {
LV_UNUSED(indev);
static bool was_pressed = false;
@@ -154,8 +191,14 @@ static void touchscreen_read(lv_indev_t *indev, lv_indev_data_t *data) {
data->state = LV_INDEV_STATE_RELEASED;
if (was_pressed) {
was_pressed = false;
if (millis() - press_ms < 400) {
uint32_t held = millis() - press_ms;
if (held >= 700) {
reset_minmax();
} else if (held < 400) {
set_backlight((bright_level + 1) & 0x03);
char buf[20];
lv_snprintf(buf, sizeof(buf), "brightness %u/3", (unsigned)bright_level);
show_hint(buf, 900);
}
}
}
@@ -172,12 +215,29 @@ static void anim_arc(lv_obj_t *arc, int32_t value) {
lv_anim_init(&a);
lv_anim_set_var(&a, arc);
lv_anim_set_values(&a, cur, value);
lv_anim_set_duration(&a, 450);
lv_anim_set_duration(&a, 520);
lv_anim_set_exec_cb(&a, arc_anim_exec);
lv_anim_set_path_cb(&a, lv_anim_path_ease_out);
lv_anim_start(&a);
}
static void bar_anim_exec(void *obj, int32_t v) {
lv_bar_set_value((lv_obj_t *)obj, v, LV_ANIM_OFF);
}
static void anim_bar(lv_obj_t *bar, int32_t value) {
int32_t cur = lv_bar_get_value(bar);
if (cur == value) return;
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, bar);
lv_anim_set_values(&a, cur, value);
lv_anim_set_duration(&a, 400);
lv_anim_set_exec_cb(&a, bar_anim_exec);
lv_anim_set_path_cb(&a, lv_anim_path_ease_out);
lv_anim_start(&a);
}
static lv_obj_t *make_panel(lv_obj_t *parent, int x, int y, int w, int h) {
lv_obj_t *p = lv_obj_create(parent);
lv_obj_set_pos(p, x, y);
@@ -186,16 +246,20 @@ static lv_obj_t *make_panel(lv_obj_t *parent, int x, int y, int w, int h) {
lv_obj_set_style_bg_opa(p, LV_OPA_COVER, 0);
lv_obj_set_style_border_color(p, COL_EDGE, 0);
lv_obj_set_style_border_width(p, 1, 0);
lv_obj_set_style_radius(p, 14, 0);
lv_obj_set_style_radius(p, 12, 0);
lv_obj_set_style_pad_all(p, 6, 0);
lv_obj_set_style_pad_row(p, 0, 0);
lv_obj_set_style_pad_column(p, 0, 0);
lv_obj_clear_flag(p, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_remove_flag(p, LV_OBJ_FLAG_SCROLLABLE);
return p;
}
static lv_obj_t *make_gauge(lv_obj_t *parent, lv_color_t accent, int max_val) {
lv_obj_t *arc = lv_arc_create(parent);
lv_obj_set_size(arc, 112, 112);
lv_obj_align(arc, LV_ALIGN_TOP_MID, 0, 14);
lv_obj_set_size(arc, UI_ARC, UI_ARC);
/* Leave room under arc for min/max line (~16px) */
lv_obj_align(arc, LV_ALIGN_TOP_MID, 0, 2);
lv_arc_set_rotation(arc, 135);
lv_arc_set_bg_angles(arc, 0, 270);
lv_arc_set_range(arc, 0, max_val);
@@ -203,9 +267,9 @@ static lv_obj_t *make_gauge(lv_obj_t *parent, lv_color_t accent, int max_val) {
lv_obj_remove_style(arc, NULL, LV_PART_KNOB);
lv_obj_clear_flag(arc, LV_OBJ_FLAG_CLICKABLE);
lv_obj_set_style_arc_color(arc, COL_ARC_BG, LV_PART_MAIN);
lv_obj_set_style_arc_width(arc, 12, LV_PART_MAIN);
lv_obj_set_style_arc_width(arc, 10, LV_PART_MAIN);
lv_obj_set_style_arc_color(arc, accent, LV_PART_INDICATOR);
lv_obj_set_style_arc_width(arc, 12, LV_PART_INDICATOR);
lv_obj_set_style_arc_width(arc, 10, LV_PART_INDICATOR);
lv_obj_set_style_arc_rounded(arc, true, LV_PART_MAIN);
lv_obj_set_style_arc_rounded(arc, true, LV_PART_INDICATOR);
return arc;
@@ -217,21 +281,22 @@ static void create_ui(void) {
lv_obj_set_style_bg_opa(scr, LV_OPA_COVER, 0);
lv_obj_clear_flag(scr, LV_OBJ_FLAG_SCROLLABLE);
/* ---- header (exclusive 0..28) ---- */
lv_obj_t *title = lv_label_create(scr);
lv_label_set_text(title, "ROOM CLIMATE");
lv_label_set_text(title, "CLIMATE");
lv_obj_set_style_text_font(title, &lv_font_montserrat_16, 0);
lv_obj_set_style_text_color(title, COL_TEXT, 0);
lv_obj_align(title, LV_ALIGN_TOP_LEFT, 10, 6);
lv_obj_set_pos(title, UI_M, 4);
lbl_uptime = lv_label_create(scr);
lv_label_set_text(lbl_uptime, "tap: brightness");
lv_label_set_text(lbl_uptime, "up 00:00");
lv_obj_set_style_text_font(lbl_uptime, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(lbl_uptime, COL_MUTED, 0);
lv_obj_align(lbl_uptime, LV_ALIGN_TOP_LEFT, 10, 24);
lv_obj_set_pos(lbl_uptime, UI_M, 22);
led_status = lv_led_create(scr);
lv_obj_set_size(led_status, 10, 10);
lv_obj_align(led_status, LV_ALIGN_TOP_RIGHT, -10, 10);
lv_obj_set_size(led_status, 9, 9);
lv_obj_align(led_status, LV_ALIGN_TOP_RIGHT, -UI_M, 8);
lv_led_set_color(led_status, COL_WARN);
lv_led_on(led_status);
@@ -239,95 +304,135 @@ static void create_ui(void) {
lv_label_set_text(lbl_status, "INIT");
lv_obj_set_style_text_font(lbl_status, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(lbl_status, COL_MUTED, 0);
lv_obj_align(lbl_status, LV_ALIGN_TOP_RIGHT, -26, 8);
lv_obj_align(lbl_status, LV_ALIGN_TOP_RIGHT, -(UI_M + 16), 6);
lv_obj_t *p_temp = make_panel(scr, 6, 40, 152, 132);
lbl_hint = lv_label_create(scr);
lv_label_set_text(lbl_hint, "");
lv_obj_set_style_text_font(lbl_hint, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(lbl_hint, COL_TEMP_WARM, 0);
lv_obj_align(lbl_hint, LV_ALIGN_TOP_MID, 0, 6);
lv_obj_add_flag(lbl_hint, LV_OBJ_FLAG_HIDDEN);
/* ---- gauge panels ---- */
const int gy = UI_HDR_H + UI_G; /* 34 */
lv_obj_t *p_temp = make_panel(scr, UI_M, gy, UI_GAUGE_W, UI_GAUGE_H);
lv_obj_t *t_cap = lv_label_create(p_temp);
lv_label_set_text(t_cap, "TEMP");
lv_obj_set_style_text_font(t_cap, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(t_cap, COL_MUTED, 0);
lv_obj_align(t_cap, LV_ALIGN_TOP_LEFT, 2, 0);
lv_obj_align(t_cap, LV_ALIGN_TOP_LEFT, 0, -2);
arc_temp = make_gauge(p_temp, COL_TEMP_OK, 50);
lbl_temp_val = lv_label_create(p_temp);
lv_label_set_text(lbl_temp_val, "--.-");
lv_obj_set_style_text_font(lbl_temp_val, &lv_font_montserrat_28, 0);
lv_obj_set_style_text_font(lbl_temp_val, &lv_font_montserrat_24, 0);
lv_obj_set_style_text_color(lbl_temp_val, COL_TEMP_OK, 0);
lv_obj_align(lbl_temp_val, LV_ALIGN_CENTER, 0, 6);
/* Center of arc: arc top+2, size 90 → center ~ y 47 */
lv_obj_align(lbl_temp_val, LV_ALIGN_TOP_MID, -4, 32);
lv_obj_t *t_unit = lv_label_create(p_temp);
lv_label_set_text(t_unit, "C");
lv_obj_set_style_text_font(t_unit, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(t_unit, COL_MUTED, 0);
lv_obj_align(t_unit, LV_ALIGN_CENTER, 36, 10);
lv_obj_align_to(t_unit, lbl_temp_val, LV_ALIGN_OUT_RIGHT_MID, 2, 2);
lbl_temp_range = lv_label_create(p_temp);
lv_label_set_text(lbl_temp_range, "min -- max --");
lv_label_set_text(lbl_temp_range, "-- / --");
lv_obj_set_style_text_font(lbl_temp_range, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(lbl_temp_range, COL_MUTED, 0);
lv_obj_align(lbl_temp_range, LV_ALIGN_BOTTOM_MID, 0, 0);
lv_obj_align(lbl_temp_range, LV_ALIGN_BOTTOM_MID, 0, 2);
lv_obj_t *p_hum = make_panel(scr, 162, 40, 152, 132);
lv_obj_t *p_hum = make_panel(scr, UI_M + UI_GAUGE_W + UI_G, gy, UI_GAUGE_W, UI_GAUGE_H);
lv_obj_t *h_cap = lv_label_create(p_hum);
lv_label_set_text(h_cap, "HUM");
lv_obj_set_style_text_font(h_cap, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(h_cap, COL_MUTED, 0);
lv_obj_align(h_cap, LV_ALIGN_TOP_LEFT, 2, 0);
lv_obj_align(h_cap, LV_ALIGN_TOP_LEFT, 0, -2);
arc_hum = make_gauge(p_hum, COL_HUM, 100);
lbl_hum_val = lv_label_create(p_hum);
lv_label_set_text(lbl_hum_val, "--.-");
lv_obj_set_style_text_font(lbl_hum_val, &lv_font_montserrat_28, 0);
lv_label_set_text(lbl_hum_val, "--");
lv_obj_set_style_text_font(lbl_hum_val, &lv_font_montserrat_24, 0);
lv_obj_set_style_text_color(lbl_hum_val, COL_HUM, 0);
lv_obj_align(lbl_hum_val, LV_ALIGN_CENTER, 0, 6);
lv_obj_align(lbl_hum_val, LV_ALIGN_TOP_MID, -2, 32);
lv_obj_t *h_unit = lv_label_create(p_hum);
lv_label_set_text(h_unit, "%");
lv_obj_set_style_text_font(h_unit, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(h_unit, COL_MUTED, 0);
lv_obj_align(h_unit, LV_ALIGN_CENTER, 36, 10);
lv_obj_align_to(h_unit, lbl_hum_val, LV_ALIGN_OUT_RIGHT_MID, 2, 2);
lbl_hum_range = lv_label_create(p_hum);
lv_label_set_text(lbl_hum_range, "min -- max --");
lv_label_set_text(lbl_hum_range, "-- / --");
lv_obj_set_style_text_font(lbl_hum_range, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(lbl_hum_range, COL_MUTED, 0);
lv_obj_align(lbl_hum_range, LV_ALIGN_BOTTOM_MID, 0, 0);
lv_obj_align(lbl_hum_range, LV_ALIGN_BOTTOM_MID, 0, 2);
lv_obj_t *p_bot = make_panel(scr, 6, 176, 308, 58);
lbl_comfort = lv_label_create(p_bot);
lv_label_set_text(lbl_comfort, "WAITING");
/* ---- bottom: left info | right chart (no shared space) ---- */
lv_obj_t *p_bot = make_panel(scr, UI_M, UI_BOT_Y, UI_BOT_W, UI_BOT_H);
lv_obj_t *info = lv_obj_create(p_bot);
lv_obj_set_size(info, UI_INFO_W, UI_BOT_H - 12);
lv_obj_align(info, LV_ALIGN_LEFT_MID, 0, 0);
lv_obj_set_style_bg_opa(info, LV_OPA_TRANSP, 0);
lv_obj_set_style_border_width(info, 0, 0);
lv_obj_set_style_pad_all(info, 0, 0);
lv_obj_clear_flag(info, LV_OBJ_FLAG_SCROLLABLE);
lbl_comfort = lv_label_create(info);
lv_label_set_text(lbl_comfort, "WAIT");
lv_obj_set_style_text_font(lbl_comfort, &lv_font_montserrat_14, 0);
lv_obj_set_style_text_color(lbl_comfort, COL_WARN, 0);
lv_obj_align(lbl_comfort, LV_ALIGN_TOP_LEFT, 4, 0);
lv_obj_set_width(lbl_comfort, UI_INFO_W);
lv_label_set_long_mode(lbl_comfort, LV_LABEL_LONG_CLIP);
lv_obj_align(lbl_comfort, LV_ALIGN_TOP_LEFT, 0, 0);
lbl_feels = lv_label_create(p_bot);
lv_label_set_text(lbl_feels, "FEELS -- DEW --");
lv_obj_set_style_text_font(lbl_feels, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(lbl_feels, COL_MUTED, 0);
lv_obj_align(lbl_feels, LV_ALIGN_TOP_RIGHT, -4, 2);
bar_comfort = lv_bar_create(p_bot);
lv_obj_set_size(bar_comfort, 120, 10);
lv_obj_align(bar_comfort, LV_ALIGN_TOP_LEFT, 4, 20);
bar_comfort = lv_bar_create(info);
lv_obj_set_size(bar_comfort, UI_INFO_W - 4, 8);
lv_obj_align(bar_comfort, LV_ALIGN_TOP_LEFT, 0, 20);
lv_bar_set_range(bar_comfort, 0, 100);
lv_bar_set_value(bar_comfort, 0, LV_ANIM_OFF);
lv_obj_set_style_bg_color(bar_comfort, COL_ARC_BG, LV_PART_MAIN);
lv_obj_set_style_bg_opa(bar_comfort, LV_OPA_COVER, LV_PART_MAIN);
lv_obj_set_style_radius(bar_comfort, 5, LV_PART_MAIN);
lv_obj_set_style_radius(bar_comfort, 4, LV_PART_MAIN);
lv_obj_set_style_bg_color(bar_comfort, COL_WARN, LV_PART_INDICATOR);
lv_obj_set_style_radius(bar_comfort, 5, LV_PART_INDICATOR);
lv_obj_set_style_radius(bar_comfort, 4, LV_PART_INDICATOR);
lbl_feels = lv_label_create(info);
lv_label_set_text(lbl_feels, "Feel --.-");
lv_obj_set_style_text_font(lbl_feels, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(lbl_feels, COL_MUTED, 0);
lv_obj_set_width(lbl_feels, UI_INFO_W);
lv_label_set_long_mode(lbl_feels, LV_LABEL_LONG_CLIP);
lv_obj_align(lbl_feels, LV_ALIGN_TOP_LEFT, 0, 34);
lbl_dew = lv_label_create(info);
lv_label_set_text(lbl_dew, "Dew --.-");
lv_obj_set_style_text_font(lbl_dew, &lv_font_montserrat_12, 0);
lv_obj_set_style_text_color(lbl_dew, COL_MUTED, 0);
lv_obj_set_width(lbl_dew, UI_INFO_W);
lv_label_set_long_mode(lbl_dew, LV_LABEL_LONG_CLIP);
lv_obj_align(lbl_dew, LV_ALIGN_TOP_LEFT, 0, 48);
chart = lv_chart_create(p_bot);
lv_obj_set_size(chart, 168, 28);
lv_obj_align(chart, LV_ALIGN_BOTTOM_RIGHT, -2, -2);
lv_obj_set_size(chart, UI_CHART_W, UI_BOT_H - 16);
lv_obj_align(chart, LV_ALIGN_RIGHT_MID, 0, 0);
lv_chart_set_type(chart, LV_CHART_TYPE_LINE);
lv_chart_set_point_count(chart, HISTORY_LEN);
lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, 10, 40);
lv_chart_set_range(chart, LV_CHART_AXIS_SECONDARY_Y, 0, 100);
lv_obj_set_style_bg_opa(chart, LV_OPA_TRANSP, 0);
lv_obj_set_style_border_width(chart, 0, 0);
lv_obj_set_style_pad_all(chart, 0, 0);
lv_chart_set_div_line_count(chart, 0, 0);
lv_chart_set_update_mode(chart, LV_CHART_UPDATE_MODE_SHIFT);
lv_obj_set_style_bg_color(chart, COL_CHART_BG, 0);
lv_obj_set_style_bg_opa(chart, LV_OPA_COVER, 0);
lv_obj_set_style_border_color(chart, COL_EDGE, 0);
lv_obj_set_style_border_width(chart, 1, 0);
lv_obj_set_style_radius(chart, 8, 0);
lv_obj_set_style_pad_all(chart, 4, 0);
lv_obj_set_style_line_width(chart, 2, LV_PART_ITEMS);
lv_chart_set_div_line_count(chart, 2, 4);
lv_obj_set_style_line_color(chart, COL_EDGE, LV_PART_MAIN);
lv_obj_set_style_line_opa(chart, LV_OPA_40, LV_PART_MAIN);
ser_temp = lv_chart_add_series(chart, COL_TEMP_WARM, LV_CHART_AXIS_PRIMARY_Y);
ser_hum = lv_chart_add_series(chart, COL_HUM, LV_CHART_AXIS_SECONDARY_Y);
}
@@ -335,10 +440,15 @@ static void create_ui(void) {
static void refresh_meta(void) {
char buf[40];
uint32_t up = millis() / 1000;
lv_snprintf(buf, sizeof(buf), "up %02lu:%02lu bl %u/3",
lv_snprintf(buf, sizeof(buf), "up %02lu:%02lu bl%u",
(unsigned long)(up / 60), (unsigned long)(up % 60), (unsigned)bright_level);
lv_label_set_text(lbl_uptime, buf);
if (hint_until_ms && (int32_t)(millis() - hint_until_ms) >= 0) {
hint_until_ms = 0;
lv_obj_add_flag(lbl_hint, LV_OBJ_FLAG_HIDDEN);
}
if (sensor_ok) {
uint32_t age = (millis() - last_ok_ms) / 1000;
lv_snprintf(buf, sizeof(buf), "LIVE %lus", (unsigned long)age);
@@ -348,7 +458,7 @@ static void refresh_meta(void) {
}
static void update_ui(bool ok) {
char buf[40];
char buf[32];
if (ok && !isnan(disp_temp) && !isnan(disp_hum)) {
lv_color_t tc = temp_color(disp_temp);
@@ -363,27 +473,29 @@ static void update_ui(bool ok) {
lv_label_set_text(lbl_hum_val, buf);
anim_arc(arc_hum, (int)lroundf(constrain(disp_hum, 0.0f, 100.0f)));
lv_snprintf(buf, sizeof(buf), "min %.0f max %.0f", min_temp, max_temp);
lv_snprintf(buf, sizeof(buf), "%.0f / %.0f", min_temp, max_temp);
lv_label_set_text(lbl_temp_range, buf);
lv_snprintf(buf, sizeof(buf), "min %.0f max %.0f", min_hum, max_hum);
lv_snprintf(buf, sizeof(buf), "%.0f / %.0f", min_hum, max_hum);
lv_label_set_text(lbl_hum_range, buf);
float feels = heat_index_c(disp_temp, disp_hum);
float dew = dew_point_c(disp_temp, disp_hum);
lv_snprintf(buf, sizeof(buf), "FEELS %.1f DEW %.1f", feels, dew);
lv_snprintf(buf, sizeof(buf), "Feel %.1f", feels);
lv_label_set_text(lbl_feels, buf);
lv_snprintf(buf, sizeof(buf), "Dew %.1f", dew);
lv_label_set_text(lbl_dew, buf);
lv_color_t cc = comfort_color(disp_temp, disp_hum);
lv_label_set_text(lbl_comfort, comfort_text(disp_temp, disp_hum));
lv_obj_set_style_text_color(lbl_comfort, cc, 0);
lv_bar_set_value(bar_comfort, comfort_score(disp_temp, disp_hum), LV_ANIM_ON);
anim_bar(bar_comfort, comfort_score(disp_temp, disp_hum));
lv_obj_set_style_bg_color(bar_comfort, cc, LV_PART_INDICATOR);
lv_chart_set_next_value(chart, ser_temp, (int32_t)lroundf(disp_temp));
lv_chart_set_next_value(chart, ser_hum, (int32_t)lroundf(disp_hum));
refresh_meta();
} else {
lv_label_set_text(lbl_comfort, "SENSOR ERROR");
lv_label_set_text(lbl_comfort, "ERROR");
lv_obj_set_style_text_color(lbl_comfort, COL_BAD, 0);
lv_label_set_text(lbl_status, "ERR");
lv_led_set_color(led_status, COL_BAD);