Просмотр исходного кода

1. Ui.c 新增顶栏 TC 徽章,PID 运行绿,未运行红
2. Ui_status.c 状态页重写为双卡片
3. App_display.c 删除假数据 Ui_set_ready(true);顶栏 Ready 改由真实的 4s 通信存活检测 App_cpld_comm_alive()
4. 新增 s_last_rx_ticks 记录(收到有效帧时刷新)与 App_cpld_comm_alive():从未收到帧或超 4s 无有效帧即为 NO/红,否则 OK/绿。
5. App_pidControl.新增 App_pidControl_is_running() 直接读 volatile s_running,供 TC 徽章与状态页判断运行状态。
6. App_preheat. 新增 APP_PREHEAT_CMD_SKIP 命令,跳过预热直接进 PID
7. Ui_preheat.c 动画面板底部新增 Skip 按钮
8. Ui样式修改

zhanghongyi 2 месяцев назад
Родитель
Сommit
a6f06ccf85

+ 9 - 0
App/Inc/App_cpld.h

@@ -7,6 +7,7 @@
 #ifndef __APP_CPLD_H
 #define __APP_CPLD_H
 
+#include <stdint.h>
 #include "FreeRTOS.h"
 #include "task.h"
 
@@ -19,4 +20,12 @@ extern TaskHandle_t xCPLDProcessTaskHandle;
  */
 void App_cpld_task_create(void);
 
+/**
+ * @brief  查询 CPLD 通讯是否存活
+ * @note   最近 4s 内收到过任何 CPLD 有效帧 (ACK/SNAPSHOT) 视为正常
+ * @param  无
+ * @return 1=通讯正常, 0=未接通/失联
+ */
+uint8_t App_cpld_comm_alive(void);
+
 #endif /* __APP_CPLD_H */

+ 8 - 0
App/Inc/App_pidControl.h

@@ -40,4 +40,12 @@ void App_pidControl_Start(uint8_t target);
  */
 void App_pidControl_Stop(void);
 
+/**
+ * @brief  查询 PID 闭环控温是否运行中
+ * @note   供 UI/其它任务只读状态用
+ * @param  无
+ * @return 1=正在 PID 控温, 0=未运行
+ */
+uint8_t App_pidControl_is_running(void);
+
 #endif /* __APP_PIDCONTROL_H */

+ 2 - 0
App/Inc/App_preheat.h

@@ -20,6 +20,8 @@ extern TaskHandle_t xPreheatTaskHandle;
 typedef enum
 {
     APP_PREHEAT_CMD_START = 0,   /* 开始预加热 (携带目标温度) */
+    APP_PREHEAT_CMD_START_PID,   /* 直接从设置页启动 PID 控温 (携带目标温度) */
+    APP_PREHEAT_CMD_SKIP,        /* 跳过预热, 直接进入 PID 控温 */
     APP_PREHEAT_CMD_STOP         /* 停止/取消预加热 */
 } app_preheat_cmd_e;
 

+ 25 - 0
App/Src/App_cpld.c

@@ -31,8 +31,14 @@
 /* RX 滚动缓冲 (一帧最多 COM_PROTOCOL_FRAME_MAX_LEN 字节) */
 #define CPLD_RX_BUF_LEN         (COM_PROTOCOL_FRAME_MAX_LEN + 8)
 
+/* 通讯存活判定窗口: 超过该时长未收到任何有效帧视为失联 */
+#define APP_CPLD_COMM_TIMEOUT_MS  4000
+
 TaskHandle_t xCPLDProcessTaskHandle = NULL;
 
