#include #include #include #include #include #include "ui.h" #include "iconstore.h" #include "rocketstore.h" #include "display.h" #include "icons.h" #include "board_config.h" #include "ota.h" #include "clock.h" #include "nixie.h" #include /* 版面:header 那行 0..HDR_LINE / 内容区 TOP_Y..BOT_Y / 按键条。 320x240 横屏就是设计稿原尺寸:内容区占满整宽,底部一条四个按键的图例。 640x172 长条屏(带触摸)整屏横向布局:没有按钮条——上下滑翻页、卡片和分页标签直接点, 页面级动作只剩 header 右端那 1~2 颗按钮(见 header_buttons)。 header 那行的留白:长条屏 1px ≈ 0.13mm,按钮文字上下各 3px、header 与内容区之间 3px, 横屏那版的几个常量维持原值,设计稿尺寸不动。 */ #if LCD_HEIGHT < 200 #define STRIP 1 /* 长条屏 */ #else #define STRIP 0 #endif #define HDR_TY (STRIP ? 5 : 2) /* header 那行文字的 y */ #define HDR_LINE (STRIP ? 27 : 19) /* header 与内容区之间的分隔线 */ #define TOP_Y (STRIP ? 31 : 22) /* 内容区顶 */ #define CONT_W LCD_WIDTH #if STRIP #define KEY_H 0 #define BOT_Y (LCD_HEIGHT - 1) #else #define KEY_H 20 #define BOT_Y (LCD_HEIGHT - KEY_H - 8) #define KEY_Y (LCD_HEIGHT - KEY_H - 4) #endif /* 右端那一列右对齐文字(状态栏右端的用户名、详情页标题行右端的日期)共同的右边界。 长条屏的 header 按钮就画在右上角,它得先按按钮宽度往左让。 */ static int s_info_r = CONT_W - 4; #define LIST_ROWS (STRIP ? 2 : 3) /* 长条屏 2 张卡 y=31/101,h=66,铺到 167 */ #define CARD_H (STRIP ? 66 : 60) /* 列表页的留白:卡片到屏左、翻页按钮到屏右、卡片到翻页按钮,三段用同一个值, 改一处就整体一起变宽。横屏没有翻页按钮那一列,维持原来的 3。 */ #define LIST_PAD (STRIP ? 16 : 3) #define CARD_X LIST_PAD #define RAIL_BTN_W 26 /* 上/下按钮本体宽 */ #define RAIL_W (STRIP ? (RAIL_BTN_W + LIST_PAD) : 0) /* 右缘那一列含左侧的缝 */ #define CARD_W (CONT_W - 2 * LIST_PAD - RAIL_W) #define CARD_PITCH (STRIP ? 70 : 65) /* 滚动条贴屏右缘。翻页按钮的热区右界是 CONT_W-LIST_PAD+6, LIST_PAD 加宽之后这条缝容得下 2px 的滚动条,两者不重迭。 */ #define SB_X (CONT_W - 3) #define SPLASH_PAD 52 #define CARD_TY (STRIP ? 14 : 8) /* 卡内标题行 / 副行的 y 偏移 */ #define CARD_SY (STRIP ? 42 : 34) /* ---------------- 触摸热区 ---------------- 画每一页时顺手把可点的矩形登记进来(ui_draw 重绘前清空)。一次按下落在哪个矩形, 就等于按下那颗按键:bits 是 XL_IO_KEY*,index 顺带告诉调用方选中的是第几行。 */ #define UI_MAX_HITS 16 struct UiHit { int16_t x, y, w, h; uint16_t bits; int8_t index; }; static UiHit s_hits[UI_MAX_HITS]; static uint8_t s_nhits; void ui_hits_reset() { s_nhits = 0; } void ui_hit_add(int x, int y, int w, int h, uint16_t bits, int index) { if (s_nhits >= UI_MAX_HITS) return; s_hits[s_nhits].x = (int16_t)x; s_hits[s_nhits].y = (int16_t)y; s_hits[s_nhits].w = (int16_t)w; s_hits[s_nhits].h = (int16_t)h; s_hits[s_nhits].bits = bits; s_hits[s_nhits].index = (int8_t)index; s_nhits++; } /* 后登记的盖在先登记的上面,所以倒着找 */ static const UiHit *hit_find(int x, int y) { for (int i = s_nhits - 1; i >= 0; i--) { const UiHit &r = s_hits[i]; if (x >= r.x && x < r.x + r.w && y >= r.y && y < r.y + r.h) return &r; } return NULL; } uint16_t ui_hit_test(int x, int y, int *index) { const UiHit *r = hit_find(x, y); if (index) *index = r ? r->index : -1; return r ? r->bits : 0; } #if BOARD_HAS_TOUCH #define HIT(x, y, w, h, bits, idx) ui_hit_add(x, y, w, h, bits, idx) #else #define HIT(x, y, w, h, bits, idx) #endif /* 窄屏上写死的行距会撞车:文字先按行宽折行,再把光标推到最后一行下面 */ static int flow(int x, int y, int w, const char *s, uint16_t fg, uint16_t bg, int gap = 6) { if (!s || !s[0]) return y; return disp_text_wrap(x, y, w, s, 16, fg, bg, 3) + gap; } static void text_right(int x_right, int y, const char *s, uint8_t size, uint16_t fg, uint16_t bg) { disp_text(x_right - disp_text_width(s, size, 1), y, s, size, fg, bg); } /* 取前 max_chars 个字符(UTF-8 安全),截断了就在末尾补 ".." */ static void clip_chars(char *dst, size_t cap, const char *src, int max_chars) { int used = 0, n = 0, chars = 0; while (src[n] && chars < max_chars && used + 4 < (int)cap) { unsigned char c = (unsigned char)src[n]; int l = (c >= 0xF0) ? 4 : (c >= 0xE0) ? 3 : (c >= 0xC0) ? 2 : 1; for (int k = 0; k < l; k++) dst[used + k] = src[n + k]; used += l; n += l; chars++; } dst[used] = 0; if (src[n] && used + 2 < (int)cap) { dst[used++] = '.'; dst[used++] = '.'; dst[used] = 0; } } /* 一行放不下的发射任务名。disp_text_clipped 只保头,"Starlink Group 15-25" 会被打成 "Starlink Group ..",偏偏编号才是区分两行 Starlink 的唯一信息,所以这里反过来: 尾巴(末尾几个完整词)优先保住,".." 放到中间。 */ static void text_elided(int x, int y, int maxw, const char *s, uint16_t fg, uint16_t bg) { if (!s) return; if (disp_text_width(s, 16, 1) <= maxw) { disp_text(x, y, s, 16, fg, bg); return; } int room = maxw - disp_text_width("..", 16, 1); if (room < 24) { disp_text(x, y, "..", 16, fg, bg); return; } /* 头和尾之间不许留白:留白了 "..15-25" 会看起来像右边那一列日期,所以头部预算 直接吃满 room - tw,切在词中间也照切,保证 "Starlink G..15-25" 是一整串 */ int len = (int)strlen(s); const char *ws[20], *we[20]; int nw = 0; for (const char *p = s; *p && nw < 20; ) { while (*p == ' ') p++; if (!*p) break; ws[nw] = p; while (*p && *p != ' ') p++; we[nw++] = p; } /* 尾巴先按整词收,最多半个区域;连一个词都塞不下就退到按字符收尾巴(长词/中文) */ int first = -1, tw = 0; /* first = 尾巴起始词下标 */ char tail[64]; tail[0] = 0; for (int i = nw - 1; i >= 0; i--) { char w[64]; int n = (int)(we[i] - ws[i]); if (n <= 0 || n >= (int)sizeof(w)) break; memcpy(w, ws[i], n); w[n] = 0; int ww = disp_text_width(w, 16, 1); if (ww > room / 2) break; /* 最后一个词本身就太宽 */ if (first >= 0 && tw + ww > room / 2) break; /* 收不下更多词了 */ char acc[64]; /* 尾巴 = 这一段原文,内部空格照抄 */ int an = (int)(we[nw - 1] - ws[i]); if (an >= (int)sizeof(acc)) break; memcpy(acc, ws[i], an); acc[an] = 0; memcpy(tail, acc, an + 1); tw = disp_text_width(tail, 16, 1); first = i; } int cut = (first >= 0) ? (int)(ws[first] - s) : len; if (first < 0) { /* 没有整词可用:从串尾往前吃字符 */ tw = 0; for (int p = len; p > 0; ) { int q = p - 1; while (q > 0 && ((unsigned char)s[q] & 0xC0) == 0x80) q--; int n = len - q; if (n >= (int)sizeof(tail)) break; /* 先量再收:直接写进 tail 的话,超宽那一轮 break 时 tail 已经变长了, 而 tw 还停在上一轮,尾巴就会比预留多出一个中文字格,压到右边的日期列 */ char cand[64]; memcpy(cand, s + q, n); cand[n] = 0; int ww = disp_text_width(cand, 16, 1); if (ww > room / 2) break; memcpy(tail, cand, n + 1); tw = ww; cut = q; p = q; } } char head[64]; int hw = 0, hn = 0; for (int i = 1; i < cut && i < (int)sizeof(head) - 1; ) { while (i < cut && ((unsigned char)s[i] & 0xC0) == 0x80) i++; /* 不切断 UTF-8 */ if (i >= cut) break; memcpy(head, s, i); head[i] = 0; int w = disp_text_width(head, 16, 1); if (w > room - tw) break; hw = w; hn = i; i++; } head[hn] = 0; while (hn > 0 && head[hn - 1] == ' ') head[--hn] = 0; /* 尾随空格白占宽度 */ if (hn) hw = disp_text_width(head, 16, 1); disp_text(x, y, head, 16, fg, bg); disp_text(x + hw, y, "..", 16, fg, bg); if (tw) disp_text(x + maxw - tw, y, tail, 16, fg, bg); } /* 中文名与英文名不同时才中英并列(系外行星的 name_zh 往往就是英文名) */ static void body_title(const BodyData &b, char *dst, size_t cap) { if (b.name_zh[0] && strcmp(b.name_zh, b.name)) snprintf(dst, cap, "%s %s", b.name_zh, b.name); else strlcpy(dst, b.name, cap); } /* 图标优先用后台「平台管理 -> 天体信息」里维护的那张(已缓存到 PSRAM), 没维护或还没拉下来时统一退回入口页那张天体线稿:ic_planet_* 和模式页的 ic_mode_planet_96 是同一张源图(资源文件/行星小.jpeg)的三个尺寸, 所以列表/详情/入口三处兜底看到的是同一个图案。 不再按名字挑各家专用线稿——那会让没图的天体之间长得不一样。 */ static const IconArt *body_art(const BodyData &b, int detail) { const IconArt *dyn = icon_store_get(&b, detail); return dyn ? dyn : (detail ? &ic_planet_detail : &ic_planet_list); } #if BOARD_HAS_BATTERY /* 电池:跟在网络状态后面,画成通行的电池形——外壳 + 右端铜帽,壳内按电量比例填一段, 充电时中间压一道闪电。颜色照手机那套:充电=绿,≤15% 红、≤30% 橙,其余用状态栏常态青; 没装电池只留个灰壳。总宽 28,比原来那句 "CHG 97%" 还窄。 */ #define BAT_W 26 /* 外壳宽,不含铜帽 */ #define BAT_H 15 /* header 那行是 5..20,取 6..20 正好嵌进去 */ #define BAT_TY 6 #define BAT_PAD 2 /* 外壳到填充区的间距,四周各留 1px 缝 */ /* 闪电:逐行填横条就够,不值得为它写个多边形填充。{ 起列, 止列 } 含端点,7 列 11 行 */ static const uint8_t kBolt[11][2] = { { 2, 5 }, { 1, 5 }, { 1, 4 }, { 0, 3 }, { 0, 5 }, { 2, 5 }, { 2, 5 }, { 2, 4 }, { 2, 3 }, { 2, 3 }, { 2, 2 } }; static void bat_label(int x, const UiState &st) { uint16_t c; if (st.bat_pct < 0) c = C_DIM; else if (st.bat_chg) c = C_GREEN; else if (st.bat_pct <= 15) c = C_RED; else if (st.bat_pct <= 30) c = C_ORANGE; else c = C_CYAN; disp_rect(x, BAT_TY, BAT_W, BAT_H, c); disp_fill(x + BAT_W, BAT_TY + 5, 2, 5, c); /* 铜帽 */ disp_fill(x + 1, BAT_TY + 1, BAT_W - 2, BAT_H - 2, C_BG); /* 垫掉背景星点 */ const int iw = BAT_W - 2 * BAT_PAD, ih = BAT_H - 2 * BAT_PAD; int w = st.bat_pct > 0 ? (iw * st.bat_pct + 50) / 100 : 0; if (w > iw) w = iw; if (w > 0) disp_fill(x + BAT_PAD, BAT_TY + BAT_PAD, w, ih, c); if (st.bat_chg) { const int bx = x + (BAT_W - 7) / 2, by = BAT_TY + (BAT_H - 11) / 2; for (int i = 0; i < 11; i++) disp_fill(bx + kBolt[i][0], by + i, kBolt[i][1] - kBolt[i][0] + 1, 1, C_WHITE); } } #endif static void status_bar(const UiState &st, const char *right) { char sig[28]; uint16_t net_c = C_CYAN; if (st.wifi_up) { /* 连着热点不等于通网:后端连续取不到数据时这里得变脸,否则旧数据看着像在线。 只显示在/离线,不再跟在后面念信号强度——设置页那一栏里还有。 */ if (st.api_fail) snprintf(sig, sizeof(sig), "NET:ONLINE API FAIL"); else strlcpy(sig, "NET:ONLINE", sizeof(sig)); net_c = st.api_fail ? C_ORANGE : C_CYAN; } else { strlcpy(sig, "NET:OFFLINE", sizeof(sig)); net_c = C_RED; } disp_text(4, HDR_TY, sig, 16, net_c, C_BG); #if STRIP && BOARD_HAS_BATTERY bat_label(4 + disp_text_width(sig, 16, 1) + 12, st); #endif if (right && right[0]) text_right(s_info_r, HDR_TY, right, 16, C_CYAN, C_BG); disp_hline(0, HDR_LINE, CONT_W, C_CYAN_DIM); } /* 底部按键条:只有带物理按键的板子需要——它是 KEY0..KEY3 的图例,按下时整块反色做反馈。 长条屏上没有这排东西,页面级动作在状态栏右端,所以那一版直接不画。 */ static void key_bar(const char *const *labels, uint8_t flash) { #if STRIP (void)labels; (void)flash; #else #if BOARD_HAS_TOUCH static const uint16_t SLOT[4] = { XL_IO_KEY0, XL_IO_KEY1, XL_IO_KEY2, XL_IO_KEY3 }; #endif const int x0 = 3, gap = 2, right = LCD_WIDTH - x0; const char *t[4]; int w[4], sum = 0; for (int i = 0; i < 4; i++) { t[i] = labels[i]; /* 没定义的槽位只留个窄条。按真实文字宽度等分的话,故障页这种 「两个空槽 + 两个带字」的组合会把文字挤出自己的按钮,压到隔壁上。 */ w[i] = t[i][0] ? disp_text_width(t[i], 16, 1) + 14 : 26; sum += w[i]; } int avail = (right - x0) - 3 * gap, x = x0; for (int i = 0; i < 4; i++) { int bw = (i == 3) ? (right - x) : avail * w[i] / sum; bool hit = flash & (1 << i); uint16_t bg = hit ? C_GOLD : C_PANEL; disp_panel(x, KEY_Y, bw, KEY_H, 5, bg, hit ? C_GOLD_LT : C_GOLD); if (t[i][0]) { disp_text_center(x, KEY_Y + (KEY_H - 16) / 2, bw, t[i], 16, hit ? C_GOLD_DK : C_GOLD, bg); HIT(x, KEY_Y, bw, KEY_H, SLOT[i], -1); } x += bw + gap; } #endif } static const char *const KEYS_NAV[] = { "KEY0 UP", "KEY1 DN", "KEY2 OK", "KEY3 MODE" }; static const char *const KEYS_MODE[] = { "KEY0 UP", "KEY1 DN", "KEY2 OK", "KEY3 SETUP" }; static const char *const KEYS_ROCKETS[] = { "KEY0 UP", "KEY1 DN", "KEY2 OK", "KEY3 MODE" }; static const char *const KEYS_ROCKET[] = { "KEY0 UP", "KEY1 DN", "KEY2 BACK", "KEY3 TAB" }; static const char *const KEYS_DETAIL[] = { "KEY0 UP", "KEY1 DN", "KEY2 BACK", "KEY3 TAB" }; static const char *const KEYS_PAIR[] = { "", "", "KEY2 SETUP", "KEY3 CODE" }; static const char *const KEYS_NET[] = { "", "", "", "KEY3 SETUP" }; static const char *const KEYS_FAULT[] = { "", "", "KEY2 SETUP", "KEY3 REF" }; static const char *const KEYS_EMPTY[] = { "", "", "", "" }; static const char *const KEYS_SETUP[] = { "", "", "", "KEY3 RETRY" }; /* 设置页只读,改东西要去配网门户(那里能同时改 WiFi 和后端地址) */ static const char *const KEYS_SETTINGS[] = { "", "", "KEY2 SETUP", "KEY3 BACK" }; static const char *const KEYS_UPDATE[] = { "", "", "KEY2 INSTALL", "KEY3 BACK" }; #if BOARD_HAS_TOUCH /* 提示语里别再说 KEY2/KEY3:这板上只有 BOOT 一颗可编程键,其余全靠点屏幕。 方括号里那两个字就是状态栏右上角那颗按钮上的字,两边得对得上。 */ #define TXT_SETUP_HOTSPOT2 "右上角点 [CONFIG]" #define TXT_SETUP_HOTSPOT3 "右上角点 [CONFIG]" #define TXT_PRESS_INSTALL "点 [INSTALL] 开始下载" #define TXT_PRESS_BACK "点 [BACK] 退出" #else #define TXT_SETUP_HOTSPOT2 "KEY2 OPENS THE SETUP HOTSPOT" #define TXT_SETUP_HOTSPOT3 "KEY3 OPENS THE SETUP HOTSPOT" #define TXT_PRESS_INSTALL "PRESS KEY2 TO INSTALL" #define TXT_PRESS_BACK "KEY3 BACK" #endif static void fmt_au(char *buf, size_t cap, float v) { if (v >= 100.0f) snprintf(buf, cap, "%.1f", v); else if (v >= 10.0f) snprintf(buf, cap, "%.2f", v); else snprintf(buf, cap, "%.3f", v); } static void draw_splash(const UiState &st) { /* 两条程序化轨道打底,面板压在轨道之上。轨道按屏宽等比缩放,320x240 时就是原稿的 150/58; 长条屏横着有的是宽度,卡的是 172 的高度,所以按高度收一份再取小的 */ const int cx = CONT_W / 2, cy = LCD_HEIGHT / 2; const int rx = min(LCD_WIDTH / 2 - 10, (LCD_HEIGHT / 2 - 12) * 150 / 58); const int ry = rx * 58 / 150, rx2 = rx * 116 / 150, ry2 = rx * 40 / 150; for (int i = 0; i < 180; i++) { float a = i * 3.1415926f / 90.0f; disp_pixel(cx + (int)(cosf(a) * rx), cy + (int)(sinf(a) * ry), C_TRACE); disp_pixel(cx + (int)(cosf(a) * rx2), cy + (int)(sinf(a) * ry2), C_TRACE); } disp_disc(cx + (int)(cosf(3.6f) * rx), cy + (int)(sinf(3.6f) * ry), 2, C_CYAN_DIM); disp_disc(cx + (int)(cosf(0.7f) * rx2), cy + (int)(sinf(0.7f) * ry2), 2, C_GOLD_DIM); #if STRIP const int pw = 240, px = (CONT_W - pw) / 2; #else const int px = SPLASH_PAD, pw = LCD_WIDTH - 2 * SPLASH_PAD; #endif const int py = cy - 68; disp_panel_glow(px, py, pw, 76, 12, C_CYAN_DIM); disp_panel(px, py, pw, 76, 12, C_PANEL, C_CYAN); /* 辉光 = 同一字模向四个方向用低阶色先印一遍,最后覆盖亮色 */ static const int off[4][2] = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } }; for (int i = 0; i < 4; i++) disp_text_center(px + off[i][0], py + 6 + off[i][1], pw, "COSMO", 32, C_CYAN_DIM, C_PANEL, 2); disp_text_center(px, py + 6, pw, "COSMO", 32, C_GREEN, C_PANEL, 2); disp_text_center(0, cy + 20, CONT_W, "ORBITAL TERMINAL", 16, C_CYAN, C_BG); disp_text_center(0, cy + 44, CONT_W, st.device_id, 16, C_DIM, C_BG); if (st.ssid[0]) { char msg[48]; snprintf(msg, sizeof(msg), "WIFI %s", st.ssid); disp_text_center(0, cy + 66, CONT_W, msg, 16, C_DIM, C_BG); } } static void draw_provision(const UiState &st) { const int px = 8, py = TOP_Y, pw = CONT_W - 16; const int ph = STRIP ? (BOT_Y - py + 1) : 176; disp_panel_glow(px, py, pw, ph, 10, C_CYAN_DIM); disp_panel(px, py, pw, ph, 10, C_PANEL, C_GOLD); disp_text(px + 12, py + 6, "NETWORK SETUP", 16, C_GOLD, C_PANEL); char msg[96]; #if STRIP /* 够两栏:左边是"连哪个热点、开哪个地址"的操作步骤,右边是当前状态 */ const int rw = 200, rx = px + pw - 12 - rw, lw = rx - px - 24; int y = py + 24; disp_text(px + 12, y, "1. JOIN THIS HOTSPOT", 16, C_DIM, C_PANEL); disp_text_clipped(px + 12, y + 18, lw, st.ap_ssid, 16, C_GOLD, C_PANEL); disp_text(px + 12, y + 40, "2. OPEN IN BROWSER", 16, C_DIM, C_PANEL); disp_text(px + 12, y + 58, "http://192.168.4.1", 16, C_CYAN, C_PANEL); disp_text_wrap(px + 12, y + 80, lw, "3. SAVE, THEN BIND ON THE WEB", 16, C_DIM, C_PANEL, 2); y = flow(rx, py + 10, rw, st.reason[0] ? st.reason : "NO SAVED WIFI CREDENTIALS", C_ORANGE, C_PANEL, 8); snprintf(msg, sizeof(msg), "API %s", st.api); disp_text_wrap(rx, y, rw, msg, 16, C_CYAN_DIM, C_PANEL, 3); #else /* 首次开机是没存凭据,跑着用是连不上,都落到这一页,原因写第一行 */ disp_text_clipped(px + 12, py + 26, pw - 24, st.reason[0] ? st.reason : "NO SAVED WIFI CREDENTIALS", 16, C_ORANGE, C_PANEL); snprintf(msg, sizeof(msg), "API %s", st.api); disp_text_clipped(px + 12, py + 50, pw - 24, msg, 16, C_CYAN_DIM, C_PANEL); disp_text(px + 12, py + 76, "1. JOIN THIS HOTSPOT", 16, C_DIM, C_PANEL); snprintf(msg, sizeof(msg), "%s", st.ap_ssid); disp_text_clipped(px + 12, py + 94, pw - 24, msg, 16, C_GOLD, C_PANEL); disp_text(px + 12, py + 116, "2. OPEN IN BROWSER", 16, C_DIM, C_PANEL); disp_text(px + 12, py + 134, "http://192.168.4.1", 16, C_CYAN, C_PANEL); disp_text(px + 12, py + 156, "3. SAVE, THEN BIND ON THE WEB", 16, C_DIM, C_PANEL); #endif } static void draw_connecting(const UiState &st) { const int px = STRIP ? 8 : 24, py = STRIP ? TOP_Y : 40, pw = CONT_W - 2 * px; const int ph = STRIP ? (BOT_Y - py + 1) : 158; disp_panel(px, py, pw, ph, 10, C_PANEL, C_CYAN); disp_text_center(px, py + 6, pw, "CONNECTING", 16, C_CYAN, C_PANEL); /* 环形进度:一圈刻度 + 随 millis 转动的指针。长条屏这页只有 150 高, 圆盘挪到左边、文字整列排在右边,不然圆盘旋着会把下面几行顶出面板 */ #if STRIP const int dgx = px + 24, dgy = py + 70; #else const int dgx = LCD_WIDTH / 2, dgy = py + 36; #endif disp_ring(dgx, dgy, 14, C_CYAN_DIM); float a = (millis() % 1600) / 1600.0f * 2 * 3.1415926f; disp_disc(dgx + (int)(cosf(a) * 14), dgy + (int)(sinf(a) * 14), 3, C_GREEN); char msg[64]; uint32_t dots = (millis() / 400) % 4; snprintf(msg, sizeof(msg), "%s%.*s", st.ssid, (int)dots, "..."); #if STRIP int y = py + 26; const int tx = px + 52, tw = pw - 64; y = flow(tx, y, tw, msg, C_GREEN, C_PANEL, 4); /* 连不上的话先说清楚为什么,再告诉用户它不会一直卡在这 */ if (st.reason[0]) y = flow(tx, y, tw, st.reason, C_ORANGE, C_PANEL, 4); if (st.hint[0]) y = flow(tx, y, tw, st.hint, C_DIM, C_PANEL, 4); snprintf(msg, sizeof(msg), "API %s", st.api); y = flow(tx, y, tw, msg, C_DIM, C_PANEL, 8); flow(tx, y, tw, TXT_SETUP_HOTSPOT3, C_CYAN_DIM, C_PANEL, 4); #else disp_text_clipped(px + 10, py + 62, pw - 20, msg, 16, C_GREEN, C_PANEL); /* 连不上的话先说清楚为什么,再告诉用户它不会一直卡在这 */ if (st.reason[0]) disp_text_clipped(px + 10, py + 82, pw - 20, st.reason, 16, C_ORANGE, C_PANEL); if (st.hint[0]) disp_text_clipped(px + 10, py + 100, pw - 20, st.hint, 16, C_DIM, C_PANEL); snprintf(msg, sizeof(msg), "API %s", st.api); disp_text_clipped(px + 10, py + 118, pw - 20, msg, 16, C_DIM, C_PANEL); disp_text_clipped(px + 10, py + 136, pw - 20, TXT_SETUP_HOTSPOT3, 16, C_CYAN_DIM, C_PANEL); #endif } static void draw_pair(const UiState &st) { const int px = 8, pw = CONT_W - 16, ph = STRIP ? (BOT_Y - TOP_Y + 1) : 180; const int py = STRIP ? TOP_Y : 28; disp_panel_glow(px, py, pw, ph, 10, C_CYAN_DIM); disp_panel(px, py, pw, ph, 10, C_PANEL, C_GREEN); disp_text_center(px, py + (STRIP ? 6 : 8), pw, "DEVICE BINDING", 16, C_GREEN, C_PANEL); if (!st.code[0]) { /* 拿不到码多半是换了网段/后端地址填错,这一页必须给出配网出口 */ disp_text_wrap(px + 14, py + 40, pw - 28, st.message, 16, C_ORANGE, C_PANEL, STRIP ? 3 : 4); char line[96]; snprintf(line, sizeof(line), "API %s", st.api); disp_text_clipped(px + 10, py + ph - 42, pw - 20, line, 16, C_DIM, C_PANEL); disp_text_clipped(px + 10, py + ph - 24, pw - 20, TXT_SETUP_HOTSPOT2, 16, C_CYAN_DIM, C_PANEL); return; } #if STRIP /* 长条屏横着够宽:左边放大验证码和有效期条,右边写"这码在哪输、这台设备是谁" */ const int bx = px + 16, bw = 220; #else const int bx = px + 22, bw = pw - 44; #endif /* 长条屏 header 占得高,验证码面板、倒计时条、"EXPIRES IN" 整体往上挪 4px */ const int cp = STRIP ? 26 : 28, cby = STRIP ? 108 : 112, cty = STRIP ? 120 : 126; disp_panel(bx, py + cp, bw, 76, 6, C_BG, C_CYAN_DIM); /* 16x32 字模放大 2 倍(每字 34px),6 位码 202px,两种版面都放得下 */ const int adv = 34, gs = 2; int cw = (int)strlen(st.code) * adv - 2; int x = STRIP ? bx + (bw - cw) / 2 : (LCD_WIDTH - cw) / 2; for (const char *p = st.code; *p; p++, x += adv) disp_text(x, py + cp + 6, p, 32, C_GREEN, C_BG, gs); /* 有效期倒计时条:最后 15 秒转红 */ int fill = 0; if (st.code_total > 0) fill = bw * st.code_left / st.code_total; disp_fill(bx + 12, py + cby, bw - 24, 6, C_TRACE); disp_fill(bx + 12, py + cby, (bw - 24) * fill / (bw ? bw : 1), 6, st.code_left < 15 ? C_RED : C_GOLD); char msg[48]; snprintf(msg, sizeof(msg), "EXPIRES IN %ds", st.code_left); disp_text_center(STRIP ? bx : px, py + cty, STRIP ? bw : pw, msg, 16, st.code_left < 15 ? C_RED : C_GOLD, C_PANEL); #if STRIP const int rx = bx + bw + 24, rw = px + pw - 12 - rx; disp_text(rx, py + 32, "ENTER CODE ON WEB", 16, C_TEXT, C_PANEL); snprintf(msg, sizeof(msg), "USER: %s", st.owner[0] ? st.owner : "?"); disp_text_clipped(rx, py + 56, rw, msg, 16, C_GREEN, C_PANEL); disp_text(rx, py + 80, "DEVICE", 16, C_DIM, C_PANEL); disp_text_clipped(rx, py + 98, rw, st.device_id, 16, C_CYAN_DIM, C_PANEL); #else snprintf(msg, sizeof(msg), "ENTER CODE ON WEB / USER: %s", st.owner[0] ? st.owner : "?"); disp_text_clipped(px + 10, py + 146, pw - 20, msg, 16, C_TEXT, C_PANEL); snprintf(msg, sizeof(msg), "DEV %s", st.device_id); disp_text_clipped(px + 10, py + 164, pw - 20, msg, 16, C_CYAN_DIM, C_PANEL); #endif } static void draw_list(const UiState &st) { const Snapshot *s = st.snap; if (!s || !s->count) { if (st.busy) return; /* 还在取:留着空白 + header 那条动线,别误报"没关注天体" */ disp_text_center(0, 84, CONT_W, "NO FOLLOWED BODIES", 16, C_ORANGE, C_BG); disp_text_center(0, 108, CONT_W, "FOLLOW ONE ON THE WEB UI", 16, C_DIM, C_BG); return; } int scroll = st.sel; if (scroll > s->count - LIST_ROWS) scroll = s->count - LIST_ROWS; if (scroll < 0) scroll = 0; for (int i = scroll; i < s->count && i < scroll + LIST_ROWS; i++) { const BodyData &b = s->bodies[i]; int y = TOP_Y + (i - scroll) * CARD_PITCH; bool sel = (i == st.sel); uint16_t bg = sel ? C_SEL : C_PANEL; if (sel) disp_panel_glow(CARD_X, y, CARD_W, CARD_H, 8, C_CYAN_DIM); disp_panel(CARD_X, y, CARD_W, CARD_H, 8, bg, sel ? C_CYAN : C_CYAN_DIM); disp_fill(CARD_X + 3, y + (CARD_H - 42) / 2, 3, 42, sel ? C_GOLD : C_TRACE); const IconArt *ic = body_art(b, 0); if (ic) disp_add_bitmap(CARD_X + 10, y + (CARD_H - ic->h) / 2, ic->w, ic->h, ic->px); char title[56]; body_title(b, title, sizeof(title)); disp_text_clipped(CARD_X + 57, y + CARD_TY, STRIP ? CARD_W - 70 : 188, title, 16, sel ? C_WHITE : C_TEXT, bg); char line[32], v[16]; fmt_au(v, sizeof(v), b.dist); snprintf(line, sizeof(line), "DIST: %s AU", v); disp_text(CARD_X + 57, y + CARD_SY, line, 16, sel ? C_GOLD : C_CYAN_DIM, bg); HIT(CARD_X, y, CARD_W, CARD_H, XL_IO_KEY2, i); } /* 右缘滚动条取代原来的 v+N 文字 */ int sbh = BOT_Y - TOP_Y + 1; disp_fill(SB_X, TOP_Y, 2, sbh, C_TRACE); int th = sbh * LIST_ROWS / s->count; if (th > sbh) th = sbh; if (th < 12) th = 12; int span = s->count - LIST_ROWS; int ty = TOP_Y + (span > 0 ? (sbh - th) * scroll / span : 0); disp_fill(SB_X, ty, 2, th, C_CYAN); } /* 数据面板里的一项:标签靠左、数值右对齐到 ir */ struct Kv { const char *l; char v[20]; }; static void kv_cell(int lx, int ir, int y, const char *l, const char *v, uint16_t lc, uint16_t vc) { disp_text(lx, y, l, 16, lc, C_PANEL); text_right(ir, y, v, 16, vc, C_PANEL); } #if STRIP /* 长条屏的信息栏改成竖排,每块只剩 65 高:四项排成 2x2, 一格净宽 112,所以标签一律用三四个字母的缩写(见调用处) */ static void kv_grid(int x, int y, int w, int h, const Kv k[4], uint16_t lc, int hl) { const int gy[2] = { y + 24, y + h - 20 }; const int cw = w / 2; for (int i = 0; i < 4; i++) { int cx = x + (i & 1) * cw; kv_cell(cx + 8, cx + cw - 8, gy[i >> 1], k[i].l, k[i].v, lc, (i == hl) ? C_WHITE : C_TEXT); } } #endif static void draw_detail(const UiState &st) { const Snapshot *s = st.snap; if (!s || st.sel >= s->count) return; const BodyData &b = s->bodies[st.sel]; /* 标题:中文名 + 英文名 + 类型,右端是位置历元(年份省掉,屏太窄) */ char time_s[16]; strlcpy(time_s, (strlen(b.pos_time) >= 10) ? b.pos_time + 5 : b.pos_time, sizeof(time_s)); char title[72], name[56], typ[17]; body_title(b, name, sizeof(name)); int tn = 0; for (; b.type[tn] && tn < (int)sizeof(typ) - 1; tn++) typ[tn] = toupper((unsigned char)b.type[tn]); typ[tn] = 0; snprintf(title, sizeof(title), "%s (%s)", name, typ); int timew = disp_text_width(time_s, 16, 1); #if STRIP /* 长条屏这页不再画状态栏:0..19 那一行留给页头本身(标题 + 历元), 不然 172 高的屏上会叠出两层 header */ disp_text_clipped(4, HDR_TY, s_info_r - timew - 12, title, 16, C_CYAN, C_BG); text_right(s_info_r, HDR_TY, time_s, 16, C_DIM, C_BG); disp_hline(0, HDR_LINE, CONT_W, C_CYAN_DIM); #else disp_text_clipped(4, 20, s_info_r - timew - 12, title, 16, C_CYAN, C_BG); text_right(s_info_r, 20, time_s, 16, C_DIM, C_BG); #endif #if STRIP /* 长条屏(640 宽)三栏:图标独占一列全高格,两组信息竖着排一列, 剩下的整块宽度全给事件面板——图标和事件才是这页的核心 */ const int iy = TOP_Y, ih = BOT_Y - iy + 1; /* 页头只剩一行,内容区顶到 TOP_Y */ const int ix = 2, iw = 148, icr = 59; const int mx = ix + iw + 7, mw = 224, mh = (ih - 3) / 2; const int qx = mx + mw + 7, qw = CONT_W - qx - 3; const int by = iy, by2 = iy + mh + 3; const int pw = mw, ph = mh, lx = mx, rx = mx; #else const int pw = 156, ph = 88, by = 40; const int lx = 3, rx = 161, by2 = by; const int iy = 132, ih = BOT_Y - iy + 1, iw = 88, icr = 34; const int ix = 3, qx = 95, qw = 222; #endif const int py = iy, bh = ih; disp_panel(lx, by, pw, ph, 6, C_PANEL, C_CYAN); disp_panel(rx, by2, pw, ph, 6, C_PANEL, C_GOLD); disp_text(lx + 8, by + 4, "POS (AU)", 16, C_GOLD, C_PANEL); disp_text(rx + 8, by2 + 4, "VEL (KM/S)", 16, C_GOLD, C_PANEL); Kv L[4], R[4]; const char *lp[4] = { "X", "Y", "Z", "DIST" }; float lv[4] = { b.x, b.y, b.z, b.dist }; const char *rp[4] = { "VX", "VY", "VZ", "SPEED" }; float rv[4] = { b.vx, b.vy, b.vz, b.speed }; for (int i = 0; i < 4; i++) { L[i].l = lp[i]; R[i].l = rp[i]; fmt_au(L[i].v, sizeof(L[i].v), lv[i]); if (b.has_vel) snprintf(R[i].v, sizeof(R[i].v), "%.1f", rv[i]); else strlcpy(R[i].v, "--", sizeof(R[i].v)); } #if STRIP kv_grid(lx, by, pw, ph, L, C_CYAN_DIM, 3); kv_grid(rx, by2, pw, ph, R, C_GOLD_DIM, 3); #else const int rows[4] = { by + 21, by + 37, by + 53, by + 69 }; for (int i = 0; i < 4; i++) { kv_cell(lx + 8, lx + pw - 8, rows[i], L[i].l, L[i].v, C_CYAN_DIM, (i == 3) ? C_WHITE : C_TEXT); kv_cell(rx + 8, rx + pw - 8, rows[i], R[i].l, R[i].v, C_GOLD_DIM, (i == 3) ? C_WHITE : C_TEXT); } #endif /* 霓虹线稿天体图标 + 雷达底纹:横屏是左边一竖条,长条屏是通高一格, 64 的线稿按格子放大到最近邻的整数倍,小图放大才不糊 */ disp_panel(ix, iy, iw, ih, 6, C_PANEL, C_CYAN_DIM); disp_radar(ix + iw / 2, iy + ih / 2, icr); const IconArt *ic = body_art(b, 1); if (ic) { int sc = 1; while (ic->w * (sc + 1) <= iw - 12 && ic->h * (sc + 1) <= ih - 6) sc++; disp_add_bitmap(ix + (iw - ic->w * sc) / 2, iy + (ih - ic->h * sc) / 2, ic->w, ic->h, ic->px, (uint8_t)sc); } /* EVENTS / INFO 分页:点标签直接跳页 */ disp_panel_glow(qx, py, qw, bh, 6, C_CYAN_DIM); disp_panel(qx, py, qw, bh, 6, C_PANEL, C_CYAN); const char *tabs[2] = { "[EVENTS]", "[INFO]" }; int tx = qx + 8; for (int i = 0; i < 2; i++) { bool on = (st.detail_tab == i); int tw = disp_text_width(tabs[i], 16, 1); disp_text(tx, py + 4, tabs[i], 16, on ? C_GOLD : C_DIM, C_PANEL); if (on) disp_hline(tx, py + 22, tw - 1, C_GOLD); HIT(tx, py + 2, tw + 8, 24, UI_ACT_TAB, i); tx += tw + 12; } if (st.detail_tab == 0) { if (!b.ev_count) { disp_text(qx + 8, py + 24, "NO EVENTS", 16, C_DIM, C_PANEL); return; } const int evr = STRIP ? 24 : 18; /* 栏高了 16px,四行事件摊开一点 */ const int evn = STRIP ? MAX_EVENTS : 3; /* 横屏那块面板纵向只放得下三行 */ for (int i = 0; i < b.ev_count && i < evn; i++) { int y = py + 24 + i * evr; char ds[8]; snprintf(ds, sizeof(ds), "%.5s ", (strlen(b.ev_date[i]) >= 10) ? b.ev_date[i] + 5 : b.ev_date[i]); disp_text(qx + 8, y, ds, 16, C_CYAN_DIM, C_PANEL); int used = disp_text_width(ds, 16, 1); disp_text_clipped(qx + 8 + used, y, qw - 16 - used, b.ev[i], 16, (i == 0) ? C_WHITE : C_TEXT, C_PANEL); } } else { disp_text_clipped(qx + 8, py + 24, qw - 16, name, 16, C_WHITE, C_PANEL); if (!b.desc[0]) { disp_text(qx + 8, py + 44, "NO DESCRIPTION", 16, C_DIM, C_PANEL); return; } /* 两行 12 字:留一个字位给 clip_chars 补的 "..",否则截断标记会被行宽吃掉。 长条屏那栏窄但高,四行 8 字 */ char desc[STRIP ? 136 : 96]; clip_chars(desc, sizeof(desc), b.desc, STRIP ? 30 : 23); disp_text_wrap(qx + 8, py + 44, qw - 16, desc, 16, C_TEXT, C_PANEL, STRIP ? 4 : 2); } } /* ================= 火箭模式 ================= */ /* 立绘优先用后端按参数画的那张(已缓存到 PSRAM);后台改过参数或还没拉下来时 退回固件内置的通用火箭,尺寸一致所以版面不用分叉 */ static const IconArt *rocket_art(const RocketData &r, int detail) { const IconArt *dyn = rocket_store_get(r.code, r.art_ver, detail); if (dyn) return dyn; return detail ? &ic_rocket_detail : &ic_rocket_list; } static void rocket_title(const RocketData &r, char *dst, size_t cap) { if (r.name_zh[0] && strcmp(r.name_zh, r.name)) snprintf(dst, cap, "%s %s", r.name_zh, r.name); else strlcpy(dst, r.name, cap); } #if STRIP /* ---------------- 首页中间的核子时钟(翻页钟样式,见 gen_nixie.py) ---------------- 只借翻页钟的外观(白卡/分裂线/轴套),不做翻页动画:到点整张卡换一张。 卡片点阵两侧各含 2px 面板底色边,贴图 X 减 2,轴套才有地方凸出到缝里。 版面(内容区 31..171,中间格 165..475): 时间行 = 3组 x (42*2+2) + 2个16px冒号位 = 290 -> 175..465 日期行 = 年4张+月2张+日2张 + 2个20px斜杠缝 = 290,与时间行同宽同左边 时间卡 y=40..105,日期卡 y=116..161,上下留白 9/10px 两行分隔符同尺寸(都 5x5):冒号浅灰白,日期分组点纯白。 */ #define NX_CARD_W 155 #define NX_CLK_X (4 + NX_CARD_W + 6) /* 165 */ #define NX_CLK_W (CONT_W - 2 * NX_CLK_X) /* 310 = 155*2 */ #define NX_MARG 2 /* 点阵含的背景边,与 gen_nixie.py 的 MARG 一致 */ #define NX_GAPY 10 /* 时间行与日期行的缝 */ #define NX_COLON_W 16 /* 时:分:秒 两个冒号位 */ #define NX_TROW (3 * (2 * FLAP_W + 2) + 2 * NX_COLON_W) /* 290 */ #define NX_BLANK 10 /* 点阵第 11 张:卡面 + 一条墨杠 */ /* 六张时间卡的 X(相对整行左端):时/时 分/分 秒/秒 */ static const int NX_T_X[6] = { 0, 44, 102, 146, 204, 248 }; static const int NX_D_X[8] = { 0, 32, 64, 96, 146, 178, 228, 260 }; /* 年月 月 日 */ static const int NX_DOT_X[2] = { 92, 194 }; /* 冒号方点左上角(5x5) */ static const int NX_SEP_X[2] = { 136, 218 }; /* 年/月、月/日 两条 20px 缝的中心 */ /* 日期分组之间的圆点,5x5 和上面那对冒号一样大:两行的分隔符要在同一套视觉里, 上一行是 5x5 方点、这一行小一号的话,眼睛会把它当成数字的一部分而不是分隔符。 用点不用斜杠/横线:斜杠在这个尺寸上全是锯齿,横线会和卡片分裂线混在一起。 5x5 居中在 20px 缝里,左右净空 8/7px(20-5 是奇数),压不到卡片也不碰轴套。 */ static void flap_dot(int cx, int cy) { disp_fill(cx - 2, cy - 2, 5, 5, C_WHITE); } static void draw_nixie(int px, int pw) { disp_panel_glow(px, TOP_Y, pw, BOT_Y - TOP_Y + 1, 10, C_GOLD_DK); disp_panel(px, TOP_Y, pw, BOT_Y - TOP_Y + 1, 10, C_PANEL, C_GOLD_DIM); char buf[24]; int y, mo, d, hh, mi, ss; clock_local(buf, sizeof(buf)); const bool live = clock_ready() && sscanf(buf, "%d-%d-%d %d:%d:%d", &y, &mo, &d, &hh, &mi, &ss) == 6; if (!live) { y = mo = d = hh = mi = ss = 0; } const int ty = TOP_Y + ((BOT_Y - TOP_Y + 1) - (FLAP_H + NX_GAPY + FLAP_DH)) / 2; const int dy = ty + FLAP_H + NX_GAPY; const int x0 = px + (pw - NX_TROW) / 2; const int tv[6] = { hh / 10, hh % 10, mi / 10, mi % 10, ss / 10, ss % 10 }; const int dv[8] = { y / 1000, y / 100 % 10, y / 10 % 10, y % 10, mo / 10, mo % 10, d / 10, d % 10 }; for (int i = 0; i < 6; i++) /* 没对时 14 张卡全显示墨杠,不摆假时间 */ disp_blit(x0 + NX_T_X[i] - NX_MARG, ty, FLAP_TIME_BW, FLAP_H, flap_time[live ? tv[i] : NX_BLANK]); for (int i = 0; i < 8; i++) disp_blit(x0 + NX_D_X[i] - NX_MARG, dy, FLAP_DATE_BW, FLAP_DH, flap_date[live ? dv[i] : NX_BLANK]); for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) disp_fill(x0 + NX_DOT_X[i], ty + FLAP_H / 2 - 11 + j * 17, 5, 5, C_FLAP_DOT); for (int i = 0; i < 2; i++) flap_dot(x0 + NX_SEP_X[i], dy + FLAP_DH / 2); } #endif /* 入口页:长条屏是三分屏(卡片 / 核子时钟 / 卡片),横屏是两块并排面板。 图标是 96x96 的大图(gen_assets.py 烘进固件) */ static void draw_mode(const UiState &st) { #if !STRIP disp_text_center(0, TOP_Y, LCD_WIDTH, "SELECT TERMINAL MODE", 16, C_CYAN, C_BG); #endif const char *zh[2] = { "天体", "火箭" }; const char *en[2] = { "CELESTIAL", "LAUNCHER" }; const IconArt *art[2] = { &ic_mode_planet_96, &ic_mode_rocket_96 }; for (int i = 0; i < 2; i++) { #if STRIP /* 左右两格各 155 宽(1:2:1 的 1),中间 310 留给核子时钟;96 图标 + 两行标签正好铺满一格 */ const int w = NX_CARD_W, x = 4 + i * (NX_CARD_W + 12 + NX_CLK_W), y = TOP_Y, h = BOT_Y - TOP_Y + 1; const int iy = y + 4, ty = y + 104; #else const int x = 8 + i * 154, y = 42, w = 150, h = 146; const int iy = y + 6, ty = y + 108; #endif bool sel = (st.mode_sel == i); uint16_t bg = sel ? C_SEL : C_PANEL; if (sel) disp_panel_glow(x, y, w, h, 10, C_CYAN_DIM); disp_panel(x, y, w, h, 10, bg, sel ? C_CYAN : C_CYAN_DIM); if (sel) disp_fill(x + 3, y + 14, 3, h - 28, C_GOLD); const IconArt *ic = art[i]; /* 图标往上提一点,两行标签才不会被面板下沿的切角吃掉 */ disp_add_bitmap(x + (w - ic->w) / 2, iy, ic->w, ic->h, ic->px); disp_text_center(x, ty, w, zh[i], 16, sel ? C_WHITE : C_TEXT, bg); disp_text_center(x, ty + 18, w, en[i], 16, sel ? C_GOLD : C_CYAN_DIM, bg); HIT(x, y, w, h, XL_IO_KEY2, i); } #if STRIP draw_nixie(NX_CLK_X, NX_CLK_W); #endif } /* 和天体列表同一种卡片,右侧换成"还有几次发射",因为火箭没有订阅开关那种状态 */ static void draw_rockets(const UiState &st) { const RocketSnapshot *s = st.rsnap; if (!s || !s->count) { if (st.busy) return; /* 同 draw_list:取数途中不报"没有火箭" */ disp_text_center(0, 84, CONT_W, "NO ACTIVE ROCKETS", 16, C_ORANGE, C_BG); disp_text_center(0, 108, CONT_W, "ENABLE ONE IN ADMIN", 16, C_DIM, C_BG); return; } int scroll = st.rsel; if (scroll > s->count - LIST_ROWS) scroll = s->count - LIST_ROWS; if (scroll < 0) scroll = 0; for (int i = scroll; i < s->count && i < scroll + LIST_ROWS; i++) { const RocketData &r = s->rockets[i]; int y = TOP_Y + (i - scroll) * CARD_PITCH; bool sel = (i == st.rsel); uint16_t bg = sel ? C_SEL : C_PANEL; if (sel) disp_panel_glow(CARD_X, y, CARD_W, CARD_H, 8, C_CYAN_DIM); disp_panel(CARD_X, y, CARD_W, CARD_H, 8, bg, sel ? C_CYAN : C_CYAN_DIM); disp_fill(CARD_X + 3, y + (CARD_H - 42) / 2, 3, 42, sel ? C_GOLD : C_TRACE); const IconArt *ic = rocket_art(r, 0); disp_add_bitmap(CARD_X + 10, y + (CARD_H - ic->h) / 2, ic->w, ic->h, ic->px); char title[56], line[40]; rocket_title(r, title, sizeof(title)); disp_text_clipped(CARD_X + 57, y + CARD_TY, STRIP ? CARD_W - 100 : 186, title, 16, sel ? C_WHITE : C_TEXT, bg); snprintf(line, sizeof(line), "H %d.%dM PAY %d.%dT", (int)r.height_m, ((int)(r.height_m * 10)) % 10, (int)(r.payload_kg / 1000.0f), ((int)(r.payload_kg / 100.0f)) % 10); disp_text_clipped(CARD_X + 57, y + CARD_SY, STRIP ? CARD_W - 130 : 186, line, 16, sel ? C_GOLD : C_CYAN_DIM, bg); char nb[8]; snprintf(nb, sizeof(nb), (r.upcoming > 0) ? "%u" : "--", (unsigned)r.upcoming); #if STRIP /* 次数那一列贴右缘,长条屏的卡片够宽,不用再居中一个 LAUNCH 标签 */ text_right(CARD_X + CARD_W - 8, y + CARD_TY, nb, 16, r.upcoming ? C_GOLD : C_DIM, bg); text_right(CARD_X + CARD_W - 8, y + CARD_SY, "LAUNCH", 16, r.upcoming ? C_GOLD_DIM : C_DIM, bg); #else text_right(308, y + 8, nb, 16, r.upcoming ? C_GOLD : C_DIM, bg); disp_text_center(250, y + 34, 58, "LAUNCH", 16, r.upcoming ? C_GOLD_DIM : C_DIM, bg); #endif HIT(CARD_X, y, CARD_W, CARD_H, XL_IO_KEY2, i); } int sbh = BOT_Y - TOP_Y + 1; disp_fill(SB_X, TOP_Y, 2, sbh, C_TRACE); int th = sbh * LIST_ROWS / s->count; if (th > sbh) th = sbh; if (th < 12) th = 12; int span = s->count - LIST_ROWS; int ty = TOP_Y + (span > 0 ? (sbh - th) * scroll / span : 0); disp_fill(SB_X, ty, 2, th, C_CYAN); } static void draw_rocket(const UiState &st) { const RocketDetail *d = st.rdet; if (!d || !d->base.code[0]) return; const RocketData &r = d->base; /* 标题就是型号名(页面本身已经说明是 TARGET),右端留最近一次发射的日期 */ char title[56], next[20]; rocket_title(r, title, sizeof(title)); if (d->next_date[0] && strlen(d->next_date) >= 10) snprintf(next, sizeof(next), "NEXT %.*s", 5, d->next_date + 5); else strlcpy(next, "NO LAUNCH", sizeof(next)); int nextw = disp_text_width(next, 16, 1); #if STRIP disp_text_clipped(4, HDR_TY, s_info_r - nextw - 12, title, 16, C_CYAN, C_BG); text_right(s_info_r, HDR_TY, next, 16, d->event_total ? C_CYAN_DIM : C_DIM, C_BG); disp_hline(0, HDR_LINE, CONT_W, C_CYAN_DIM); #else disp_text_clipped(4, 20, s_info_r - nextw - 12, title, 16, C_CYAN, C_BG); text_right(s_info_r, 20, next, 16, d->event_total ? C_CYAN_DIM : C_DIM, C_BG); #endif #if STRIP /* 和天体详情页同构:左边通高图标格,中间一列两组参数,右边整块给任务面板 */ const int iy = TOP_Y, ih = BOT_Y - iy + 1; const int ix = 2, iw = 148, icr = 59; const int mx = ix + iw + 7, mw = 224, mh = (ih - 3) / 2; const int qx = mx + mw + 7, qw = CONT_W - qx - 3; const int by = iy, by2 = iy + mh + 3; const int pw = mw, ph = mh, lx = mx, rx = mx; /* 一格净宽 112,标签一律缩写 */ const char *lp[4] = { "LEN", "DIA", "PAY", "ORB" }; const char *rp[4] = { "THR", "ISP", "ENG", "BST" }; const int tp = 26; /* 面板高了,三行任务/分级摊开 */ #else const int pw = 156, ph = 88, by = 40; const int lx = 3, rx = 161, by2 = by; const int iy = 132, ih = BOT_Y - iy + 1, iw = 88, icr = 34; const int ix = 3, qx = 95, qw = 222; const char *lp[4] = { "HEIGHT", "DIAMETER", "PAYLOAD", "ORBIT" }; const char *rp[4] = { "THRUST", "ISP", "ENGINES", "BOOSTERS" }; const int tp = 18; #endif const int py = iy, bh = ih; disp_panel(lx, by, pw, ph, 6, C_PANEL, C_CYAN); disp_panel(rx, by2, pw, ph, 6, C_PANEL, C_GOLD); disp_text(lx + 8, by + 4, "SPECS", 16, C_GOLD, C_PANEL); disp_text(rx + 8, by2 + 4, "PERFORMANCE", 16, C_GOLD, C_PANEL); char v[20]; Kv L[4], R[4]; for (int i = 0; i < 4; i++) { L[i].l = lp[i]; R[i].l = rp[i]; } snprintf(L[0].v, sizeof(L[0].v), "%.1f M", r.height_m); snprintf(L[1].v, sizeof(L[1].v), "%.1f M", r.diameter_m); snprintf(L[2].v, sizeof(L[2].v), "%.1f T", r.payload_kg / 1000.0f); /* 长条屏一格放不下 "ORBIT 2000 KM",单位和数字连着写 */ snprintf(L[3].v, sizeof(L[3].v), STRIP ? "%.0fKM" : "%.0f KM", r.orbit_km); /* 长条屏这块板窄,"22700 KN" 会顶到标签,省掉中间那个空格 */ snprintf(R[0].v, sizeof(R[0].v), (r.thrust_kn > 0) ? (STRIP ? "%.0fkN" : "%.0f KN") : "--", r.thrust_kn); snprintf(R[1].v, sizeof(R[1].v), (d->s1_isp > 0) ? "%.0f S" : "--", d->s1_isp); snprintf(R[2].v, sizeof(R[2].v), "%u", (unsigned)r.engines); snprintf(R[3].v, sizeof(R[3].v), (r.boosters > 0) ? "x%u" : "--", (unsigned)r.boosters); #if STRIP kv_grid(lx, by, pw, ph, L, C_CYAN_DIM, 0); kv_grid(rx, by2, pw, ph, R, C_GOLD_DIM, 0); #else const int rows[4] = { by + 21, by + 37, by + 53, by + 69 }; const uint16_t lvc[4] = { C_WHITE, C_TEXT, C_WHITE, C_TEXT }; const uint16_t rvc[4] = { C_WHITE, C_TEXT, C_TEXT, C_TEXT }; for (int i = 0; i < 4; i++) { kv_cell(lx + 8, lx + pw - 8, rows[i], L[i].l, L[i].v, C_CYAN_DIM, lvc[i]); kv_cell(rx + 8, rx + pw - 8, rows[i], R[i].l, R[i].v, C_GOLD_DIM, rvc[i]); } #endif /* 参数画出来的立面图 + 雷达底纹。可回收/有无整流罩这些标记画在图里,不再单列 */ disp_panel(ix, iy, iw, ih, 6, C_PANEL, C_CYAN_DIM); disp_radar(ix + iw / 2, iy + ih / 2, icr); const IconArt *ic = rocket_art(r, 1); int isc = 1; while (ic->w * (isc + 1) <= iw - 12 && ic->h * (isc + 1) <= ih - 6) isc++; disp_add_bitmap(ix + (iw - ic->w * isc) / 2, iy + (ih - ic->h * isc) / 2, ic->w, ic->h, ic->px, (uint8_t)isc); /* LAUNCH / STAGE / INFO 三页,KEY3 或点底部 TAB 循环 */ disp_panel_glow(qx, py, qw, bh, 6, C_CYAN_DIM); disp_panel(qx, py, qw, bh, 6, C_PANEL, C_CYAN); const int ry[4] = { py + 26, py + 26 + tp, py + 26 + 2 * tp, py + 26 + 3 * tp }; char tab[16]; snprintf(tab, sizeof(tab), "LAUNCH %u", (unsigned)d->event_total); const char *tabs[3] = { tab, "STAGE", "INFO" }; int tx = qx + 8; for (int i = 0; i < 3; i++) { bool on = (st.rocket_tab == i); int tw = disp_text_width(tabs[i], 16, 1); disp_text(tx, py + 4, tabs[i], 16, on ? C_GOLD : C_DIM, C_PANEL); if (on) disp_hline(tx, py + 22, tw - 1, C_GOLD); HIT(tx, py + 2, tw + 6, 24, UI_ACT_TAB, i); tx += tw + (STRIP ? 6 : 12); /* 带上任务数的 LAUNCH 最长约 100px,栏距再放大 INFO 就顶到右边框 */ } if (st.rocket_tab == 0) { if (!d->ev_count) { disp_text(qx + 8, ry[0], d->event_total ? "NO NEARBY LAUNCHES" : "NO UPCOMING LAUNCHES", 16, C_DIM, C_PANEL); return; } const int evn = STRIP ? MAX_ROCKET_EV : 3; /* 横屏那块面板纵向只放得下三行 */ for (int i = 0; i < d->ev_count && i < evn; i++) { /* 任务名是主角,占满左边;发射日期挪到行尾成一列,读起来还是"什么时候打什么" */ char ds[8]; snprintf(ds, sizeof(ds), "%.5s", (strlen(d->ev[i].date) >= 10) ? d->ev[i].date + 5 : d->ev[i].date); int dw = disp_text_width(ds, 16, 1); text_elided(qx + 8, ry[i], qw - 16 - dw - 8, d->ev[i].name, (i == 0) ? C_WHITE : C_TEXT, C_PANEL); text_right(qx + qw - 8, ry[i], ds, 16, C_CYAN_DIM, C_PANEL); } } else if (st.rocket_tab == 1) { const char *lab[3] = { "S1", "S2", "BST" }; char val[3][24]; snprintf(val[0], sizeof(val[0]), (d->s1_thrust_kn > 0) ? "%.0fKN ISP%.0f x%u" : "--", d->s1_thrust_kn, d->s1_isp, (unsigned)d->s1_engines); snprintf(val[1], sizeof(val[1]), (d->s2_thrust_kn > 0) ? "%.0fKN ISP%.0f x%u" : "--", d->s2_thrust_kn, d->s2_isp, (unsigned)d->s2_engines); if (r.boosters > 0 && d->booster_thrust_kn > 0) snprintf(val[2], sizeof(val[2]), "%.0fKN x%u", d->booster_thrust_kn, (unsigned)r.boosters); else strlcpy(val[2], "NONE", sizeof(val[2])); for (int i = 0; i < 3; i++) { disp_text(qx + 8, ry[i], lab[i], 16, C_CYAN_DIM, C_PANEL); #if STRIP /* "22700KN ISP311 x27" 右对齐会盖住 S1/S2 标签,改成省中间留尾巴 */ int lw2 = disp_text_width(lab[i], 16, 1); text_elided(qx + 16 + lw2, ry[i], qw - 24 - lw2, val[i], C_TEXT, C_PANEL); #else text_right(qx + qw - 8, ry[i], val[i], 16, C_TEXT, C_PANEL); #endif } } else { char name[56]; rocket_title(r, name, sizeof(name)); disp_text_clipped(qx + 8, ry[0], qw - 16, name, 16, C_WHITE, C_PANEL); if (!d->desc[0]) { disp_text(qx + 8, ry[1], "NO DESCRIPTION", 16, C_DIM, C_PANEL); return; } char desc[STRIP ? 136 : 96]; clip_chars(desc, sizeof(desc), d->desc, STRIP ? 30 : 23); disp_text_wrap(qx + 8, ry[1], qw - 16, desc, 16, C_TEXT, C_PANEL, STRIP ? 4 : 2); } } static void draw_error(const UiState &st) { const int px = 8, pw = CONT_W - 16, ph = STRIP ? (BOT_Y - TOP_Y + 1) : 168; const int py = STRIP ? TOP_Y : 32; disp_panel_glow(px, py, pw, ph, 10, C_RED); disp_panel(px, py, pw, ph, 10, C_PANEL, C_RED); disp_text_center(px, py + 10, pw, "FAULT", 32, C_RED, C_PANEL, 1); disp_text_wrap(px + 14, py + 56, pw - 28, st.message, 16, C_ORANGE, C_PANEL, STRIP ? 3 : 5); char msg[96]; snprintf(msg, sizeof(msg), "API %s", st.api); disp_text_clipped(px + 14, py + ph - 24, pw - 28, msg, 16, C_DIM, C_PANEL); } /* 设置页:模式页 KEY3 进来。只读地把"网络"和"后端"两件事摊开—— 改的地方仍然是配网门户(KEY2),这里不再做一套输入控件。 */ /* OTA 页:只有"要不要装"这一个决定,进度条复用同页,失败也停在这页显示原因 */ static void draw_update(const UiState &st) { const int px = 8, pw = CONT_W - 16, ph = STRIP ? (BOT_Y - TOP_Y + 1) : 176; const int py = STRIP ? TOP_Y : 22; const bool failed = (st.fw_progress == -2); const uint16_t edge = failed ? C_RED : C_GOLD; disp_panel_glow(px, py, pw, ph, 10, failed ? C_RED : C_GOLD_DIM); disp_panel(px, py, pw, ph, 10, C_PANEL, edge); disp_text_center(px, py + 10, pw, failed ? "UPDATE FAILED" : "UPDATE", 32, edge, C_PANEL, 1); char msg[80]; snprintf(msg, sizeof(msg), "FROM %s TO %s", st.fw_version, st.fw_new); disp_text_clipped(px + 10, py + (STRIP ? 48 : 52), pw - 20, msg, 16, C_CYAN, C_PANEL); if (st.fw_notes[0]) disp_text_wrap(px + 14, py + (STRIP ? 66 : 74), pw - 28, st.fw_notes, 16, C_TEXT, C_PANEL, 2); const int bx = px + 20, bw = pw - 40, by = py + (STRIP ? 104 : 126); if (st.fw_progress < 0) { disp_text_center(px, py + (STRIP ? 104 : (st.fw_notes[0] ? 100 : 90)), pw, failed ? TXT_PRESS_BACK : TXT_PRESS_INSTALL, 16, failed ? C_ORANGE : C_GREEN, C_PANEL); } else { disp_rect(bx, by, bw, 12, C_CYAN_DIM); int fill = (bw - 4) * st.fw_progress / 100; if (fill > 0) disp_fill(bx + 2, by + 2, fill, 8, C_GREEN); snprintf(msg, sizeof(msg), "%d%%", st.fw_progress); disp_text_center(px, by + (STRIP ? 18 : 20), pw, msg, 16, C_CYAN, C_PANEL); } if (st.fw_error[0]) disp_text_clipped(px + 14, py + ph - 22, pw - 28, st.fw_error, 16, C_RED, C_PANEL); } /* 设置页一行:左标签 +(可选)右对齐值。 长条屏一行塞不下两栏,右值落到标签下面一行整宽显示。 */ static void s_row(int ix, int ir, int y, const char *l, uint16_t lc, int lw, const char *r = nullptr, uint16_t rc = C_TEXT) { if (!r) { disp_text_clipped(ix, y, lw, l, 16, lc, C_PANEL); return; } /* 标签的预算还要给右对齐的值让路,否则长热点名会直接从底下压过值 */ int avail = ir - ix - disp_text_width(r, 16, 1) - 6; if (avail < 0) avail = 0; if (lw > avail) lw = avail; disp_text_clipped(ix, y, lw, l, 16, lc, C_PANEL); text_right(ir, y, r, 16, rc, C_PANEL); } #if STRIP /* 172 高放不下三张横卡:左网络右本机两张长卡,右端再留一竖列两个大按钮。 按钮列的定义排在下面 ui_glyph 之后(它要用图标)。 */ #define SET_BTN_W 104 /* 右列按钮宽:"POWER OFF" 九个字符放得下 */ #define SET_BTN_GAP 7 /* 两颗按钮之间的缝,也是按钮列和右栏之间的缝 */ /* 定义在下面:那节才有图标线稿 */ static void settings_actions(const UiState &st); static void draw_settings_strip(const UiState &st) { const int ch = BOT_Y - TOP_Y + 1; /* 两栏等宽:整宽减掉左右边距、右列按钮、两道缝 */ const int lw = (CONT_W - 8 - SET_BTN_W - 2 * SET_BTN_GAP) / 2; const int lx = 4, lix = 14, lir = lx + lw - 10; const int rx = lx + lw + SET_BTN_GAP, rw = lw, rix = rx + 10, rir = rx + rw - 10; char val[64], rv[32]; disp_panel_glow(lx, TOP_Y, lw, ch, 10, C_CYAN_DIM); disp_panel(lx, TOP_Y, lw, ch, 10, C_PANEL, C_CYAN); s_row(lix, lir, TOP_Y + 6, "WIFI", C_CYAN, 130, st.wifi_up ? "ONLINE" : "OFFLINE", st.wifi_up ? C_GREEN : C_RED); rv[0] = 0; if (st.wifi_up) snprintf(rv, sizeof(rv), "RSSI %d", st.rssi); s_row(lix, lir, TOP_Y + 28, st.ssid[0] ? st.ssid : "NO SSID SAVED", st.ssid[0] ? C_TEXT : C_DIM, 130, rv[0] ? rv : nullptr, C_CYAN_DIM); if (st.ip[0]) snprintf(val, sizeof(val), "IP %s", st.ip); else strlcpy(val, "IP --", sizeof(val)); s_row(lix, lir, TOP_Y + 50, val, st.ip[0] ? C_CYAN : C_DIM, 200); disp_hline(lix, TOP_Y + 72, lir - lix, C_TRACE); const char *link = st.api_fail ? "API FAIL" : (st.owner[0] ? "BOUND" : "NOT BOUND"); uint16_t link_c = st.api_fail ? C_RED : (st.owner[0] ? C_GREEN : C_ORANGE); s_row(lix, lir, TOP_Y + 80, "SERVER", C_GOLD, 100, link, link_c); disp_text_wrap(lix, TOP_Y + 100, lir - lix, st.api, 16, C_CYAN, C_PANEL, 2); disp_panel_glow(rx, TOP_Y, rw, ch, 10, C_GOLD_DIM); disp_panel(rx, TOP_Y, rw, ch, 10, C_PANEL, C_GOLD); s_row(rix, rir, TOP_Y + 6, "MODE", C_GOLD, 80, (st.mode < 0) ? "NOT CHOSEN" : (st.mode ? "LAUNCHER" : "CELESTIAL"), C_CYAN_DIM); snprintf(val, sizeof(val), "USER %s", st.owner[0] ? st.owner : "--"); s_row(rix, rir, TOP_Y + 28, val, st.owner[0] ? C_TEXT : C_DIM, 200); s_row(rix, rir, TOP_Y + 50, st.device_id, C_TEXT, 200); bool pending = ota_pending(); if (st.fw_version[0]) snprintf(rv, sizeof(rv), pending ? "%s PENDING" : "%s", st.fw_version); else snprintf(rv, sizeof(rv), pending ? "PENDING" : "--"); s_row(rix, rir, TOP_Y + 72, "FIRMWARE", C_GOLD, 100, rv, pending ? C_ORANGE : C_GOLD); s_row(rix, rir, TOP_Y + 94, "BOARD", C_GOLD, 100, BOARD_NAME, C_TEXT); clock_local(rv, sizeof(rv)); /* 服务器同步来的本地时间,没同步过时是 "--" */ s_row(rix, rir, TOP_Y + 116, "TIME", C_GOLD, 100, rv, C_TEXT); settings_actions(st); } #endif static void draw_settings(const UiState &st) { #if STRIP draw_settings_strip(st); return; #endif const int px = 8, pw = CONT_W - 16, ix = px + 12, ir = px + pw - 12; /* 三张等高卡:横屏 y=22/86/150,h=62 间距 2,正好铺到内容区下沿 212, 行距 18(行首 y = 卡顶 +6/+24/+42),16px 字模上下各留 2~4px。 */ const int ch = 62, gap = 2, rp = 18; const int c0 = TOP_Y, c1 = TOP_Y + ch + gap, c2 = TOP_Y + 2 * (ch + gap); char val[48], rv[32]; /* ---- WiFi ---- */ disp_panel_glow(px, c0, pw, ch, 10, C_CYAN_DIM); disp_panel(px, c0, pw, ch, 10, C_PANEL, C_CYAN); s_row(ix, ir, c0 + 6, "WIFI", C_CYAN, 190, st.wifi_up ? "ONLINE" : "OFFLINE", st.wifi_up ? C_GREEN : C_RED); /* 热点名要去配网时才需要,那一页第 1 步就写着,这里腾给 IP */ rv[0] = 0; if (st.wifi_up) snprintf(rv, sizeof(rv), "RSSI %d", st.rssi); s_row(ix, ir, c0 + 6 + rp, st.ssid[0] ? st.ssid : "NO SSID SAVED", st.ssid[0] ? C_TEXT : C_DIM, 190, rv[0] ? rv : nullptr, C_CYAN_DIM); if (st.ip[0]) snprintf(val, sizeof(val), "IP %s", st.ip); else strlcpy(val, "IP --", sizeof(val)); s_row(ix, ir, c0 + 6 + 2 * rp, val, st.ip[0] ? C_CYAN : C_DIM, 280); /* ---- 后端 ---- */ disp_panel_glow(px, c1, pw, ch, 10, C_GOLD_DIM); disp_panel(px, c1, pw, ch, 10, C_PANEL, C_GOLD); const char *link_st = st.api_fail ? "API FAIL" : (st.owner[0] ? "BOUND" : "NOT BOUND"); uint16_t link_c = st.api_fail ? C_RED : (st.owner[0] ? C_GREEN : C_ORANGE); s_row(ix, ir, c1 + 6, "SERVER", C_GOLD, 190, link_st, link_c); s_row(ix, ir, c1 + 6 + rp, st.api, C_CYAN, 280); snprintf(val, sizeof(val), "USER %s", st.owner[0] ? st.owner : "--"); s_row(ix, ir, c1 + 6 + 2 * rp, val, C_TEXT, 140, (st.mode < 0) ? "MODE NOT CHOSEN" : (st.mode ? "MODE LAUNCHER" : "MODE CELESTIAL"), C_CYAN_DIM); /* ---- 本机:设备号 / 板型 / 固件版本(后两项就是后端 terminal_devices 里那两个字段) ---- */ disp_panel_glow(px, c2, pw, ch, 10, C_CYAN_DIM); disp_panel(px, c2, pw, ch, 10, C_PANEL, C_CYAN); /* 升级写完了但还没画出首屏确认,版本行标成 PENDING,免得看着像没升上去 */ bool pending = ota_pending(); if (st.fw_version[0]) snprintf(rv, sizeof(rv), pending ? "FW %s PENDING" : "FW %s", st.fw_version); else snprintf(rv, sizeof(rv), pending ? "PENDING" : "FW --"); s_row(ix, ir, c2 + 6, "DEVICE", C_CYAN, 190, rv, pending ? C_ORANGE : C_GOLD); snprintf(val, sizeof(val), "DEV %s", st.device_id); const esp_partition_t *slot = esp_ota_get_running_partition(); s_row(ix, ir, c2 + 6 + rp, val, C_TEXT, 220, slot ? slot->label : "APP", C_CYAN_DIM); if (psramFound()) snprintf(rv, sizeof(rv), "PSRAM %uMB", (unsigned)(ESP.getPsramSize() / (1024 * 1024))); else snprintf(rv, sizeof(rv), "NO PSRAM"); s_row(ix, ir, c2 + 6 + 2 * rp, "BOARD " BOARD_NAME, C_TEXT, 200, rv, C_CYAN_DIM); } #if STRIP /* ---------------- 长条屏:状态栏右端的上下文按钮 ---------------- 这块板子上只有触摸:翻页靠上下滑或列表页右缘那两颗键,卡片和详情页的分页标签直接点, 剩下的页面级动作(返回/设置/配网/换码/重试/安装)满打满算两颗,画在状态栏右端。 屏一共 172 高,按钮画成 14x14 线稿图标 + 一个英文词:图标好认,英文比中文省一半宽度。 点它等价于按下 on_key_press 早就认识的那颗键,所以每一页的业务逻辑一行都不用改。 */ enum Glyph { G_BACK, G_GEAR, G_TUNE, G_REDO, G_DL, G_POWER, G_UP, G_DOWN }; struct HdrBtn { Glyph g; const char *label; uint16_t bits; }; #define GLYPH_SZ 14 /* 线稿图标的方框边长 */ #define HDR_PAD 7 /* 按钮左右各让出的留白 */ #define HDR_IV 4 /* 图标和英文标签之间的缝 */ #define HDR_GAP 8 /* 两颗按钮之间的缝(含热区不重叠的余量) */ #define HDR_BTN_H 24 /* 按钮面板高:16px 的文字上下各留 3px */ #define HDR_HIT_H 31 /* 热区盖住整条 header,但不吃到内容区 */ static int hdr_w(const char *label) { return 2 * HDR_PAD + GLYPH_SZ + HDR_IV + disp_text_width(label, 16, 1); } /* 按角度描弧:0° 在正右方,逆时针为正。逐度打点再往下补 1px 加粗,1px 的线在这块屏上太细 */ static void arc_px(int cx, int cy, int r, int a0, int a1, uint16_t c) { for (int a = a0; a <= a1; a++) { float rad = a * 0.0174533f; int px = cx + (int)lroundf(r * cosf(rad)); int py = cy - (int)lroundf(r * sinf(rad)); disp_pixel(px, py, c); disp_pixel(px, py + 1, c); } } static void ui_glyph(int x, int y, Glyph g, uint16_t c) { const int cx = x + 7, cy = y + 7; switch (g) { case G_BACK: /* 返回:朝左的尖角 */ for (int i = 0; i < 6; i++) { disp_fill(x + 7 - i, y + 1 + i, 2, 2, c); disp_fill(x + 2 + i, y + 6 + i, 2, 2, c); } break; case G_UP: case G_DOWN: /* 列表页上/下:人字形 */ for (int i = 0; i < 6; i++) { int yy = (g == G_UP) ? (y + 4 + i) : (y + 9 - i); disp_fill(x + 6 - i, yy, 2, 2, c); disp_fill(x + 6 + i, yy, 2, 2, c); } break; case G_GEAR: /* 设置:圆环 + 四齿 + 轴心 */ disp_ring(cx, cy, 4, c); disp_disc(cx, cy, 1, c); disp_fill(x + 6, y + 1, 2, 2, c); disp_fill(x + 6, y + 11, 2, 2, c); disp_fill(x + 1, y + 6, 2, 2, c); disp_fill(x + 11, y + 6, 2, 2, c); break; case G_TUNE: /* 配网门户:三条滑轨 + 错开的滑块 */ for (int i = 0; i < 3; i++) { int yy = y + 2 + 4 * i; disp_fill(x + 1, yy, 12, 1, c); disp_fill(x + (i == 0 ? 3 : (i == 1 ? 9 : 6)), yy - 1, 2, 3, c); } break; case G_REDO: /* 换码/重试:顶部缺口的圆环 + 两头箭头 */ arc_px(cx, cy, 5, 115, 425, c); for (int i = 0; i < 3; i++) { disp_fill(x + 2 + i, y + 3 - i, 1, 1 + 2 * i, c); disp_fill(x + 11 - i, y + 3 - i, 1, 1 + 2 * i, c); } break; case G_POWER: /* 关机:顶部缺口的圆环 + 中轴线 */ arc_px(cx, cy, 5, 115, 425, c); disp_fill(cx - 1, y, 2, 7, c); break; case G_DL: /* 安装:向下箭头 + 托盘 */ disp_fill(x + 6, y + 1, 2, 8, c); for (int i = 0; i < 4; i++) { disp_fill(x + 6 - i, y + 8 - i, 2, 2, c); disp_fill(x + 6 + i, y + 8 - i, 2, 2, c); } disp_fill(x + 2, y + 12, 10, 2, c); break; } } /* 设置页右列的两个大按钮:CONFIG 进配网门户(等价 on_key_press 的 KEY2), POWER OFF 断掉 SYS_EN 关机。 USB 插着时 VBUS 供着整板,关机关不掉,所以那时 POWER OFF 整颗压暗并且 **不登记热区**——点了没反应的东西不能还长得像能点(和列表页的 nav_rail 同一个原则)。 */ static void settings_actions(const UiState &st) { const int bw = SET_BTN_W; const int bh = (BOT_Y - TOP_Y + 1 - SET_BTN_GAP) / 2; const int bx = CONT_W - 4 - bw; const struct { Glyph g; const char *label; uint16_t bits; uint16_t c; bool en; } b[2] = { { G_TUNE, "CONFIG", XL_IO_KEY2, C_GOLD, true }, { G_POWER, "POWER OFF", UI_ACT_POWOFF, C_RED, !st.bat_chg }, }; for (int i = 0; i < 2; i++) { const int y = TOP_Y + i * (bh + SET_BTN_GAP); const uint16_t line = b[i].en ? b[i].c : C_TRACE; const uint16_t fg = b[i].en ? b[i].c : C_DIM; disp_panel(bx, y, bw, bh, 8, C_PANEL, line); const int tw = disp_text_width(b[i].label, 16, 1); /* 图标 14 + 缝 8 + 文字 16 = 38,在 67 高里上下各留 14 */ ui_glyph(bx + (bw - GLYPH_SZ) / 2, y + 14, b[i].g, fg); disp_text(bx + (bw - tw) / 2, y + 36, b[i].label, 16, fg, C_PANEL); if (b[i].en) HIT(bx, y, bw, bh, b[i].bits, -1); } } /* 每一页右上角放哪几颗,顺序 = 从右往左;语义照 on_key_press。 齿轮 SETUP 进的是只读的设置页,滑杆 CONFIG 直接进配网门户(改 WiFi、改后端地址都在那里)。 */ static int header_actions(const UiState &st, HdrBtn *b) { int n = 0; switch (st.screen) { case SC_MODE: b[n++] = { G_GEAR, "SETUP", XL_IO_KEY3 }; break; case SC_LIST: case SC_ROCKETS: case SC_PROVISION: b[n++] = { G_BACK, "BACK", XL_IO_KEY3 }; break; case SC_DETAIL: case SC_ROCKET: b[n++] = { G_BACK, "BACK", XL_IO_KEY2 }; break; case SC_CONNECTING: b[n++] = { G_TUNE, "CONFIG", XL_IO_KEY3 }; break; case SC_SETTINGS: /* CONFIG 在这页是右列的大按钮,header 只留返回 */ b[n++] = { G_BACK, "BACK", XL_IO_KEY3 }; break; case SC_PAIR: b[n++] = { G_REDO, "CODE", XL_IO_KEY3 }; b[n++] = { G_TUNE, "CONFIG", XL_IO_KEY2 }; break; case SC_ERROR: b[n++] = { G_REDO, "RETRY", XL_IO_KEY3 }; b[n++] = { G_TUNE, "CONFIG", XL_IO_KEY2 }; break; case SC_UPDATE: /* 下载已经阻塞在 loop 里,这期间按了也没用,别画出来骗人 */ if (st.fw_progress >= 0) break; b[n++] = { G_BACK, "BACK", XL_IO_KEY3 }; b[n++] = { (st.fw_progress == -2) ? G_REDO : G_DL, (st.fw_progress == -2) ? "RETRY" : "INSTALL", XL_IO_KEY2 }; break; default: break; } return n; } static void header_buttons(const HdrBtn *b, int n, uint8_t flash) { int x = CONT_W - 4; for (int i = 0; i < n; i++) { int w = hdr_w(b[i].label); x -= w; int slot = (b[i].bits == XL_IO_KEY2) ? 2 : 3; /* 这板上只用得上这两颗键 */ bool fl = (flash & (1 << slot)) != 0; uint16_t bg = fl ? C_GOLD : C_PANEL; disp_panel(x, 1, w, HDR_BTN_H, 4, bg, fl ? C_GOLD_LT : C_GOLD_DIM); ui_glyph(x + HDR_PAD, HDR_TY + 1, b[i].g, fl ? C_GOLD_DK : C_GOLD); disp_text(x + HDR_PAD + GLYPH_SZ + HDR_IV, HDR_TY, b[i].label, 16, fl ? C_GOLD_DK : C_GOLD, bg); HIT(x - 4, 0, w + 8, HDR_HIT_H, b[i].bits, -1); x -= HDR_GAP; } } /* 列表页右缘那一竖条:上/下两颗图标键,等价 KEY0/KEY1(和上下滑是同一个动作)。 卡片已经靠 RAIL_W 往左让过,不会压在按钮下面。 enabled=false(列表空着、或者总共就一页翻无可翻)时按钮照画但整组压暗, 并且**不登记热区**——点了没反应的东西不能还长得像能点。 */ static void nav_rail(uint8_t flash, bool enabled) { const int bw = RAIL_BTN_W, bh = 26; /* 贴右缘留 LIST_PAD,和卡片左边距、卡片与按钮之间的缝是同一个值 */ const int x = CONT_W - bw - LIST_PAD; const int mid = (TOP_Y + BOT_Y) / 2; const uint16_t key[2] = { XL_IO_KEY0, XL_IO_KEY1 }; const Glyph gl[2] = { G_UP, G_DOWN }; for (int i = 0; i < 2; i++) { int y = mid + (i ? 4 : -4 - bh); bool fl = enabled && (flash & (1 << i)) != 0; /* KEY0=bit0 KEY1=bit1 */ uint16_t bg = fl ? C_GOLD : C_PANEL; disp_panel(x, y, bw, bh, 5, bg, fl ? C_GOLD_LT : (enabled ? C_CYAN_DIM : C_TRACE)); ui_glyph(x + (bw - GLYPH_SZ) / 2, y + (bh - GLYPH_SZ) / 2, gl[i], fl ? C_GOLD_DK : (enabled ? C_CYAN : C_CYAN_DIM)); if (enabled) HIT(x - 6, y - 4, bw + 12, bh + 8, key[i], -1); } } #endif void ui_draw(const UiState &st) { disp_bg(); ui_hits_reset(); #if STRIP /* 右上角那几颗先量宽度:状态栏右端的用户名、详情页标题行右端的日期都要让开它 */ HdrBtn hb[2]; int nhb = header_actions(st, hb); int wrow = 0; for (int i = 0; i < nhb; i++) wrow += hdr_w(hb[i].label) + (i ? HDR_GAP : 0); s_info_r = CONT_W - 14 - (nhb ? wrow : 0); #endif const char *right = "COSMO"; if (st.screen == SC_LIST || st.screen == SC_DETAIL || st.screen == SC_ROCKETS || st.screen == SC_ROCKET || st.screen == SC_MODE || st.screen == SC_SETTINGS || st.screen == SC_UPDATE) right = st.owner; /* 详情页把 0..19 那一行让给自己的页头(标题 + 日期),状态栏不再画, 否则这块矮屏上会叠出两层 header;其它页照旧 */ const bool own_hdr = STRIP && (st.screen == SC_DETAIL || st.screen == SC_ROCKET); if (st.screen != SC_SPLASH && !own_hdr) status_bar(st, right); switch (st.screen) { case SC_SPLASH: draw_splash(st); break; case SC_PROVISION: draw_provision(st); break; case SC_CONNECTING: draw_connecting(st); break; case SC_PAIR: draw_pair(st); break; case SC_MODE: draw_mode(st); break; case SC_LIST: draw_list(st); break; case SC_DETAIL: draw_detail(st); break; case SC_ROCKETS: draw_rockets(st); break; case SC_ROCKET: draw_rocket(st); break; case SC_ERROR: draw_error(st); break; case SC_SETTINGS: draw_settings(st); break; case SC_UPDATE: draw_update(st); break; } const char *const *keys = KEYS_EMPTY; if (st.screen == SC_LIST) keys = KEYS_NAV; else if (st.screen == SC_DETAIL) keys = KEYS_DETAIL; else if (st.screen == SC_MODE) keys = KEYS_MODE; else if (st.screen == SC_ROCKETS) keys = KEYS_ROCKETS; else if (st.screen == SC_ROCKET) keys = KEYS_ROCKET; else if (st.screen == SC_PAIR) keys = KEYS_PAIR; else if (st.screen == SC_CONNECTING) keys = KEYS_NET; else if (st.screen == SC_ERROR) keys = KEYS_FAULT; else if (st.screen == SC_PROVISION) keys = KEYS_SETUP; else if (st.screen == SC_SETTINGS) keys = KEYS_SETTINGS; else if (st.screen == SC_UPDATE) keys = (st.fw_progress < 0) ? KEYS_UPDATE : KEYS_EMPTY; /* 下载中按了也没用,别画出来骗人 */ if (st.screen != SC_SPLASH) key_bar(keys, st.key_flash); #if STRIP if (st.screen == SC_LIST || st.screen == SC_ROCKETS) { const int cnt = (st.screen == SC_ROCKETS) ? (st.rsnap ? st.rsnap->count : 0) : (st.snap ? st.snap->count : 0); nav_rail(st.key_flash, cnt > LIST_ROWS); /* 空列表或不足一页:翻无可翻,整组禁用 */ } header_buttons(hb, nhb, st.key_flash); /* 画在页面之后:热区后登记的才压得住卡片 */ #endif /* 最后这层是操作反馈,得盖在按钮自己之上。全站只有这一种加载表达:请求在飞或立绘 还在补时,header 那条分隔线上有一截青色亮段横向流过(不再另开加载页)。 画在页面之后才压得住卡片;每一页都自己画 HDR_LINE,带头部标题的详情页也让得开。 亮段只在 header 线**正中**那 160px 区间里跑(区间本身跟页面无关,各页看到的 位置一致,也不会撞上状态栏左边的电量格和右边的用户名),出区间就整段消失再从头 进,是标准的不定长进度跑马。2px 高刚好压在内容区之上(HDR_LINE+1 < TOP_Y), 只比线本身粗 1px,读起来是"这条线在流动"而不是"线上盖了根进度条"; 相位取 millis(),重绘就自己在动。 */ if (st.busy) { const int span = 160; /* 居中跑马区的宽度 */ const int x0 = (CONT_W - span) / 2; const int tail = 72, head = 16, bw = tail + head; const int x = x0 - bw + (int)((millis() / 8) % (unsigned)(span + bw)); disp_fill(x, HDR_LINE, tail, 2, C_CYAN); disp_fill(x + tail, HDR_LINE, head, 2, C_WHITE); } disp_flush(); }