| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- /**
- ******************************************************************************
- * @file Ui_status.c
- * @brief 设备状态页面 (UI 页面层)
- *
- * @note 面板1: Status/Power/Comm 三行
- * Power 恒显示 OK (上电即正常);
- * Comm 与 CPLD 通讯正常显示 OK, 否则 NO (红);
- * Status 两者全 OK 显示 Running (绿), 任一异常显示 Fault (红);
- * 面板2: TC 温度控制状态 (PID 运行中 Running 绿 / 否则 Not Running 红).
- * 页面内 500ms 定时器实时刷新 (进入页面时取最新值)。
- ******************************************************************************
- */
- #include <stdio.h>
- #include "Ui_status.h"
- #include "Ui.h"
- #include "Ui_theme.h"
- #include "App_cpld.h"
- #include "App_pidControl.h"
- /* 状态卡片位置 */
- #define UI_STATUS_PANEL_X 10
- #define UI_STATUS_PANEL_Y 48
- #define UI_STATUS_PANEL_W 610
- #define UI_STATUS_PANEL_H 200
- /* TC 控制状态卡片 (位于状态卡片下方) */
- #define UI_STATUS_TC_PANEL_Y (UI_STATUS_PANEL_Y + UI_STATUS_PANEL_H + 12)
- #define UI_STATUS_TC_PANEL_H 84
- /* 行内坐标 */
- #define UI_STATUS_KEY_X 16
- #define UI_STATUS_VALUE_OFF_X -16
- #define UI_STATUS_ROW_Y0 14 /* 首行 y */
- #define UI_STATUS_ROW_GAP 52 /* 行间距 */
- #define UI_STATUS_LINE_X 16 /* 分隔线 */
- #define UI_STATUS_LINE_W (UI_STATUS_PANEL_W - 32)
- /* 实时刷新周期 (ms) */
- #define UI_STATUS_REFRESH_MS 500
- /* 全局句柄 (页面销毁时置空) */
- static lv_obj_t * s_status_panel = NULL;
- static lv_timer_t * s_status_timer = NULL;
- static lv_obj_t * s_status_value = NULL; /* Status 值标签 */
- static lv_obj_t * s_comm_value = NULL; /* Comm 值标签 */
- static lv_obj_t * s_tc_value = NULL; /* TC 值标签 */
- static lv_obj_t * ui_status_add_item(lv_obj_t * parent, const char * key, const char * value,
- lv_coord_t y, lv_color_t value_color)
- {
- lv_obj_t * k = lv_label_create(parent);
- lv_label_set_text(k, key);
- lv_obj_set_style_text_font(k, &lv_font_montserrat_16, LV_STATE_DEFAULT);
- lv_obj_set_style_text_color(k, UI_CLR_TEXT_DIM, LV_STATE_DEFAULT);
- lv_obj_set_pos(k, UI_STATUS_KEY_X, y);
- lv_obj_t * v = lv_label_create(parent);
- lv_label_set_text(v, value);
- lv_obj_set_style_text_font(v, &lv_font_montserrat_16, LV_STATE_DEFAULT);
- lv_obj_set_style_text_color(v, value_color, LV_STATE_DEFAULT);
- lv_obj_align(v, LV_ALIGN_TOP_RIGHT, UI_STATUS_VALUE_OFF_X, y);
- return v;
- }
- /* 刷新各行动态状态 */
- static void ui_status_refresh(void)
- {
- uint8_t comm_ok = App_cpld_comm_alive();
- uint8_t pid_run = App_pidControl_is_running();
- if (s_status_value != NULL)
- {
- lv_label_set_text_static(s_status_value, comm_ok ? "Running" : "Fault");
- lv_obj_set_style_text_color(s_status_value, comm_ok ? UI_CLR_OK : UI_CLR_ERR, LV_STATE_DEFAULT);
- }
- if (s_comm_value != NULL)
- {
- lv_label_set_text_static(s_comm_value, comm_ok ? "OK" : "NO");
- lv_obj_set_style_text_color(s_comm_value, comm_ok ? UI_CLR_OK : UI_CLR_ERR, LV_STATE_DEFAULT);
- }
- if (s_tc_value != NULL)
- {
- lv_label_set_text_static(s_tc_value, pid_run ? "Running" : "Not Running");
- lv_obj_set_style_text_color(s_tc_value, pid_run ? UI_CLR_OK : UI_CLR_ERR, LV_STATE_DEFAULT);
- }
- }
- static void ui_status_timer_cb(lv_timer_t * t)
- {
- (void)t;
- ui_status_refresh();
- }
- /* 页面销毁时释放定时器, 防止悬挂指针 */
- static void ui_status_delete_cb(lv_event_t * e)
- {
- (void)e;
- s_status_panel = NULL;
- if (s_status_timer != NULL)
- {
- lv_timer_del(s_status_timer);
- s_status_timer = NULL;
- }
- }
- void Ui_status_create(lv_obj_t * parent)
- {
- Ui_theme_add_title(parent, "Device Status", 10);
- /* 状态信息卡片 */
- s_status_panel = lv_obj_create(parent);
- lv_obj_set_pos(s_status_panel, UI_STATUS_PANEL_X, UI_STATUS_PANEL_Y);
- lv_obj_set_size(s_status_panel, UI_STATUS_PANEL_W, UI_STATUS_PANEL_H);
- Ui_theme_style_panel(s_status_panel);
- lv_obj_add_event_cb(s_status_panel, ui_status_delete_cb, LV_EVENT_DELETE, NULL);
- s_status_value = ui_status_add_item(s_status_panel, "Status:", "Fault", UI_STATUS_ROW_Y0 + 0 * UI_STATUS_ROW_GAP, UI_CLR_ERR);
- ui_status_add_item(s_status_panel, "Power:", "OK", UI_STATUS_ROW_Y0 + 1 * UI_STATUS_ROW_GAP, UI_CLR_OK);
- s_comm_value = ui_status_add_item(s_status_panel, "Comm:", "NO", UI_STATUS_ROW_Y0 + 2 * UI_STATUS_ROW_GAP, UI_CLR_ERR);
- /* 行间分隔线 (前两行下方) */
- uint8_t i;
- for (i = 0; i < 2; i++)
- {
- lv_obj_t * line = lv_obj_create(s_status_panel);
- lv_obj_set_pos(line, UI_STATUS_LINE_X, UI_STATUS_ROW_Y0 + (i + 1) * UI_STATUS_ROW_GAP - 18);
- lv_obj_set_size(line, UI_STATUS_LINE_W, 1);
- Ui_theme_clear_visuals(line);
- lv_obj_set_style_bg_color(line, UI_CLR_LINE, LV_STATE_DEFAULT);
- lv_obj_set_style_bg_opa(line, LV_OPA_COVER, LV_STATE_DEFAULT);
- }
- /* TC 温度控制状态卡片 */
- lv_obj_t * tc_panel = lv_obj_create(parent);
- lv_obj_set_pos(tc_panel, UI_STATUS_PANEL_X, UI_STATUS_TC_PANEL_Y);
- lv_obj_set_size(tc_panel, UI_STATUS_PANEL_W, UI_STATUS_TC_PANEL_H);
- Ui_theme_style_panel(tc_panel);
- s_tc_value = ui_status_add_item(tc_panel, "Temperature Control:", "Not Running", 14, UI_CLR_ERR);
- ui_status_refresh();
- /* 启动实时刷新定时器 (500ms) */
- s_status_timer = lv_timer_create(ui_status_timer_cb, UI_STATUS_REFRESH_MS, NULL);
- lv_timer_set_repeat_count(s_status_timer, -1);
- }
|