+/* 最近一次收到 CPLD 有效帧的 tick (0 = 从未收到) */
+static volatile uint32_t s_last_rx_ticks = 0;
+
 /**
  * @brief  解析刚收到的快照并打印全部遥测字段
  * @note   仅打印, 数据已由 Mid_Temp_UpdateSnapshot 缓存
@@ -142,6 +148,8 @@ static void App_Cpld_PollRx(void)
 
             if (Com_protocol_check_frame(&s_rx[pos], need, &type, &payload, &plen))
             {
+                s_last_rx_ticks = xTaskGetTickCount();
+
                 if (type == COM_PROTOCOL_TYPE_SNAPSHOT_DATA)
                 {
                     if (Mid_Temp_UpdateSnapshot(payload, plen))
@@ -183,6 +191,23 @@ static void App_Cpld_PollRx(void)
     }
 }
 
+/**
+ * @brief  查询 CPLD 通讯是否存活
+ * @note   最近 APP_CPLD_COMM_TIMEOUT_MS 内收到过任何 CPLD 有效帧
+ *         (ACK/SNAPSHOT) 视为存活; 从未收到返回 0。
+ * @param  无
+ * @return 1=通讯正常, 0=未接通/失联
+ */
+uint8_t App_cpld_comm_alive(void)
+{
+    if (s_last_rx_ticks == 0)
+    {
+        return 0;
+    }
+    return ((uint32_t)(xTaskGetTickCount() - s_last_rx_ticks) <
+            (uint32_t)pdMS_TO_TICKS(APP_CPLD_COMM_TIMEOUT_MS)) ? 1 : 0;
+}
+
 /**
  * @brief  CPLD 通信任务体: 周期下发 SET_ALL 并轮询快照
  * @note   在任务上下文完成 Mid_PID_Init()/Mid_Temp_Init() (软复位后依赖);

+ 0 - 3
App/Src/App_display.c

@@ -55,9 +55,6 @@ static void Task_LVGL_Display(void *argument)
     /* 创建工业设备主页 (UI 页面层) */
     Ui_init();
 
-    /* 假数据: 设备就绪 */
-    Ui_set_ready(true);
-
     while (1)
     {
         /* 周期驱动 LVGL(渲染/动画/输入),配合 LV_DISP_DEF_REFR_PERIOD 30ms */

+ 5 - 0
App/Src/App_pidControl.c

@@ -133,6 +133,11 @@ void App_pidControl_Stop(void)
     printf("[PID] stop\r\n");
 }
 
+uint8_t App_pidControl_is_running(void)
+{
+    return (s_running != 0) ? 1 : 0;
+}
+
 /**
  * @brief  创建 PID 控温任务
  * @note   在 vTaskStartScheduler() 之前调用一次; 句柄存于 xPidControlTaskHandle。

+ 48 - 0
App/Src/App_preheat.c

@@ -102,6 +102,38 @@ static void preheat_handle_stop(const app_preheat_cmd_t *cmd)
     s_state = PREHEAT_STATE_IDLE;
 }
 
+/**
+ * @brief  SKIP 命令处理: 跳过预热, 直接进入 PID 闭环控温
+ * @note   与达标移交同一路径: PID 接管输出, preheat 回到 IDLE 不再写 100%;
+ *         UI 经 Ui_preheat_done_exit 异步关闭预加热页返回实时页。
+ * @param  cmd : 来源命令
+ * @return 无
+ */
+static void preheat_handle_skip(const app_preheat_cmd_t *cmd)
+{
+    s_target = cmd->target;
+    printf("[Preheat] skip, start PID control target=%d src=%d\r\n",
+           (int)s_target, (int)cmd->src);
+    App_pidControl_Start((uint8_t)s_target);
+    Ui_preheat_done_exit();
+    s_state = PREHEAT_STATE_IDLE;
+}
+
+/**
+ * @brief  START_PID 命令处理: 从温度设置页直接启动 PID 闭环控温
+ * @note   不经过预热, 目标温度取命令携带值 (EEPROM 已保存值); 不切换页面。
+ * @param  cmd : 来源命令
+ * @return 无
+ */
+static void preheat_handle_start_pid(const app_preheat_cmd_t *cmd)
+{
+    s_target = cmd->target;
+    printf("[Preheat] start PID directly target=%d src=%d\r\n",
+           (int)s_target, (int)cmd->src);
+    App_pidControl_Start((uint8_t)s_target);
+    s_state = PREHEAT_STATE_IDLE;
+}
+
 /**
  * @brief  控制周期步进
  * @note   写满功率加热 + 分项风扇 + 立即 SET_ALL; 检测预加热 4 路
@@ -221,6 +253,14 @@ void Task_Preheat(void *argument)
             {
                 preheat_handle_start(&cmd);
             }
+            else if (cmd.type == APP_PREHEAT_CMD_START_PID)
+            {
+                preheat_handle_start_pid(&cmd);
+            }
+            else if (cmd.type == APP_PREHEAT_CMD_SKIP)
+            {
+                preheat_handle_skip(&cmd);
+            }
             else
             {
                 preheat_handle_stop(&cmd);
@@ -233,6 +273,14 @@ void Task_Preheat(void *argument)
             {
                 preheat_handle_start(&cmd);
             }
+            else if (cmd.type == APP_PREHEAT_CMD_START_PID)
+            {
+                preheat_handle_start_pid(&cmd);
+            }
+            else if (cmd.type == APP_PREHEAT_CMD_SKIP)
+            {
+                preheat_handle_skip(&cmd);
+            }
             else
             {
                 preheat_handle_stop(&cmd);

+ 74 - 0
LVGL8v3/ui/Ui.c

@@ -15,12 +15,17 @@
 #include "Ui_status.h"
 #include "Ui_temp_setting.h"
 #include "Ui_preheat.h"
+#include "App_cpld.h"
+#include "App_pidControl.h"
 
 /*----------------------------- 布局尺寸 ------------------------------*/
 #define UI_STATUS_BAR_H     40          /* 顶部状态栏高度 */
 #define UI_MENU_W           160         /* 左侧菜单栏宽度 */
 #define UI_CONTENT_X        (UI_MENU_W + 10)   /* 内容区起点 X */
 
