|
|
@@ -0,0 +1,265 @@
|
|
|
+/**
|
|
|
+ ******************************************************************************
|
|
|
+ * @file Ui_preheat.c
|
|
|
+ * @brief 预加热全屏页面 (UI 页面层)
|
|
|
+ *
|
|
|
+ * @note 点击"开始预热"确认框的 Yes 后进入: 全屏不透明覆盖, 隐藏状态栏/
|
|
|
+ * 菜单/内容区; 左 3/4 为 CPU0 / CPU1 两张温度卡片 (各 2 路),
|
|
|
+ * 右 1/4 为加热动画 + 已加热时长; 底部红色 cancel 返回温度设置页。
|
|
|
+ ******************************************************************************
|
|
|
+ */
|
|
|
+#include <stdio.h>
|
|
|
+#include "Ui.h"
|
|
|
+#include "Ui_preheat.h"
|
|
|
+#include "Ui_temp_setting.h"
|
|
|
+#include "Ui_theme.h"
|
|
|
+#include "Logic_temperature.h"
|
|
|
+
|
|
|
+/*-------------------------------- 布局 ---------------------------------*/
|
|
|
+#define UI_PRE_W (LV_HOR_RES) /* 全屏宽 */
|
|
|
+#define UI_PRE_H (LV_VER_RES) /* 全屏高 */
|
|
|
+#define UI_PRE_TEMPS_W (LV_HOR_RES * 3 / 4) /* 左 3/4 */
|
|
|
+
|
|
|
+/* 温度卡片 (上下两张: CPU0 / CPU1) */
|
|
|
+#define UI_PRE_CARD_X 16
|
|
|
+#define UI_PRE_CARD_Y0 56
|
|
|
+#define UI_PRE_CARD_GAP 12
|
|
|
+#define UI_PRE_CARD_W (UI_PRE_TEMPS_W - 32)
|
|
|
+#define UI_PRE_CARD_H 150
|
|
|
+
|
|
|
+/* 卡片内行布局 */
|
|
|
+#define UI_PRE_ROW_Y0 46
|
|
|
+#define UI_PRE_ROW_GAP 52
|
|
|
+#define UI_PRE_ROW_LINE_Y (UI_PRE_ROW_Y0 + UI_PRE_ROW_GAP - 18) /* 行间分隔线 */
|
|
|
+
|
|
|
+/* 右 1/4 加热动画面板 (与卡片同高) */
|
|
|
+#define UI_PRE_ANIM_X (UI_PRE_TEMPS_W + 16)
|
|
|
+#define UI_PRE_ANIM_W (LV_HOR_RES - UI_PRE_ANIM_X - 16)
|
|
|
+#define UI_PRE_ANIM_H (UI_PRE_CARD_H * 2 + UI_PRE_CARD_GAP)
|
|
|
+
|
|
|
+/* 底部 cancel 按钮 */
|
|
|
+#define UI_PRE_CANCEL_W 200
|
|
|
+#define UI_PRE_CANCEL_H 48
|
|
|
+
|
|
|
+/* 顶部目标值 chip */
|
|
|
+#define UI_PRE_TARGET_W 180
|
|
|
+#define UI_PRE_TARGET_H 34
|
|
|
+
|
|
|
+/* 实时刷新周期 (ms) */
|
|
|
+#define UI_PRE_REFRESH_MS 500
|
|
|
+
|
|
|
+/*-------------------------------- 句柄 ---------------------------------*/
|
|
|
+static lv_obj_t * s_pre_root = NULL; /* 全屏页面根 */
|
|
|
+static lv_timer_t * s_pre_timer = NULL; /* 刷新定时器 */
|
|
|
+static lv_obj_t * s_pre_value[LOGIC_PREHEAT_TEMP_NUM];/* 4 路温度值 */
|
|
|
+static char s_pre_buf[LOGIC_PREHEAT_TEMP_NUM][12];
|
|
|
+
|
|
|
+/*----------------------------- 静态函数 ------------------------------*/
|
|
|
+
|
|
|
+/* 刷新 4 路温度数值 */
|
|
|
+static void ui_preheat_refresh(void)
|
|
|
+{
|
|
|
+ uint8_t i;
|
|
|
+ for (i = 0; i < LOGIC_PREHEAT_TEMP_NUM; i++)
|
|
|
+ {
|
|
|
+ int8_t t = Logic_preheat_get(i);
|
|
|
+ snprintf(s_pre_buf[i], sizeof(s_pre_buf[i]), "%d\xC2\xB0"
|
|
|
+ "C", (int)t);
|
|
|
+ lv_label_set_text_static(s_pre_value[i], s_pre_buf[i]);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/* 刷新定时器回调 */
|
|
|
+static void ui_preheat_timer_cb(lv_timer_t * t)
|
|
|
+{
|
|
|
+ (void)t;
|
|
|
+ ui_preheat_refresh();
|
|
|
+}
|
|
|
+
|
|
|
+/* 页面销毁: 释放定时器, 防止悬挂指针 */
|
|
|
+static void ui_preheat_delete_cb(lv_event_t * e)
|
|
|
+{
|
|
|
+ (void)e;
|
|
|
+ if (s_pre_timer != NULL)
|
|
|
+ {
|
|
|
+ lv_timer_del(s_pre_timer);
|
|
|
+ s_pre_timer = NULL;
|
|
|
+ }
|
|
|
+ s_pre_root = NULL;
|
|
|
+}
|
|
|
+
|
|
|
+/* cancel 按钮: 必须在按钮范围内抬手才退出 (手指移出后抬起不生效) */
|
|
|
+static void ui_preheat_cancel_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; /* 手指已移出按钮范围, 不触发 */
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (s_pre_root != NULL)
|
|
|
+ {
|
|
|
+ lv_obj_del(s_pre_root);
|
|
|
+ s_pre_root = NULL;
|
|
|
+ }
|
|
|
+ Ui_frame_set_visible(true);
|
|
|
+ Ui_build_page((uint8_t)UI_MENU_TEMP_SETTING);
|
|
|
+}
|
|
|
+
|
|
|
+/* 构建一张温度卡片 (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)
|
|
|
+{
|
|
|
+ lv_obj_t * card = lv_obj_create(root);
|
|
|
+ lv_obj_set_pos(card, UI_PRE_CARD_X, y);
|
|
|
+ lv_obj_set_size(card, UI_PRE_CARD_W, UI_PRE_CARD_H);
|
|
|
+ Ui_theme_style_panel(card);
|
|
|
+
|
|
|
+ /* 卡片头: 强调色竖条 + CPU 名称 */
|
|
|
+ lv_obj_t * tick = lv_obj_create(card);
|
|
|
+ lv_obj_set_size(tick, 4, 22);
|
|
|
+ lv_obj_set_pos(tick, 14, 12);
|
|
|
+ Ui_theme_clear_visuals(tick);
|
|
|
+ lv_obj_set_style_radius(tick, 2, LV_STATE_DEFAULT);
|
|
|
+ lv_obj_set_style_bg_color(tick, UI_CLR_ACCENT, LV_STATE_DEFAULT);
|
|
|
+ lv_obj_set_style_bg_opa(tick, LV_OPA_COVER, LV_STATE_DEFAULT);
|
|
|
+
|
|
|
+ lv_obj_t * name = lv_label_create(card);
|
|
|
+ lv_label_set_text(name, cpu_name);
|
|
|
+ lv_obj_set_pos(name, 28, 10);
|
|
|
+ lv_obj_set_style_text_font(name, &lv_font_montserrat_20, LV_STATE_DEFAULT);
|
|
|
+ lv_obj_set_style_text_color(name, UI_CLR_TEXT, LV_STATE_DEFAULT);
|
|
|
+
|
|
|
+ /* 2 行温度 */
|
|
|
+ uint8_t r;
|
|
|
+ for (r = 0; r < 2; r++)
|
|
|
+ {
|
|
|
+ uint8_t idx = (uint8_t)(start_idx + r);
|
|
|
+ lv_coord_t ry = UI_PRE_ROW_Y0 + r * UI_PRE_ROW_GAP;
|
|
|
+
|
|
|
+ /* 行标签圆点 + "CHx" */
|
|
|
+ lv_obj_t * dot = lv_obj_create(card);
|
|
|
+ lv_obj_set_size(dot, 14, 14);
|
|
|
+ lv_obj_set_pos(dot, 14, ry + 7);
|
|
|
+ Ui_theme_clear_visuals(dot);
|
|
|
+ lv_obj_set_style_radius(dot, LV_RADIUS_CIRCLE, LV_STATE_DEFAULT);
|
|
|
+ lv_obj_set_style_bg_color(dot, UI_CLR_ACCENT, LV_STATE_DEFAULT);
|
|
|
+ lv_obj_set_style_bg_opa(dot, LV_OPA_COVER, LV_STATE_DEFAULT);
|
|
|
+
|
|
|
+ lv_obj_t * tag = lv_label_create(card);
|
|
|
+ char tag_txt[8];
|
|
|
+ snprintf(tag_txt, sizeof(tag_txt), "CH%d", (int)(r + 1));
|
|
|
+ lv_label_set_text(tag, tag_txt);
|
|
|
+ lv_obj_set_pos(tag, 38, ry);
|
|
|
+ lv_obj_set_style_text_font(tag, &lv_font_montserrat_16, LV_STATE_DEFAULT);
|
|
|
+ lv_obj_set_style_text_color(tag, UI_CLR_TEXT_DIM, LV_STATE_DEFAULT);
|
|
|
+
|
|
|
+ /* 温度值 (右对齐, 含单位) */
|
|
|
+ lv_obj_t * v = lv_label_create(card);
|
|
|
+ lv_obj_set_style_text_font(v, &lv_font_montserrat_24, LV_STATE_DEFAULT);
|
|
|
+ lv_obj_set_style_text_color(v, UI_CLR_ACCENT, LV_STATE_DEFAULT);
|
|
|
+ lv_obj_align(v, LV_ALIGN_TOP_RIGHT, -16, ry);
|
|
|
+ s_pre_value[idx] = v;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 行间分隔线 */
|
|
|
+ lv_obj_t * line = lv_obj_create(card);
|
|
|
+ lv_obj_set_pos(line, 16, UI_PRE_ROW_LINE_Y);
|
|
|
+ lv_obj_set_size(line, UI_PRE_CARD_W - 32, 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);
|
|
|
+}
|
|
|
+
|
|
|
+/*----------------------------- 全局函数 ------------------------------*/
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief 进入预加热页面 (全屏不透明覆盖主界面)
|
|
|
+ */
|
|
|
+void Ui_preheat_enter(void)
|
|
|
+{
|
|
|
+ if (s_pre_root != NULL)
|
|
|
+ {
|
|
|
+ return; /* 已存在, 防重复进入 */
|
|
|
+ }
|
|
|
+
|
|
|
+ lv_obj_t * root = lv_obj_create(lv_scr_act());
|
|
|
+ lv_obj_set_size(root, UI_PRE_W, UI_PRE_H);
|
|
|
+ lv_obj_set_pos(root, 0, 0);
|
|
|
+ Ui_theme_clear_visuals(root);
|
|
|
+ lv_obj_set_style_bg_color(root, UI_CLR_BG, LV_STATE_DEFAULT);
|
|
|
+ lv_obj_set_style_bg_opa(root, LV_OPA_COVER, LV_STATE_DEFAULT);
|
|
|
+ lv_obj_add_event_cb(root, ui_preheat_delete_cb, LV_EVENT_DELETE, NULL);
|
|
|
+ s_pre_root = root;
|
|
|
+
|
|
|
+ /* 隐藏主框架: 预加热打开期间仅预加热参与渲染 */
|
|
|
+ Ui_frame_set_visible(false);
|
|
|
+
|
|
|
+ /* 左上标题 */
|
|
|
+ Ui_theme_add_title(root, "Preheating", 10);
|
|
|
+
|
|
|
+ /* 右上: 目标温度 chip */
|
|
|
+ int16_t target = Ui_temp_setting_get_target();
|
|
|
+ lv_obj_t * target_chip = lv_obj_create(root);
|
|
|
+ lv_obj_set_size(target_chip, UI_PRE_TARGET_W, UI_PRE_TARGET_H);
|
|
|
+ lv_obj_align(target_chip, LV_ALIGN_TOP_RIGHT, -16, 10);
|
|
|
+ Ui_theme_style_chip(target_chip);
|
|
|
+ lv_obj_t * target_key = lv_label_create(target_chip);
|
|
|
+ lv_label_set_text(target_key, "Target");
|
|
|
+ lv_obj_set_style_text_font(target_key, &lv_font_montserrat_16, LV_STATE_DEFAULT);
|
|
|
+ lv_obj_set_style_text_color(target_key, UI_CLR_TEXT_DIM, LV_STATE_DEFAULT);
|
|
|
+ lv_obj_align(target_key, LV_ALIGN_LEFT_MID, 14, 0);
|
|
|
+ lv_obj_t * target_val = lv_label_create(target_chip);
|
|
|
+ lv_label_set_text_fmt(target_val, "%d\xC2\xB0"
|
|
|
+ "C", (int)target);
|
|
|
+ lv_obj_set_style_text_font(target_val, &lv_font_montserrat_20, LV_STATE_DEFAULT);
|
|
|
+ lv_obj_set_style_text_color(target_val, UI_CLR_ACCENT, LV_STATE_DEFAULT);
|
|
|
+ lv_obj_align_to(target_val, target_key, LV_ALIGN_OUT_RIGHT_MID, 8, 0);
|
|
|
+
|
|
|
+ /* 左 3/4: 两张温度卡片 */
|
|
|
+ ui_preheat_build_card(root, "CPU0", 0, UI_PRE_CARD_Y0);
|
|
|
+ ui_preheat_build_card(root, "CPU1", 2, UI_PRE_CARD_Y0 + UI_PRE_CARD_H + UI_PRE_CARD_GAP);
|
|
|
+
|
|
|
+ /* 底部红色 cancel 按钮 (整屏水平居中) */
|
|
|
+ lv_obj_t * cancel = lv_btn_create(root);
|
|
|
+ lv_obj_set_size(cancel, UI_PRE_CANCEL_W, UI_PRE_CANCEL_H);
|
|
|
+ lv_obj_align(cancel, LV_ALIGN_BOTTOM_MID, 0, -16);
|
|
|
+ Ui_theme_style_btn_danger(cancel);
|
|
|
+ lv_obj_add_event_cb(cancel, ui_preheat_cancel_cb, LV_EVENT_RELEASED, NULL);
|
|
|
+ lv_obj_t * cl = lv_label_create(cancel);
|
|
|
+ lv_label_set_text(cl, "cancel");
|
|
|
+ lv_obj_set_style_text_font(cl, &lv_font_montserrat_20, LV_STATE_DEFAULT);
|
|
|
+ lv_obj_set_style_text_color(cl, UI_CLR_ERR, LV_STATE_DEFAULT);
|
|
|
+ lv_obj_center(cl);
|
|
|
+
|
|
|
+ /* 右 1/4: 加热动画面板 (标题 + spinner) */
|
|
|
+ lv_obj_t * panel = lv_obj_create(root);
|
|
|
+ lv_obj_set_pos(panel, UI_PRE_ANIM_X, UI_PRE_CARD_Y0);
|
|
|
+ lv_obj_set_size(panel, UI_PRE_ANIM_W, UI_PRE_ANIM_H);
|
|
|
+ Ui_theme_style_panel(panel);
|
|
|
+
|
|
|
+ lv_obj_t * head = lv_label_create(panel);
|
|
|
+ lv_label_set_text(head, "Heating...");
|
|
|
+ lv_obj_set_style_text_font(head, &lv_font_montserrat_20, LV_STATE_DEFAULT);
|
|
|
+ lv_obj_set_style_text_color(head, UI_CLR_TEXT, LV_STATE_DEFAULT);
|
|
|
+ lv_obj_align(head, LV_ALIGN_TOP_MID, 0, 24);
|
|
|
+
|
|
|
+ lv_obj_t * spin = lv_spinner_create(panel, 1000, 70);
|
|
|
+ lv_obj_set_size(spin, 120, 120);
|
|
|
+ lv_obj_set_style_arc_width(spin, 8, LV_PART_MAIN | LV_STATE_DEFAULT);
|
|
|
+ lv_obj_set_style_arc_color(spin, UI_CLR_PANEL_HI, LV_PART_MAIN | LV_STATE_DEFAULT);
|
|
|
+ lv_obj_set_style_arc_width(spin, 8, LV_PART_INDICATOR | LV_STATE_DEFAULT);
|
|
|
+ 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);
|
|
|
+
|
|
|
+ ui_preheat_refresh();
|
|
|
+
|
|
|
+ /* 启动实时刷新定时器 */
|
|
|
+ s_pre_timer = lv_timer_create(ui_preheat_timer_cb, UI_PRE_REFRESH_MS, NULL);
|
|
|
+ lv_timer_set_repeat_count(s_pre_timer, -1);
|
|
|
+}
|