+/* 顶栏徽章刷新周期 (ms) */
+#define UI_STATUSBAR_REFRESH_MS  500
+
 /*----------------------------- 状态栏 ------------------------------*/
 typedef enum
 {
@@ -38,6 +43,9 @@ typedef enum
 static lv_obj_t * s_status_dot   = NULL;   /* 状态指示灯 (圆点) */
 static lv_obj_t * s_status_label = NULL;   /* 状态文字 ("Ready"/"Not Ready") */
 static lv_obj_t * s_status_badge = NULL;   /* 就绪徽章 (圆角底) */
+static lv_obj_t * s_tc_dot       = NULL;   /* TC 指示灯 (圆点) */
+static lv_obj_t * s_tc_label     = NULL;   /* TC 文字 */
+static lv_obj_t * s_tc_badge     = NULL;   /* TC 徽章 (圆角底) */
 static lv_obj_t * s_status_bar   = NULL;   /* 顶部状态栏容器 */
 static lv_obj_t * s_menu         = NULL;   /* 左侧菜单栏容器 */
 static lv_obj_t * s_content      = NULL;   /* 右侧内容区容器 */
@@ -115,6 +123,36 @@ static void ui_build_status_bar(lv_obj_t * scr)
     lv_label_set_text(s_status_label, "Not Ready");
     lv_obj_set_style_text_font(s_status_label, &lv_font_montserrat_16, LV_STATE_DEFAULT);
     lv_obj_align(s_status_label, LV_ALIGN_RIGHT_MID, -12, 0);
+
+    /* TC 徽章 (PID 控温状态), 位于就绪徽章左侧 */
+    s_tc_badge = lv_obj_create(bar);
+    lv_obj_set_size(s_tc_badge, 100, 30);
+    lv_obj_align(s_tc_badge, LV_ALIGN_RIGHT_MID, -178, 0);
+    lv_obj_set_style_radius(s_tc_badge, LV_RADIUS_CIRCLE, LV_STATE_DEFAULT);
+    lv_obj_set_style_bg_opa(s_tc_badge, LV_OPA_COVER, LV_STATE_DEFAULT);
+    lv_obj_set_style_border_width(s_tc_badge, 1, LV_STATE_DEFAULT);
+    lv_obj_set_style_shadow_width(s_tc_badge, 0, LV_STATE_DEFAULT);
+    lv_obj_set_style_shadow_opa(s_tc_badge, LV_OPA_TRANSP, LV_STATE_DEFAULT);
+    lv_obj_set_style_outline_width(s_tc_badge, 0, LV_STATE_DEFAULT);
+    lv_obj_set_style_pad_all(s_tc_badge, 0, LV_STATE_DEFAULT);
+    ui_fix_scroll(s_tc_badge);
+
+    s_tc_dot = lv_obj_create(s_tc_badge);
+    lv_obj_set_size(s_tc_dot, 14, 14);
+    lv_obj_align(s_tc_dot, LV_ALIGN_LEFT_MID, 12, 0);
+    lv_obj_set_style_radius(s_tc_dot, LV_RADIUS_CIRCLE, LV_STATE_DEFAULT);
+    lv_obj_set_style_bg_opa(s_tc_dot, LV_OPA_COVER, LV_STATE_DEFAULT);
+    lv_obj_set_style_border_opa(s_tc_dot, LV_OPA_TRANSP, LV_STATE_DEFAULT);
+    lv_obj_set_style_shadow_width(s_tc_dot, 0, LV_STATE_DEFAULT);
+    lv_obj_set_style_shadow_opa(s_tc_dot, LV_OPA_TRANSP, LV_STATE_DEFAULT);
+    lv_obj_set_style_outline_width(s_tc_dot, 0, LV_STATE_DEFAULT);
+    lv_obj_set_style_pad_all(s_tc_dot, 0, LV_STATE_DEFAULT);
+    ui_fix_scroll(s_tc_dot);
+
+    s_tc_label = lv_label_create(s_tc_badge);
+    lv_label_set_text(s_tc_label, "TC");
+    lv_obj_set_style_text_font(s_tc_label, &lv_font_montserrat_16, LV_STATE_DEFAULT);
+    lv_obj_align(s_tc_label, LV_ALIGN_RIGHT_MID, -12, 0);
 }
 
 static void ui_refresh_ready(void)
@@ -142,6 +180,38 @@ static void ui_refresh_ready(void)
     }
 }
 
+/* 刷新 TC 徽章: PID 闭环运行中显示绿色, 否则红色 */
+static void ui_refresh_tc(void)
+{
+    if (s_tc_dot == NULL || s_tc_label == NULL || s_tc_badge == NULL)
+    {
+        return;
+    }
+
+    if (App_pidControl_is_running())
+    {
+        lv_obj_set_style_bg_color(s_tc_badge, UI_BADGE_OK_BG, LV_STATE_DEFAULT);
+        lv_obj_set_style_border_color(s_tc_badge, UI_BADGE_OK_BORDER, LV_STATE_DEFAULT);
+        lv_obj_set_style_bg_color(s_tc_dot,   UI_CLR_OK, LV_STATE_DEFAULT);
+        lv_obj_set_style_text_color(s_tc_label, UI_CLR_OK, LV_STATE_DEFAULT);
+    }
+    else
+    {
+        lv_obj_set_style_bg_color(s_tc_badge, UI_BADGE_ERR_BG, LV_STATE_DEFAULT);
+        lv_obj_set_style_border_color(s_tc_badge, UI_BADGE_ERR_BORDER, LV_STATE_DEFAULT);
+        lv_obj_set_style_bg_color(s_tc_dot,   UI_CLR_ERR, LV_STATE_DEFAULT);
+        lv_obj_set_style_text_color(s_tc_label, UI_CLR_ERR, LV_STATE_DEFAULT);
+    }
+}
+
+/* 顶栏徽章周期刷新: Ready 跟随 CPLD 通讯, TC 跟随 PID 状态 */
+static void ui_statusbar_timer_cb(lv_timer_t * t)
+{
+    (void)t;
+    Ui_set_ready(App_cpld_comm_alive() != 0);
+    ui_refresh_tc();
+}
+
 static void ui_menu_refresh_active(void)
 {
     uint32_t i;
@@ -282,6 +352,10 @@ void Ui_init(void)
     Ui_temperature_create(s_page);             /* 默认显示实时温度页 */
     ui_refresh_ready();
 
+    /* 顶栏徽章周期刷新 (500ms): Ready 随 Comm, TC 随 PID 状态 */
+    lv_timer_t * bar_timer = lv_timer_create(ui_statusbar_timer_cb, UI_STATUSBAR_REFRESH_MS, NULL);
+    lv_timer_set_repeat_count(bar_timer, -1);
+
     /* 立即重绘一次, 避免首帧位置不正 */
     lv_obj_update_layout(scr);
     lv_refr_now(NULL);

+ 39 - 0
LVGL8v3/ui/Ui_preheat.c

@@ -42,6 +42,10 @@
 #define UI_PRE_CANCEL_W        200
 #define UI_PRE_CANCEL_H        48
 
+/* 右侧面板底部 skip 按钮 (跳过预热, 直接 PID 控温) */
+#define UI_PRE_SKIP_W          140
+#define UI_PRE_SKIP_H          48
+
 /* 顶部目标值 chip */
 #define UI_PRE_TARGET_W        180
 #define UI_PRE_TARGET_H        34
@@ -127,6 +131,29 @@ static void ui_preheat_cancel_cb(lv_event_t * e)
     Ui_build_page((uint8_t)UI_MENU_TEMP_SETTING);
 }
 
+/* skip 按钮: 跳过预热, 直接进入 PID 控温
+ * 页面不在此关闭, 由 preheatTask 经 Ui_preheat_done_exit 异步关闭返回实时页 */
+static void ui_preheat_skip_cb(lv_event_t * e)
+{
+    lv_obj_t * btn = lv_event_get_target(e);
+    lv_indev_t * indev = lv_indev_get_act();
+    if (indev != NULL)
+    {
+        lv_point_t pt;
+        lv_indev_get_point(indev, &pt);
+        if (!lv_obj_hit_test(btn, &pt))
+        {
+            return;                    /* 手指已移出按钮范围, 不触发 */
+        }
+    }
+
+    app_preheat_cmd_t cmd;
+    cmd.type   = APP_PREHEAT_CMD_SKIP;
+    cmd.src    = APP_PREHEAT_SRC_UI;
+    cmd.target = (int16_t)Com_parameter_get_target();
+    App_preheat_send_cmd(&cmd);
+}
+
 /* 构建一张温度卡片 (CPU0/CPU1, 各含 2 行温度) */
 static void ui_preheat_build_card(lv_obj_t * root, const char * cpu_name,
                                   uint8_t start_idx, lv_coord_t y)
@@ -291,6 +318,18 @@ void Ui_preheat_enter(void)
     lv_obj_set_style_arc_color(spin, UI_CLR_ACCENT, LV_PART_INDICATOR | LV_STATE_DEFAULT);
     lv_obj_align(spin, LV_ALIGN_CENTER, 0, 0);
 
+    /* Skip 按钮: 跳过预热, 直接进入 PID 控温 */
+    lv_obj_t * skip = lv_btn_create(panel);
+    lv_obj_set_size(skip, UI_PRE_SKIP_W, UI_PRE_SKIP_H);
+    lv_obj_align(skip, LV_ALIGN_BOTTOM_MID, 0, -16);
+    Ui_theme_style_btn_accent(skip);
+    lv_obj_add_event_cb(skip, ui_preheat_skip_cb, LV_EVENT_RELEASED, NULL);
+    lv_obj_t * sl = lv_label_create(skip);
+    lv_label_set_text(sl, "Skip");
+    lv_obj_set_style_text_font(sl, &lv_font_montserrat_20, LV_STATE_DEFAULT);
+    lv_obj_set_style_text_color(sl, UI_CLR_ACCENT_DARK, LV_STATE_DEFAULT);
+    lv_obj_center(sl);
+
     ui_preheat_refresh();
 
     /* 启动实时刷新定时器 */

+ 93 - 18
LVGL8v3/ui/Ui_status.c

@@ -2,12 +2,21 @@
   ******************************************************************************
   * @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 "Logic_temperature.h"
+#include "App_cpld.h"
+#include "App_pidControl.h"
 
 /* 状态卡片位置 */
 #define UI_STATUS_PANEL_X       10
@@ -15,6 +24,10 @@
 #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
@@ -23,8 +36,18 @@
 #define UI_STATUS_LINE_X        16      /* 分隔线 */
 #define UI_STATUS_LINE_W        (UI_STATUS_PANEL_W - 32)
 
-static void ui_status_add_item(lv_obj_t * parent, const char * key, const char * value,
-                               lv_coord_t y, lv_color_t value_color)
+/* 实时刷新周期 (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);
@@ -37,6 +60,48 @@ static void ui_status_add_item(lv_obj_t * parent, const char * key, const char *
     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)
@@ -44,29 +109,39 @@ void Ui_status_create(lv_obj_t * parent)
     Ui_theme_add_title(parent, "Device Status", 10);
 
     /* 状态信息卡片 */
-    lv_obj_t * panel = lv_obj_create(parent);
-    lv_obj_set_pos(panel, UI_STATUS_PANEL_X, UI_STATUS_PANEL_Y);
-    lv_obj_set_size(panel, UI_STATUS_PANEL_W, UI_STATUS_PANEL_H);
-    Ui_theme_style_panel(panel);
-
-    /* 状态信息 (假数据) */
-    lv_color_t ok_color = UI_CLR_OK;
-    lv_color_t gray     = UI_CLR_TEXT;
+    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);
 
-    ui_status_add_item(panel, "Status:", "Running", UI_STATUS_ROW_Y0 + 0 * UI_STATUS_ROW_GAP, gray);
-    ui_status_add_item(panel, "Power:",  "OK",      UI_STATUS_ROW_Y0 + 1 * UI_STATUS_ROW_GAP, ok_color);
-    ui_status_add_item(panel, "Comm:",   "OK",      UI_STATUS_ROW_Y0 + 2 * UI_STATUS_ROW_GAP, ok_color);
-    ui_status_add_item(panel, "Ready:",  "Ready",   UI_STATUS_ROW_Y0 + 3 * UI_STATUS_ROW_GAP, ok_color);
+    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 < 3; i++)
+    for (i = 0; i < 2; i++)
     {
-        lv_obj_t * line = lv_obj_create(panel);
+        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);
 }

+ 121 - 13
LVGL8v3/ui/Ui_temp_setting.c

@@ -54,13 +54,15 @@
 #define UI_TSET_VAL_H       56      /* 高度与加减号按钮一致 */
 #define UI_TSET_BTN_PLUS_X  355
 
-/* 底部按钮行 (水平居中) */
-#define UI_TSET_APPLY_X     132
-#define UI_TSET_APPLY_Y     240
-#define UI_TSET_APPLY_W     140
-#define UI_TSET_PREHEAT_X   288
-#define UI_TSET_PREHEAT_W   210
-#define UI_TSET_BTN_H       44
+/* 底部按钮区: 四个按钮同一大小 270x48, 2x2 网格, 整体水平居中于 315
+ * 网格总宽 = 270*2 + 20(列间距) = 560, 起始 x=35; 上下行间距 16 (y: 240 / 304)
+ * 左列 x=35: Apply / Start Temp Control    右列 x=325: Start preheating / Stop Temp Control */
+#define UI_TSET_BTN_W       270
+#define UI_TSET_BTN_H       48
+#define UI_TSET_BTN_X0      35      /* 左列 */
+#define UI_TSET_BTN_X1      325     /* 右列 */
+#define UI_TSET_ROW1_Y      240
+#define UI_TSET_ROW2_Y      304
 
 /* 弹窗宽度 (预热确认框与保存成功弹窗同尺寸, 适配 4.3 寸 800x480) */
 #define UI_TSET_MBOX_W      420
@@ -73,7 +75,7 @@
 static int16_t    s_target = 60;    /* 目标温度 (打开页面时从 EEPROM 加载) */
 static lv_obj_t * s_ta     = NULL;  /* 目标温度数值输入框 */
 static lv_obj_t * s_kb     = NULL;  /* 数字键盘 (弹出时有效) */
-static lv_obj_t * s_msgbox = NULL;  /* 预热确认弹窗 (弹出时有效) */
+static lv_obj_t * s_msgbox = NULL;  /* 确认弹窗 (预热/Start/Stop 共用, 同一时刻至多一个) */
 static lv_obj_t * s_saved  = NULL;  /* 保存成功弹窗 (弹出时有效) */
 static lv_timer_t * s_repeat_timer = NULL;  /* 长按重复定时器 */
 static uint8_t    s_active = 0xFF;  /* 当前激活按键: 0xFF=无, 0=递减, 1=递增 */
@@ -316,6 +318,85 @@ static void ui_tset_msgbox_cb(lv_event_t * e)
     s_msgbox = NULL;
 }
 
+/* 静态缓冲: 弹窗文本需保持有效直到弹窗关闭 (lv_msgbox 内部按静态文本使用) */
+static char s_ctl_start_txt[64];
+
+/* Start Temp Control 确认回调: Yes 直接启动 PID 控温 */
+static void ui_tset_startpid_confirm_cb(lv_event_t * e)
+{
+    lv_obj_t * mbox = lv_event_get_current_target(e);
+    if (lv_msgbox_get_active_btn(mbox) == 0)
+    {
+        app_preheat_cmd_t cmd;
+        cmd.type   = APP_PREHEAT_CMD_START_PID;
+        cmd.src    = APP_PREHEAT_SRC_UI;
+        cmd.target = (int16_t)Com_parameter_get_target();
+        App_preheat_send_cmd(&cmd);
+
+        lv_msgbox_close(mbox);
+        s_msgbox = NULL;
+        return;
+    }
+    lv_msgbox_close(mbox);
+    s_msgbox = NULL;
+}
+
+/* Start Temp Control 按钮: 弹出确认框 (目标温度 = Apply 保存值) */
+static void ui_tset_start_ctrl_cb(lv_event_t * e)
+{
+    (void)e;
+    if (s_msgbox != NULL)
+    {
+        return;
+    }
+    static const char * btns[] = { "Yes", "No", "" };
+    snprintf(s_ctl_start_txt, sizeof(s_ctl_start_txt),
+             "Start temperature control with target %d\xC2\xB0"
+             "C?", (int)Com_parameter_get_target());
+    s_msgbox = lv_msgbox_create(NULL, "Start Temp Control", s_ctl_start_txt, btns, false);
+    ui_tset_style_msgbox(s_msgbox);
+
+    lv_obj_add_event_cb(s_msgbox, ui_tset_startpid_confirm_cb, LV_EVENT_VALUE_CHANGED, NULL);
+    ui_tset_center_msgbox(s_msgbox);
+}
+
+/* Stop Temp Control 确认回调: Yes 停止 PID 控温 */
+static void ui_tset_stoppid_confirm_cb(lv_event_t * e)
+{
+    lv_obj_t * mbox = lv_event_get_current_target(e);
+    if (lv_msgbox_get_active_btn(mbox) == 0)
+    {
+        app_preheat_cmd_t cmd;
+        cmd.type   = APP_PREHEAT_CMD_STOP;
+        cmd.src    = APP_PREHEAT_SRC_UI;
+        cmd.target = 0;
+        App_preheat_send_cmd(&cmd);
+
+        lv_msgbox_close(mbox);
+        s_msgbox = NULL;
+        return;
+    }
+    lv_msgbox_close(mbox);
+    s_msgbox = NULL;
+}
+
+/* Stop Temp Control 按钮: 弹出确认框 */
+static void ui_tset_stop_ctrl_cb(lv_event_t * e)
+{
+    (void)e;
+    if (s_msgbox != NULL)
+    {
+        return;
+    }
+    static const char * btns[] = { "Yes", "No", "" };
+    s_msgbox = lv_msgbox_create(NULL, "Stop Temp Control",
+                                "Stop temperature control?", btns, false);
+    ui_tset_style_msgbox(s_msgbox);
+
+    lv_obj_add_event_cb(s_msgbox, ui_tset_stoppid_confirm_cb, LV_EVENT_VALUE_CHANGED, NULL);
+    ui_tset_center_msgbox(s_msgbox);
+}
+
 /* Start preheating 按钮: 弹出确认框 (与保存成功弹窗同尺寸同风格) */
 static void ui_tset_preheat_cb(lv_event_t * e)
 {
@@ -519,10 +600,12 @@ void Ui_temp_setting_create(lv_obj_t * parent)
     /* 递增按钮 "+" (长按自动加) */
     ui_tset_add_step_btn(card, LV_SYMBOL_PLUS, UI_TSET_BTN_PLUS_X, ui_tset_plus_cb);
 
-    /* 底部按钮行 (居中): Apply + Start preheating */
+    /* 底部按钮区: 四个按钮同一大小, 2x2 网格 (居中) */
+
+    /* 左上: Apply —— 校验并保存目标温度到 EEPROM, 按结果弹成功/失败提示 */
     lv_obj_t * apply = lv_btn_create(parent);
-    lv_obj_set_size(apply, UI_TSET_APPLY_W, UI_TSET_BTN_H);
-    lv_obj_set_pos(apply, UI_TSET_APPLY_X, UI_TSET_APPLY_Y);
+    lv_obj_set_size(apply, UI_TSET_BTN_W, UI_TSET_BTN_H);
+    lv_obj_set_pos(apply, UI_TSET_BTN_X0, UI_TSET_ROW1_Y);
     lv_obj_add_event_cb(apply, ui_tset_apply_cb, LV_EVENT_CLICKED, NULL);
     Ui_theme_style_btn_accent(apply);
     lv_obj_t * al = lv_label_create(apply);
@@ -531,9 +614,10 @@ void Ui_temp_setting_create(lv_obj_t * parent)
     lv_obj_set_style_text_color(al, UI_CLR_ACCENT_DARK, LV_STATE_DEFAULT);
     lv_obj_center(al);
 
+    /* 右上: Start preheating —— 确认后进入预加热流程 */
     lv_obj_t * ph = lv_btn_create(parent);
-    lv_obj_set_size(ph, UI_TSET_PREHEAT_W, UI_TSET_BTN_H);
-    lv_obj_set_pos(ph, UI_TSET_PREHEAT_X, UI_TSET_APPLY_Y);
+    lv_obj_set_size(ph, UI_TSET_BTN_W, UI_TSET_BTN_H);
+    lv_obj_set_pos(ph, UI_TSET_BTN_X1, UI_TSET_ROW1_Y);
     lv_obj_add_event_cb(ph, ui_tset_preheat_cb, LV_EVENT_CLICKED, NULL);
     Ui_theme_style_btn_accent(ph);
     lv_obj_t * pl = lv_label_create(ph);
@@ -542,6 +626,30 @@ void Ui_temp_setting_create(lv_obj_t * parent)
     lv_obj_set_style_text_color(pl, UI_CLR_ACCENT_DARK, LV_STATE_DEFAULT);
     lv_obj_center(pl);
 
+    /* 左下: Start Temp Control —— 确认后以已保存温度直接启动 PID 控温 */
+    lv_obj_t * starttc = lv_btn_create(parent);
+    lv_obj_set_size(starttc, UI_TSET_BTN_W, UI_TSET_BTN_H);
+    lv_obj_set_pos(starttc, UI_TSET_BTN_X0, UI_TSET_ROW2_Y);
+    lv_obj_add_event_cb(starttc, ui_tset_start_ctrl_cb, LV_EVENT_CLICKED, NULL);
+    Ui_theme_style_btn_accent(starttc);
+    lv_obj_t * spl = lv_label_create(starttc);
+    lv_label_set_text(spl, "Start Temp Control");
+    lv_obj_set_style_text_font(spl, &lv_font_montserrat_16, LV_STATE_DEFAULT);
+    lv_obj_set_style_text_color(spl, UI_CLR_ACCENT_DARK, LV_STATE_DEFAULT);
+    lv_obj_center(spl);
+
+    /* 右下: Stop Temp Control —— 确认后停止 PID 控温; 红色 danger 区分停止操作 */
+    lv_obj_t * stoptc = lv_btn_create(parent);
+    lv_obj_set_size(stoptc, UI_TSET_BTN_W, UI_TSET_BTN_H);
+    lv_obj_set_pos(stoptc, UI_TSET_BTN_X1, UI_TSET_ROW2_Y);
+    lv_obj_add_event_cb(stoptc, ui_tset_stop_ctrl_cb, LV_EVENT_CLICKED, NULL);
+    Ui_theme_style_btn_danger(stoptc);
+    lv_obj_t * stl = lv_label_create(stoptc);
+    lv_label_set_text(stl, "Stop Temp Control");
+    lv_obj_set_style_text_font(stl, &lv_font_montserrat_16, LV_STATE_DEFAULT);
+    lv_obj_set_style_text_color(stl, UI_CLR_ERR, LV_STATE_DEFAULT);
+    lv_obj_center(stl);
+
     ui_tset_refresh();
 }
 

+ 8 - 0
MDK-ARM/build.log

@@ -0,0 +1,8 @@
+*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\Program Files\Keil\Keil_5\ARM\keil_506\Bin'
+Build target 'STMH7_temperature_control_board'
+compiling Ui_temp_setting.c...
+linking...
+Program Size: Code=284738 RO-data=85658 RW-data=6368 ZI-data=279360  
+FromELF: creating hex file...
+"STMH7_temperature_control_board\STMH7_temperature_control_board.axf" - 0 Error(s), 0 Warning(s).
+Build Time Elapsed:  00:00:09