dsh-design-studio 1.5.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +6 -5
- package/README.md +7 -6
- package/THIRD_PARTY_NOTICES.md +108 -0
- package/assets/art/README.md +102 -0
- package/assets/art/brand-mark.webp +0 -0
- package/assets/art/check-clean.webp +0 -0
- package/assets/art/coach-markup.webp +0 -0
- package/assets/art/drop-file.webp +0 -0
- package/assets/art/empty-components.webp +0 -0
- package/assets/art/empty-data.webp +0 -0
- package/assets/art/empty-error.webp +0 -0
- package/assets/art/empty-frames.webp +0 -0
- package/assets/art/empty-history.webp +0 -0
- package/assets/art/empty-market.webp +0 -0
- package/assets/art/empty-notes.webp +0 -0
- package/assets/art/empty-search.webp +0 -0
- package/assets/art/empty-tokens.webp +0 -0
- package/assets/art/empty-works.webp +0 -0
- package/assets/art/guide-icon.webp +0 -0
- package/assets/art/kind-app.webp +0 -0
- package/assets/art/kind-desktop.webp +0 -0
- package/assets/art/kind-diagram.webp +0 -0
- package/assets/art/kind-dshplugin.webp +0 -0
- package/assets/art/kind-email.webp +0 -0
- package/assets/art/kind-embedded.webp +0 -0
- package/assets/art/kind-framed.webp +0 -0
- package/assets/art/kind-miniprogram.webp +0 -0
- package/assets/art/kind-poster.webp +0 -0
- package/assets/art/kind-slides.webp +0 -0
- package/assets/art/kind-tablet.webp +0 -0
- package/assets/art/kind-web.webp +0 -0
- package/assets/art/placeholder-inspire-img.webp +0 -0
- package/assets/art/wait-creating.webp +0 -0
- package/assets/demo.gif +0 -0
- package/assets/hero-sm.jpg +0 -0
- package/assets/motion/ai-capsule.html +124 -0
- package/assets/motion/ai-glow-input.html +112 -0
- package/assets/motion/balance-odometer.html +112 -0
- package/assets/motion/bottom-sheet.html +149 -0
- package/assets/motion/brightness-pill.html +114 -0
- package/assets/motion/comet-ring.html +95 -0
- package/assets/motion/copy-morph.html +116 -0
- package/assets/motion/cube-grid.html +103 -0
- package/assets/motion/day-night.html +120 -0
- package/assets/motion/dial-knob.html +130 -0
- package/assets/motion/dock-magnify.html +118 -0
- package/assets/motion/download-ring.html +135 -0
- package/assets/motion/expand-card.html +137 -0
- package/assets/motion/flip-card.html +100 -0
- package/assets/motion/hold-pay.html +137 -0
- package/assets/motion/holo-card.html +130 -0
- package/assets/motion/keycap.html +92 -0
- package/assets/motion/like-jelly.html +88 -0
- package/assets/motion/liquid-progress.html +113 -0
- package/assets/motion/liquid-segment.html +127 -0
- package/assets/motion/live-capsule.html +144 -0
- package/assets/motion/marker-highlight.html +94 -0
- package/assets/motion/marquee-logos.html +110 -0
- package/assets/motion/otp-code.html +111 -0
- package/assets/motion/password-eye.html +136 -0
- package/assets/motion/ruler-slider.html +140 -0
- package/assets/motion/search-expand.html +81 -0
- package/assets/motion/send-fly.html +121 -0
- package/assets/motion/skeleton-shine.html +124 -0
- package/assets/motion/star-rate.html +98 -0
- package/assets/motion/success-check.html +114 -0
- package/assets/motion/suggest-chips.html +134 -0
- package/assets/motion/swipe-row.html +126 -0
- package/assets/motion/tabbar-bounce.html +92 -0
- package/assets/motion/tactile-controls.html +89 -0
- package/assets/motion/text-scramble.html +173 -0
- package/assets/motion/toast-stack.html +115 -0
- package/assets/motion/token-stream.html +106 -0
- package/assets/motion/voice-orb.html +144 -0
- package/assets/showcase/alley-noodles-1.webp +0 -0
- package/assets/showcase/alley-noodles-2.webp +0 -0
- package/assets/showcase/alley-noodles-3.webp +0 -0
- package/assets/showcase/autumn-sale-1.webp +0 -0
- package/assets/showcase/bold-folio-1.webp +0 -0
- package/assets/showcase/bold-folio-2.webp +0 -0
- package/assets/showcase/book-club-1.webp +0 -0
- package/assets/showcase/book-club-2.webp +0 -0
- package/assets/showcase/book-club-3.webp +0 -0
- package/assets/showcase/flower-order-1.webp +0 -0
- package/assets/showcase/little-painter-1.webp +0 -0
- package/assets/showcase/little-painter-2.webp +0 -0
- package/assets/showcase/moon-fair-1.webp +0 -0
- package/assets/showcase/nail-booking-1.webp +0 -0
- package/assets/showcase/nail-booking-2.webp +0 -0
- package/assets/showcase/nail-booking-3.webp +0 -0
- package/assets/showcase/night-run-1.webp +0 -0
- package/assets/showcase/paw-diary-1.webp +0 -0
- package/assets/showcase/paw-diary-2.webp +0 -0
- package/assets/showcase/paw-diary-3.webp +0 -0
- package/assets/showcase/pixel-planet-1.webp +0 -0
- package/assets/showcase/pixel-planet-2.webp +0 -0
- package/assets/showcase/pixel-planet-3.webp +0 -0
- package/assets/showcase/pocket-ledger-1.webp +0 -0
- package/assets/showcase/pocket-ledger-2.webp +0 -0
- package/assets/showcase/shiftloom-1.webp +0 -0
- package/assets/showcase/shiftloom-2.webp +0 -0
- package/assets/showcase/slow-breath-1.webp +0 -0
- package/assets/showcase/slow-breath-2.webp +0 -0
- package/assets/showcase/slow-breath-3.webp +0 -0
- package/assets/showcase/slow-trip-1.webp +0 -0
- package/assets/showcase/slow-trip-2.webp +0 -0
- package/assets/showcase/slow-trip-3.webp +0 -0
- package/assets/showcase/slow-weekly-1.webp +0 -0
- package/assets/showcase/stay-confirm-1.webp +0 -0
- package/assets/showcase/stove-recipes-1.webp +0 -0
- package/assets/showcase/stove-recipes-2.webp +0 -0
- package/assets/showcase/strobewatch-1.webp +0 -0
- package/assets/showcase/strobewatch-2.webp +0 -0
- package/assets/showcase/tapeworks-1.webp +0 -0
- package/assets/showcase/tapeworks-2.webp +0 -0
- package/assets/showcase/tea-brand-pitch-1.webp +0 -0
- package/assets/showcase/tea-brand-pitch-2.webp +0 -0
- package/assets/showcase/tea-brand-pitch-3.webp +0 -0
- package/assets/showcase/time-bookshop-1.webp +0 -0
- package/assets/showcase/time-bookshop-2.webp +0 -0
- package/assets/showcase/water-journey-1.webp +0 -0
- package/assets/showcase/water-journey-2.webp +0 -0
- package/assets/showcase/water-journey-3.webp +0 -0
- package/assets/showcase/weekend-go-1.webp +0 -0
- package/assets/showcase/weekend-go-2.webp +0 -0
- package/assets/showcase/weekend-go-3.webp +0 -0
- package/assets/showcase/winter-soup-1.webp +0 -0
- package/assets/showcase/year-review-1.webp +0 -0
- package/assets/showcase/year-review-2.webp +0 -0
- package/assets/showcase/year-review-3.webp +0 -0
- package/lib/browser.js +3 -1
- package/lib/bundle.js +8 -3
- package/lib/canvthumb.js +9 -6
- package/lib/client.js +7428 -2624
- package/lib/components.js +4 -2
- package/lib/core.js +762 -132
- package/lib/design-page-settings.js +48 -0
- package/lib/design-scope.js +36 -0
- package/lib/design-transactions.js +259 -0
- package/lib/drop-folder.js +25 -0
- package/lib/edits.js +125 -8
- package/lib/embedded/lvgl_shot.c +133 -0
- package/lib/embedded/qml_shot.py +66 -0
- package/lib/embedded-shot.js +400 -0
- package/lib/embedded-trust.js +76 -0
- package/lib/fonts.js +30 -21
- package/lib/frames.js +23 -23
- package/lib/gallery/css.js +9 -2
- package/lib/gallery/market-routes.js +23 -7
- package/lib/gallery/pack.js +25 -8
- package/lib/gallery/policy.js +6 -4
- package/lib/gallery/routes.js +255 -83
- package/lib/gallery/submit.js +285 -57
- package/lib/gallery/use.js +13 -4
- package/lib/handoff-embedded.js +1182 -0
- package/lib/handoff.js +212 -71
- package/lib/history.js +393 -43
- package/lib/htmlpack.js +34 -13
- package/lib/impl.js +3 -0
- package/lib/index.js +661 -136
- package/lib/inspire.js +73 -26
- package/lib/kinds.js +11 -2
- package/lib/look.js +45 -25
- package/lib/mock.js +41 -4
- package/lib/motion.js +90 -0
- package/lib/page-settings.js +103 -0
- package/lib/picker.js +348 -70
- package/lib/rules.js +85 -0
- package/lib/serve.js +154 -15
- package/lib/showcase.json +22 -0
- package/lib/styles.js +16 -7
- package/lib/system.js +19 -8
- package/lib/tool.js +2 -1
- package/lib/tweaks.js +146 -9
- package/lib/works.js +151 -19
- package/locale/auto/en.json +1 -1
- package/locale/auto/zh.json +1 -1
- package/locale/en.json +1 -1
- package/locale/offline/en.json +1 -1
- package/locale/offline/zh.json +2 -2
- package/locale/zh.json +1 -1
- package/package.json +3 -2
- package/skills/ui-design/SKILL.md +56 -46
- package/skills/ui-design/frames/dsh/frame.json +1 -1
- package/skills/ui-design/references/app.md +29 -2
- package/skills/ui-design/references/components.md +1 -1
- package/skills/ui-design/references/desktop.md +1 -1
- package/skills/ui-design/references/dshplugin.md +12 -12
- package/skills/ui-design/references/embedded.md +40 -0
- package/skills/ui-design/references/frames.md +20 -20
- package/skills/ui-design/references/miniprogram.md +2 -2
- package/skills/ui-design/references/mock.md +16 -0
- package/skills/ui-design/references/poster.md +2 -1
- package/skills/ui-design/references/tweaks.md +17 -0
- package/skills/ui-design/tokens.css +19 -5
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 设计台:在电脑上把 LVGL 界面画成一张 BMP(compare_design 用,不进固件)。
|
|
3
|
+
* LVGL 8.x / 9.x 都能编:自己建一个显示、整屏渲染进内存,再存成 24 位 BMP。
|
|
4
|
+
*
|
|
5
|
+
* shot <宽> <高> <输出.bmp> <屏> [状态]
|
|
6
|
+
*
|
|
7
|
+
* 界面那边要有 ui_init() 和 ui_dev_show(屏, 状态)(HANDOFF.md 里约定的,写在 ui/tools/ui_dev.c)。
|
|
8
|
+
*/
|
|
9
|
+
#include <stdio.h>
|
|
10
|
+
#include <stdlib.h>
|
|
11
|
+
#include <string.h>
|
|
12
|
+
#include <stdint.h>
|
|
13
|
+
|
|
14
|
+
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
|
15
|
+
#include "lvgl.h"
|
|
16
|
+
#else
|
|
17
|
+
#include "lvgl/lvgl.h"
|
|
18
|
+
#endif
|
|
19
|
+
|
|
20
|
+
void ui_init(void);
|
|
21
|
+
void ui_dev_show(const char * screen, const char * state);
|
|
22
|
+
|
|
23
|
+
static int W, H;
|
|
24
|
+
static uint8_t * rgb; /* W×H×3,R G B */
|
|
25
|
+
static int bad_format = -1; /* 解不了的颜色格式(单色、索引色这些):不出图,说清楚 */
|
|
26
|
+
|
|
27
|
+
static void put(int x, int y, uint8_t r, uint8_t g, uint8_t b)
|
|
28
|
+
{
|
|
29
|
+
if(x < 0 || y < 0 || x >= W || y >= H) return;
|
|
30
|
+
uint8_t * p = rgb + ((size_t)y * W + x) * 3;
|
|
31
|
+
p[0] = r; p[1] = g; p[2] = b;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#if LVGL_VERSION_MAJOR >= 9
|
|
35
|
+
static void flush(lv_display_t * d, const lv_area_t * a, uint8_t * px)
|
|
36
|
+
{
|
|
37
|
+
lv_color_format_t cf = lv_display_get_color_format(d);
|
|
38
|
+
int32_t w = lv_area_get_width(a);
|
|
39
|
+
uint32_t stride = lv_draw_buf_width_to_stride(w, cf);
|
|
40
|
+
uint32_t size = lv_color_format_get_size(cf);
|
|
41
|
+
/* RGB565_SWAPPED(SPI 屏常用,高低字节换过):9.x 后来才有这个名字,按数值认,老版本也编得过 */
|
|
42
|
+
int swapped = (int)cf == 0x1B;
|
|
43
|
+
for(int32_t y = a->y1; y <= a->y2; y++) {
|
|
44
|
+
const uint8_t * row = px + (size_t)(y - a->y1) * stride;
|
|
45
|
+
for(int32_t x = a->x1; x <= a->x2; x++) {
|
|
46
|
+
const uint8_t * c = row + (size_t)(x - a->x1) * size;
|
|
47
|
+
if(cf == LV_COLOR_FORMAT_RGB565 || swapped) {
|
|
48
|
+
uint16_t v = swapped ? (uint16_t)((c[0] << 8) | c[1]) : (uint16_t)(c[0] | (c[1] << 8));
|
|
49
|
+
uint8_t r = (v >> 11) & 0x1F, g = (v >> 5) & 0x3F, b = v & 0x1F;
|
|
50
|
+
put(x, y, (uint8_t)((r * 527 + 23) >> 6), (uint8_t)((g * 259 + 33) >> 6), (uint8_t)((b * 527 + 23) >> 6));
|
|
51
|
+
}
|
|
52
|
+
else if(cf == LV_COLOR_FORMAT_RGB888 || cf == LV_COLOR_FORMAT_XRGB8888 || cf == LV_COLOR_FORMAT_ARGB8888) put(x, y, c[2], c[1], c[0]); /* LVGL 存的是 B G R (A) */
|
|
53
|
+
else if(cf == LV_COLOR_FORMAT_L8) put(x, y, c[0], c[0], c[0]);
|
|
54
|
+
else { bad_format = (int)cf; y = a->y2; break; }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
lv_display_flush_ready(d);
|
|
58
|
+
}
|
|
59
|
+
#else
|
|
60
|
+
static void flush(lv_disp_drv_t * drv, const lv_area_t * a, lv_color_t * px)
|
|
61
|
+
{
|
|
62
|
+
for(int32_t y = a->y1; y <= a->y2; y++) {
|
|
63
|
+
for(int32_t x = a->x1; x <= a->x2; x++) {
|
|
64
|
+
uint32_t c = lv_color_to32(*px++);
|
|
65
|
+
put(x, y, (uint8_t)(c >> 16), (uint8_t)(c >> 8), (uint8_t)c);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
lv_disp_flush_ready(drv);
|
|
69
|
+
}
|
|
70
|
+
#endif
|
|
71
|
+
|
|
72
|
+
static int save_bmp(const char * file)
|
|
73
|
+
{
|
|
74
|
+
FILE * f = fopen(file, "wb");
|
|
75
|
+
if(!f) return 0;
|
|
76
|
+
uint32_t row = (uint32_t)((W * 3 + 3) & ~3);
|
|
77
|
+
uint32_t data = row * (uint32_t)H, total = 54 + data;
|
|
78
|
+
uint8_t h[54] = { 'B', 'M' };
|
|
79
|
+
#define LE32(o, v) do { h[o] = (uint8_t)(v); h[o + 1] = (uint8_t)((v) >> 8); h[o + 2] = (uint8_t)((v) >> 16); h[o + 3] = (uint8_t)((v) >> 24); } while(0)
|
|
80
|
+
LE32(2, total); LE32(10, 54u); LE32(14, 40u); LE32(18, (uint32_t)W); LE32(22, (uint32_t)H);
|
|
81
|
+
h[26] = 1; h[28] = 24; LE32(34, data);
|
|
82
|
+
fwrite(h, 1, 54, f);
|
|
83
|
+
uint8_t * line = calloc(1, row);
|
|
84
|
+
for(int y = H - 1; y >= 0; y--) { /* BMP 从下往上存,一行 B G R */
|
|
85
|
+
const uint8_t * p = rgb + (size_t)y * W * 3;
|
|
86
|
+
for(int x = 0; x < W; x++) { line[x * 3] = p[x * 3 + 2]; line[x * 3 + 1] = p[x * 3 + 1]; line[x * 3 + 2] = p[x * 3]; }
|
|
87
|
+
fwrite(line, 1, row, f);
|
|
88
|
+
}
|
|
89
|
+
free(line);
|
|
90
|
+
return fclose(f) == 0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
int main(int argc, char ** argv)
|
|
94
|
+
{
|
|
95
|
+
if(argc < 5) { fprintf(stderr, "用法:shot 宽 高 输出.bmp 屏 [状态]\n"); return 2; }
|
|
96
|
+
W = atoi(argv[1]); H = atoi(argv[2]);
|
|
97
|
+
if(W <= 0 || H <= 0 || W > 4096 || H > 4096) { fprintf(stderr, "尺寸不对:%s×%s\n", argv[1], argv[2]); return 2; }
|
|
98
|
+
rgb = calloc((size_t)W * H, 3);
|
|
99
|
+
|
|
100
|
+
lv_init();
|
|
101
|
+
#if LVGL_VERSION_MAJOR >= 9
|
|
102
|
+
lv_display_t * d = lv_display_create(W, H);
|
|
103
|
+
lv_color_format_t cf = lv_display_get_color_format(d);
|
|
104
|
+
uint32_t bytes = lv_draw_buf_width_to_stride(W, cf) * (uint32_t)H;
|
|
105
|
+
void * buf = malloc(bytes + 64);
|
|
106
|
+
void * aligned = (void *)(((uintptr_t)buf + 63) & ~(uintptr_t)63);
|
|
107
|
+
lv_display_set_buffers(d, aligned, NULL, bytes, LV_DISPLAY_RENDER_MODE_FULL);
|
|
108
|
+
lv_display_set_flush_cb(d, flush);
|
|
109
|
+
#else
|
|
110
|
+
static lv_disp_draw_buf_t dbuf;
|
|
111
|
+
static lv_disp_drv_t drv;
|
|
112
|
+
lv_color_t * buf = malloc(sizeof(lv_color_t) * (size_t)W * H);
|
|
113
|
+
lv_disp_draw_buf_init(&dbuf, buf, NULL, (uint32_t)W * H);
|
|
114
|
+
lv_disp_drv_init(&drv);
|
|
115
|
+
drv.hor_res = (lv_coord_t)W;
|
|
116
|
+
drv.ver_res = (lv_coord_t)H;
|
|
117
|
+
drv.flush_cb = flush;
|
|
118
|
+
drv.draw_buf = &dbuf;
|
|
119
|
+
drv.full_refresh = 1;
|
|
120
|
+
lv_disp_drv_register(&drv);
|
|
121
|
+
#endif
|
|
122
|
+
|
|
123
|
+
ui_init();
|
|
124
|
+
ui_dev_show(argv[4], argc > 5 ? argv[5] : "");
|
|
125
|
+
/* 让切屏动画、定时器走完(按 10 毫秒一拍走 1.5 秒) */
|
|
126
|
+
for(int i = 0; i < 150; i++) { lv_tick_inc(10); lv_timer_handler(); }
|
|
127
|
+
lv_refr_now(NULL);
|
|
128
|
+
|
|
129
|
+
if(bad_format >= 0) { printf("DSH_UNSUPPORTED_FORMAT 0x%02X\n", bad_format); return 4; }
|
|
130
|
+
if(!save_bmp(argv[3])) { fprintf(stderr, "存不了图:%s\n", argv[3]); return 3; }
|
|
131
|
+
printf("DSH_SHOT_OK %dx%d\n", W, H);
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""设计台:在电脑上把 QML 界面截成一张 PNG(compare_design 用,不进工程)。
|
|
2
|
+
|
|
3
|
+
python qml_shot.py <Main.qml> <输出.png> <宽> <高> <屏> [状态]
|
|
4
|
+
|
|
5
|
+
离屏加载 Main.qml,调根对象的 devShow(屏, 状态)(HANDOFF.md 里约定的),等一会儿让动画走完,截根窗口存图后退出。
|
|
6
|
+
根对象没有 devShow 时退出码 4。
|
|
7
|
+
"""
|
|
8
|
+
import os
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
|
12
|
+
os.environ.setdefault("QT_QUICK_CONTROLS_STYLE", "Basic")
|
|
13
|
+
os.environ.setdefault("QT_QUICK_BACKEND", "software") # 没显示器 / 没 OpenGL 也能画
|
|
14
|
+
|
|
15
|
+
from PySide6.QtCore import QMetaObject, QTimer, QUrl, Q_ARG, Qt # noqa: E402
|
|
16
|
+
from PySide6.QtGui import QGuiApplication # noqa: E402
|
|
17
|
+
from PySide6.QtQml import QQmlApplicationEngine # noqa: E402
|
|
18
|
+
from PySide6.QtQuick import QQuickWindow # noqa: E402
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def main():
|
|
22
|
+
if len(sys.argv) < 6:
|
|
23
|
+
print("用法:qml_shot.py Main.qml 输出.png 宽 高 屏 [状态]", file=sys.stderr)
|
|
24
|
+
os._exit(2)
|
|
25
|
+
main_qml, out, w, h, screen = sys.argv[1], sys.argv[2], int(sys.argv[3]), int(sys.argv[4]), sys.argv[5]
|
|
26
|
+
state = sys.argv[6] if len(sys.argv) > 6 else ""
|
|
27
|
+
app = QGuiApplication([sys.argv[0]])
|
|
28
|
+
engine = QQmlApplicationEngine()
|
|
29
|
+
qml_dir = os.path.dirname(os.path.abspath(main_qml))
|
|
30
|
+
engine.addImportPath(qml_dir)
|
|
31
|
+
engine.addImportPath(os.path.dirname(qml_dir))
|
|
32
|
+
engine.load(QUrl.fromLocalFile(os.path.abspath(main_qml)))
|
|
33
|
+
roots = engine.rootObjects()
|
|
34
|
+
if not roots:
|
|
35
|
+
print("DSH_LOAD_FAILED", flush=True)
|
|
36
|
+
os._exit(3)
|
|
37
|
+
root = roots[0]
|
|
38
|
+
meta = root.metaObject()
|
|
39
|
+
if meta.indexOfMethod("devShow(QVariant,QVariant)") < 0:
|
|
40
|
+
print("DSH_NO_DEVSHOW", flush=True)
|
|
41
|
+
os._exit(4)
|
|
42
|
+
QMetaObject.invokeMethod(root, "devShow", Qt.DirectConnection, Q_ARG("QVariant", screen), Q_ARG("QVariant", state))
|
|
43
|
+
|
|
44
|
+
def shot():
|
|
45
|
+
win = root if isinstance(root, QQuickWindow) else None
|
|
46
|
+
if win is None:
|
|
47
|
+
wins = [x for x in QGuiApplication.topLevelWindows() if isinstance(x, QQuickWindow)]
|
|
48
|
+
win = wins[0] if wins else None
|
|
49
|
+
if win is None:
|
|
50
|
+
print("DSH_NO_WINDOW", flush=True)
|
|
51
|
+
os._exit(5)
|
|
52
|
+
img = win.grabWindow()
|
|
53
|
+
if img.width() != w or img.height() != h:
|
|
54
|
+
# 高分屏截出来是 2 倍:缩回设计尺寸(比对也会缩,这里先缩好存小一点)
|
|
55
|
+
img = img.scaled(w, h, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
|
|
56
|
+
if not img.save(out):
|
|
57
|
+
print("DSH_SAVE_FAILED", flush=True)
|
|
58
|
+
os._exit(6)
|
|
59
|
+
print("DSH_SHOT_OK %dx%d" % (img.width(), img.height()), flush=True)
|
|
60
|
+
os._exit(0)
|
|
61
|
+
|
|
62
|
+
QTimer.singleShot(1200, shot)
|
|
63
|
+
app.exec()
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
main()
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 嵌入式界面在电脑上出图(compare_design 用):
|
|
3
|
+
* LVGL:用电脑上的 C 编译器(gcc / clang)把工程里的 LVGL 源码 + ui/ + 插件带的出图程序编在一起,跑一次存一张 BMP;
|
|
4
|
+
* lv_conf.h 不直接用工程的(板子的内存地址、时钟、DMA2D、RTOS 在电脑上跑不了),只搬会影响画面的那些开关。
|
|
5
|
+
* LVGL 编一次缓存起来(系统临时目录),之后每次只编 ui/。
|
|
6
|
+
* QML:用 Python 的 PySide6 离屏加载 qml/Main.qml,调根对象的 devShow(屏, 状态),截图存 PNG。
|
|
7
|
+
* 屏和状态怎么切由工程自己提供入口(HANDOFF.md 约定):LVGL 的 ui_dev_show(屏, 状态),QML 的 devShow(屏, 状态)。
|
|
8
|
+
* 全程只用参数数组起子进程(不拼命令行),每一步都有超时。
|
|
9
|
+
*/
|
|
10
|
+
import fs from 'node:fs'
|
|
11
|
+
import os from 'node:os'
|
|
12
|
+
import path from 'node:path'
|
|
13
|
+
import { createHash } from 'node:crypto'
|
|
14
|
+
import { execFile, spawnSync } from 'node:child_process'
|
|
15
|
+
import { fileURLToPath } from 'node:url'
|
|
16
|
+
import { withProjectCopy } from './embedded-trust.js'
|
|
17
|
+
import { detectEmbeddedProject } from './handoff-embedded.js'
|
|
18
|
+
|
|
19
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
|
20
|
+
const HARNESS = path.join(HERE, 'embedded', 'lvgl_shot.c')
|
|
21
|
+
const QML_SHOT = path.join(HERE, 'embedded', 'qml_shot.py')
|
|
22
|
+
const CACHE = path.join(os.tmpdir(), 'dsh-design-embedded')
|
|
23
|
+
const HARNESS_VER = 1
|
|
24
|
+
const COMPILE_MS = 120000
|
|
25
|
+
const LINK_MS = 120000
|
|
26
|
+
const RUN_MS = 20000
|
|
27
|
+
const QML_MS = 30000
|
|
28
|
+
|
|
29
|
+
const sha1 = (s) => createHash('sha1').update(s).digest('hex')
|
|
30
|
+
const short = (s, n = 1800) => { const t = String(s || '').trim(); return t.length > n ? t.slice(0, n) + '\n…' : t }
|
|
31
|
+
|
|
32
|
+
/** 起一个子进程(参数数组,不经过 shell),超时就杀掉 → { code, stdout, stderr, timedOut } */
|
|
33
|
+
function run(bin, args, { cwd, timeout, env } = {}) {
|
|
34
|
+
return new Promise((resolve) => {
|
|
35
|
+
execFile(bin, args, { cwd, timeout, env, maxBuffer: 8 * 1024 * 1024, windowsHide: true, killSignal: 'SIGKILL' }, (err, stdout, stderr) => {
|
|
36
|
+
resolve({ code: err ? (typeof err.code === 'number' ? err.code : -1) : 0, stdout: String(stdout || ''), stderr: String(stderr || ''), timedOut: !!(err && err.killed), error: err && typeof err.code === 'string' ? err.code : '' })
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 一批任务最多并行 n 个 */
|
|
42
|
+
async function pool(items, n, fn) {
|
|
43
|
+
const out = new Array(items.length)
|
|
44
|
+
let i = 0
|
|
45
|
+
await Promise.all(Array.from({ length: Math.max(1, Math.min(n, items.length)) }, async () => {
|
|
46
|
+
while (i < items.length) { const k = i++; out[k] = await fn(items[k], k) }
|
|
47
|
+
}))
|
|
48
|
+
return out
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ───────────────────────── 编译器 ─────────────────────────
|
|
52
|
+
|
|
53
|
+
let ccCache
|
|
54
|
+
/** 电脑上的 C 编译器:CC 环境变量 → cc → clang → gcc(Windows 先 gcc)。MSVC 的 cl 不支持 */
|
|
55
|
+
export function findCompiler() {
|
|
56
|
+
if (ccCache !== undefined) return ccCache
|
|
57
|
+
const list = []
|
|
58
|
+
const env = String(process.env.CC || '').trim()
|
|
59
|
+
// CC 写的是完整路径(Windows 上常带空格,如 C:\Program Files\…\gcc.exe)就直接用;写成「ccache gcc」这种带参数的不认
|
|
60
|
+
if (env && (fs.existsSync(env) || !/\s/.test(env))) list.push(env)
|
|
61
|
+
list.push(...(process.platform === 'win32' ? ['gcc', 'clang', 'cc'] : ['cc', 'clang', 'gcc']))
|
|
62
|
+
ccCache = null
|
|
63
|
+
for (const bin of list) {
|
|
64
|
+
const r = spawnSync(bin, ['--version'], { timeout: 10000, encoding: 'utf8', windowsHide: true })
|
|
65
|
+
if (r.status === 0) { ccCache = { bin, version: String(r.stdout || '').split('\n')[0].trim() }; break }
|
|
66
|
+
}
|
|
67
|
+
return ccCache
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ───────────────────────── lv_conf.h ─────────────────────────
|
|
71
|
+
|
|
72
|
+
// 不搬的:内存、时钟、系统、日志、断言、缓存、硬件加速和显示 / 输入驱动、要外部库的(这些在电脑上编不过或跑不了)
|
|
73
|
+
const CONF_SKIP = new RegExp('^LV_(?:' + [
|
|
74
|
+
'MEM_\\w+', 'USE_STDLIB_MALLOC', 'USE_STDLIB_STRING', 'STDLIB_\\w+', 'TICK_\\w+', 'ATTRIBUTE_\\w+', 'USE_OS', 'OS_\\w+',
|
|
75
|
+
'USE_LOG', 'LOG_\\w+', 'USE_ASSERT_\\w+', 'ASSERT_\\w+', 'USE_PERF_MONITOR\\w*', 'PERF_\\w+', 'USE_MEM_MONITOR\\w*', 'USE_SYSMON', 'SYSMON_\\w+', 'USE_PROFILER\\w*', 'PROFILER_\\w+',
|
|
76
|
+
'USE_REFR_DEBUG', 'USE_LAYER_DEBUG', 'USE_PARALLEL_DRAW_DEBUG', 'USE_DRAW_SW', 'DRAW_SW_ASM\\w*', 'DRAW_SW_DRAW_UNIT_CNT', 'USE_DRAW_(?!SW_)\\w+', 'DRAW_(?:BUF|LAYER|THREAD|TRANSFORM|DMA2D|PXP|VGLITE|NEMA|G2D|DAVE|VG_LITE|OPENGLES|EVE)\\w*', 'LAYER_\\w+',
|
|
77
|
+
'USE_GPU\\w*', 'GPU_\\w+', 'USE_NEMA\\w*', 'NEMA\\w*', 'USE_DMA2D\\w*', 'DMA2D\\w*', 'USE_PXP\\w*', 'USE_VGLITE\\w*', 'VGLITE\\w*', 'USE_DAVE2D', 'USE_G2D\\w*', 'USE_SDL\\w*', 'SDL_\\w+', 'USE_X11', 'X11_\\w+', 'USE_WAYLAND', 'WAYLAND_\\w+',
|
|
78
|
+
'USE_LINUX_\\w+', 'LINUX_\\w+', 'USE_WINDOWS', 'WINDOWS_\\w+', 'USE_OPENGLES', 'USE_GLFW\\w*', 'USE_EGL\\w*', 'USE_EVDEV', 'USE_LIBINPUT', 'LIBINPUT_\\w+', 'USE_NUTTX\\w*', 'NUTTX_\\w+', 'USE_ST_LTDC', 'ST_LTDC_\\w+',
|
|
79
|
+
'USE_ST7\\w+', 'USE_ILI\\w+', 'USE_LCD_\\w+', 'USE_GENERIC_MIPI', 'USE_RENESAS\\w*', 'USE_TFT_ESPI', 'USE_FT81X', 'USE_NXP\\w*', 'USE_QNX', 'USE_UEFI', 'UEFI_\\w+', 'USE_ESP\\w*', 'USE_ANDROID\\w*', 'USE_DRM\\w*',
|
|
80
|
+
'USE_FS_\\w+', 'FS_\\w+', 'USE_FREETYPE', 'FREETYPE_\\w+', 'USE_THORVG\\w*', 'USE_VECTOR_GRAPHIC', 'USE_LOTTIE', 'USE_SVG\\w*', 'USE_RLOTTIE', 'USE_FFMPEG', 'FFMPEG_\\w+', 'USE_LIBPNG', 'USE_LIBJPEG\\w*', 'USE_LIBWEBP', 'USE_GSTREAMER',
|
|
81
|
+
'USE_LZ4_EXTERNAL', 'USE_TEST\\w*', 'USE_DEMO_\\w+', 'USE_GRIDNAV', 'USE_OBSERVER_DEBUG', 'BUILD_\\w+', 'USE_MONKEY', 'CACHE_\\w+', 'IMAGE_CACHE\\w*', 'IMG_CACHE\\w*', 'SHADOW_CACHE\\w*', 'CIRCLE_CACHE\\w*', 'GRAD_CACHE\\w*', 'GLOBAL_\\w+',
|
|
82
|
+
'ENABLE_GC', 'GC_\\w+', 'EXPORT_CONST_INT', 'BIG_ENDIAN_SYSTEM', 'STDINT_INCLUDE', 'STDDEF_INCLUDE', 'STDBOOL_INCLUDE', 'INTTYPES_INCLUDE', 'LIMITS_INCLUDE', 'STDARG_INCLUDE', 'DEF_REFR_PERIOD', 'DISP_DEF_REFR_PERIOD', 'INDEV_DEF_\\w+',
|
|
83
|
+
'USE_FONT_PLACEHOLDER', 'KCONFIG_\\w+', 'CONF_\\w+', 'USE_MATRIX', 'USE_FLOAT', 'USE_OBJ_ID\\w*', 'OBJ_ID_\\w+', 'USE_OBJ_PROPERTY\\w*', 'USE_SNAPSHOT', 'USE_FRAGMENT', 'USE_IMGFONT', 'USE_IME_PINYIN', 'IME_\\w+',
|
|
84
|
+
].join('|') + ')$')
|
|
85
|
+
|
|
86
|
+
/** 工程的 lv_conf.h → 电脑上编用的 lv_conf.h:只搬画面相关的开关(字体、控件、颜色深度、复杂绘制),其余用 LVGL 默认值 + 电脑上能跑的设置 */
|
|
87
|
+
export function desktopConf(confText, major) {
|
|
88
|
+
const text = String(confText || '').replace(/\/\*[\s\S]*?\*\/|\/\/[^\r\n]*/g, ' ').replace(/\\\r?\n/g, ' ')
|
|
89
|
+
const carried = new Map()
|
|
90
|
+
for (const [, name, value] of text.matchAll(/^[ \t]*#[ \t]*define[ \t]+(LV_\w+)(?![\w(])[ \t]*([^\r\n]*)$/gm)) {
|
|
91
|
+
if (carried.has(name) || CONF_SKIP.test(name)) continue
|
|
92
|
+
// 值里引用别的头文件、板子上的函数的不搬(#include 写在值里、或像 HAL_xxx() 这种调用)
|
|
93
|
+
const v = value.trim()
|
|
94
|
+
if (/#\s*include|\bHAL_|\b__attribute__|\b__section|\bxTask|\bosKernel/.test(v)) continue
|
|
95
|
+
// 指向别的头文件的(xxx_INCLUDE "board.h"):只留标准库的 <stdio.h> 这种
|
|
96
|
+
if (/_INCLUDE$/.test(name) && !/^<std\w*\.h>$/.test(v)) continue
|
|
97
|
+
carried.set(name, v)
|
|
98
|
+
}
|
|
99
|
+
// 函数形式的宏(LV_FONT_CUSTOM_DECLARE 这种不带括号参数,上面已收;带参数的不搬)
|
|
100
|
+
const lines = ['/* 设计台自动生成:电脑上出图专用,不进固件 */', '#ifndef LV_CONF_H', '#define LV_CONF_H', '#include <stdint.h>', '#include <stdlib.h>', '']
|
|
101
|
+
for (const [name, v] of carried) lines.push(`#define ${name} ${v}`.trimEnd())
|
|
102
|
+
lines.push('', '/* 电脑上能跑的设置 */')
|
|
103
|
+
if (major >= 9) {
|
|
104
|
+
lines.push('#define LV_USE_STDLIB_MALLOC LV_STDLIB_CLIB', '#define LV_USE_STDLIB_STRING LV_STDLIB_CLIB', '#define LV_USE_OS LV_OS_NONE',
|
|
105
|
+
'#define LV_USE_DRAW_SW 1', '#define LV_DRAW_SW_ASM LV_DRAW_SW_ASM_NONE', '#define LV_USE_LOG 0', '#define LV_USE_SYSMON 0', '#define LV_USE_PERF_MONITOR 0', '#define LV_USE_MEM_MONITOR 0')
|
|
106
|
+
} else {
|
|
107
|
+
lines.push('#define LV_MEM_CUSTOM 1', '#define LV_MEM_CUSTOM_INCLUDE <stdlib.h>', '#define LV_MEM_CUSTOM_ALLOC malloc', '#define LV_MEM_CUSTOM_FREE free', '#define LV_MEM_CUSTOM_REALLOC realloc',
|
|
108
|
+
'#define LV_TICK_CUSTOM 0', '#define LV_USE_LOG 0', '#define LV_USE_PERF_MONITOR 0', '#define LV_USE_MEM_MONITOR 0', '#define LV_USE_GPU_STM32_DMA2D 0')
|
|
109
|
+
}
|
|
110
|
+
if (!carried.has('LV_COLOR_DEPTH')) lines.push('#define LV_COLOR_DEPTH 16')
|
|
111
|
+
lines.push('', '#endif', '')
|
|
112
|
+
return lines.join('\n')
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* 工程的 lv_conf.h 交给 C 预处理器展开(-E -dM):#if / #else 按真的算,拿到最后生效的那些宏。
|
|
117
|
+
* 板子头文件(#include "stm32xxx.h")去掉再展开;LVGL 自己在引入 lv_conf.h 前定义的常量(LV_STDLIB_BUILTIN、LV_OS_NONE 这些)先补上,
|
|
118
|
+
* 不然 `#if LV_USE_OS == LV_OS_NONE` 这种判断会算错。展开不了(写法太怪)返回 null,退回直接读
|
|
119
|
+
*/
|
|
120
|
+
export async function resolvedConf(cc, confText, lvglDir) {
|
|
121
|
+
if (!cc || !String(confText || '').trim()) return null
|
|
122
|
+
const internal = ['include/lvgl/config/lv_conf_internal.h', 'src/lv_conf_internal.h'].map((f) => path.join(lvglDir, f)).find((f) => fs.existsSync(f))
|
|
123
|
+
let consts = ''
|
|
124
|
+
if (internal) {
|
|
125
|
+
const head = fs.readFileSync(internal, 'utf8').split(/#\s*include\s+"lv_conf\.h"/)[0]
|
|
126
|
+
consts = [...head.matchAll(/^[ \t]*#[ \t]*define[ \t]+(LV_\w+)[ \t]+(\(?-?(?:0x[0-9a-fA-F]+|\d+)[uUlL]*\)?)[ \t]*(?:\/[*/].*)?$/gm)].map((m) => `#define ${m[1]} ${m[2]}`).join('\n')
|
|
127
|
+
}
|
|
128
|
+
const body = String(confText).replace(/^[ \t]*#[ \t]*include[ \t]*[<"](?!std\w*\.h[>"])[^>"]*[>"].*$/gm, '/* 去掉的头文件 */')
|
|
129
|
+
const tmp = path.join(os.tmpdir(), `dsh-lvconf-${process.pid}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}.h`)
|
|
130
|
+
fs.writeFileSync(tmp, consts + '\n' + body + '\n')
|
|
131
|
+
try {
|
|
132
|
+
const r = await run(cc.bin, ['-E', '-dM', '-x', 'c', tmp], { timeout: 30000 })
|
|
133
|
+
if (r.code !== 0) return null
|
|
134
|
+
// 只要 lv_conf.h 自己定义的(LVGL 的常量不算)
|
|
135
|
+
const mine = new Set([...body.matchAll(/^[ \t]*#[ \t]*define[ \t]+(LV_\w+)/gm)].map((m) => m[1]))
|
|
136
|
+
return r.stdout.split(/\r?\n/).filter((l) => { const m = /^#define (LV_\w+)(?![\w(])/.exec(l); return m && mine.has(m[1]) }).join('\n')
|
|
137
|
+
} finally {
|
|
138
|
+
try { fs.rmSync(tmp, { force: true }) } catch {}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// ───────────────────────── LVGL ─────────────────────────
|
|
143
|
+
|
|
144
|
+
function walk(dir, { skip } = {}) {
|
|
145
|
+
const out = []
|
|
146
|
+
const stack = [dir]
|
|
147
|
+
while (stack.length) {
|
|
148
|
+
const d = stack.pop()
|
|
149
|
+
let list = []
|
|
150
|
+
try { list = fs.readdirSync(d, { withFileTypes: true }) } catch { continue }
|
|
151
|
+
for (const e of list) {
|
|
152
|
+
const p = path.join(d, e.name)
|
|
153
|
+
if (e.isDirectory()) { if (!e.name.startsWith('.') && !(skip && skip(p))) stack.push(p) }
|
|
154
|
+
else if (e.isFile()) out.push(p)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return out.sort()
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function prune() {
|
|
161
|
+
try {
|
|
162
|
+
const now = Date.now()
|
|
163
|
+
const dirs = fs.readdirSync(CACHE, { withFileTypes: true }).filter((e) => e.isDirectory())
|
|
164
|
+
.map((e) => { const p = path.join(CACHE, e.name); let t = 0; try { t = fs.statSync(p).mtimeMs } catch {} return { p, t, name: e.name } })
|
|
165
|
+
const lv = dirs.filter((d) => d.name.startsWith('lv-')).sort((a, b) => b.t - a.t)
|
|
166
|
+
for (const [i, d] of lv.entries()) if (i >= 6 || now - d.t > 14 * 86400e3) fs.rmSync(d.p, { recursive: true, force: true })
|
|
167
|
+
for (const d of dirs) if ((d.name.startsWith('ui-') || d.name.includes('.tmp-')) && now - d.t > 7 * 86400e3) fs.rmSync(d.p, { recursive: true, force: true })
|
|
168
|
+
} catch { /* 缓存清不掉不要紧 */ }
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const objName = (rel) => rel.replace(/[\\/]+/g, '__').replace(/[^\w.-]/g, '_').replace(/\.c$/i, '') + '.o'
|
|
172
|
+
const jobs = () => Math.max(1, Math.min(8, (os.availableParallelism ? os.availableParallelism() : os.cpus().length) || 2))
|
|
173
|
+
|
|
174
|
+
/** 编译出错时给模型看的那几行(去掉一长串 note) */
|
|
175
|
+
function compileError(file, r) {
|
|
176
|
+
if (r.timedOut) return `编译 ${file} 超时(${COMPILE_MS / 1000} 秒)`
|
|
177
|
+
const lines = (r.stderr || r.stdout).split(/\r?\n/).filter((l) => /error|错误/i.test(l) || /^\s+\|/.test(l) || /^\s*\d+\s*\|/.test(l)).slice(0, 24)
|
|
178
|
+
return `编译 ${file} 出错:\n${short(lines.join('\n') || r.stderr || r.stdout, 2400)}`
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** LVGL 库本身:编一次放缓存(lv-<键>/),键 = 库的位置和版本 + 生成的 lv_conf.h + 编译器 */
|
|
182
|
+
async function lvglObjects(cc, lvglDir, version, conf, sourceKey = lvglDir) {
|
|
183
|
+
const key = sha1(JSON.stringify({ sourceKey, version, conf, cc: cc.version, HARNESS_VER })).slice(0, 16)
|
|
184
|
+
const dir = path.join(CACHE, 'lv-' + key)
|
|
185
|
+
const inc = path.join(dir, 'inc')
|
|
186
|
+
const manifest = path.join(dir, 'objects.json')
|
|
187
|
+
if (fs.existsSync(manifest)) {
|
|
188
|
+
try { const objs = JSON.parse(fs.readFileSync(manifest, 'utf8')); fs.utimesSync(dir, new Date(), new Date()); return { objs, inc, built: false } } catch { /* 坏了就重编 */ }
|
|
189
|
+
}
|
|
190
|
+
const tmp = `${dir}.tmp-${process.pid}-${Date.now()}`
|
|
191
|
+
fs.mkdirSync(path.join(tmp, 'inc'), { recursive: true })
|
|
192
|
+
fs.writeFileSync(path.join(tmp, 'inc', 'lv_conf.h'), conf)
|
|
193
|
+
// ui 里写 #include "lvgl/lvgl.h"、库目录又不叫 lvgl 时:放一个转发头文件
|
|
194
|
+
if (path.basename(lvglDir) !== 'lvgl') {
|
|
195
|
+
fs.mkdirSync(path.join(tmp, 'inc', 'lvgl'), { recursive: true })
|
|
196
|
+
fs.writeFileSync(path.join(tmp, 'inc', 'lvgl', 'lvgl.h'), '#include <lvgl.h>\n')
|
|
197
|
+
}
|
|
198
|
+
const srcs = walk(path.join(lvglDir, 'src'), { skip: (p) => /[\\/](?:thorvg|nxp|renesas|nema_gfx|dma2d|vg_lite|espressif|arm2d|helium|neon)$/i.test(p) })
|
|
199
|
+
.filter((f) => /\.c$/i.test(f))
|
|
200
|
+
const flags = lvFlags(path.join(tmp, 'inc'), lvglDir, [])
|
|
201
|
+
let failed = null
|
|
202
|
+
const objs = await pool(srcs, jobs(), async (src) => {
|
|
203
|
+
if (failed) return null
|
|
204
|
+
const rel = path.relative(lvglDir, src)
|
|
205
|
+
const obj = path.join(tmp, objName(rel))
|
|
206
|
+
const r = await run(cc.bin, [...flags, '-c', src, '-o', obj], { timeout: COMPILE_MS })
|
|
207
|
+
if (r.code !== 0 && !failed) failed = compileError('lvgl/' + rel.split(path.sep).join('/'), r)
|
|
208
|
+
return obj
|
|
209
|
+
})
|
|
210
|
+
if (failed) { fs.rmSync(tmp, { recursive: true, force: true }); return { error: failed } }
|
|
211
|
+
const finalObjs = objs.map((o) => path.join(dir, path.basename(o)))
|
|
212
|
+
fs.writeFileSync(path.join(tmp, 'objects.json'), JSON.stringify(finalObjs))
|
|
213
|
+
try { fs.renameSync(tmp, dir) } catch {
|
|
214
|
+
// 别的进程先编好了:用它的
|
|
215
|
+
fs.rmSync(tmp, { recursive: true, force: true })
|
|
216
|
+
if (!fs.existsSync(manifest)) return { error: 'LVGL 编好了但放不进缓存目录' }
|
|
217
|
+
}
|
|
218
|
+
return { objs: JSON.parse(fs.readFileSync(manifest, 'utf8')), inc, built: true }
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function lvFlags(inc, lvglDir, uiIncs) {
|
|
222
|
+
return ['-std=gnu99', '-O1', '-w', '-DLV_CONF_INCLUDE_SIMPLE', '-DLV_LVGL_H_INCLUDE_SIMPLE',
|
|
223
|
+
'-I', inc, '-I', lvglDir, '-I', path.dirname(lvglDir), ...uiIncs.flatMap((d) => ['-I', d])]
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** gcc / clang 的响应文件:一行一个参数,带空格的用双引号包 */
|
|
227
|
+
const rspArg = (a) => '"' + String(a).replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"'
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* 编 + 跑 LVGL 出图
|
|
231
|
+
* @returns { file, ms, built } 或 { error }
|
|
232
|
+
*/
|
|
233
|
+
export async function renderLvgl({ dir, project, w, h, screen, state = '', out, sourceKey, workKey = dir }) {
|
|
234
|
+
const t0 = Date.now()
|
|
235
|
+
const cc = findCompiler()
|
|
236
|
+
if (!cc) return { error: '这台电脑上没找到 C 编译器(gcc / clang),在电脑上出不了 LVGL 的图。Mac 上让用户装 Xcode 命令行工具(xcode-select --install),Windows 上装 MSYS2 / MinGW 的 gcc,Linux 上装 gcc。装不了就请用户从模拟器或板子上截一张图,url 填那张图。' }
|
|
237
|
+
const uiDir = path.join(dir, 'ui')
|
|
238
|
+
if (!fs.statSync(uiDir, { throwIfNoEntry: false })?.isDirectory()) return { error: `${dir} 里没有 ui/ 目录:界面代码照 HANDOFF.md 放在 ui/ 下再比。` }
|
|
239
|
+
const lv = project.lvgl
|
|
240
|
+
const lvglDir = path.resolve(dir, lv.at === '.' ? '' : lv.at)
|
|
241
|
+
const confText = lv.conf ? fs.readFileSync(path.join(dir, lv.conf), 'utf8') : ''
|
|
242
|
+
const conf = { text: desktopConf(await resolvedConf(cc, confText, lvglDir) ?? confText, lv.major) }
|
|
243
|
+
fs.mkdirSync(CACHE, { recursive: true })
|
|
244
|
+
prune()
|
|
245
|
+
const lib = await lvglObjects(cc, lvglDir, `${lv.major}.${lv.minor}.${lv.patch ?? ''}`, conf.text, sourceKey)
|
|
246
|
+
if (lib.error) return { error: `${lib.error}\n(LVGL 库本身编不过:多半是工程的 lv_conf.h 里开了电脑上编不了的东西,或者编译器太老)` }
|
|
247
|
+
// ui/ 下的 .c:ui/tools/ 里只要 ui_dev.c(别的是模型自己写的出图程序,带 main)
|
|
248
|
+
const toolsDir = path.join(uiDir, 'tools')
|
|
249
|
+
const all = walk(uiDir)
|
|
250
|
+
const srcs = all.filter((f) => /\.c$/i.test(f) && (!f.startsWith(toolsDir + path.sep) || path.basename(f) === 'ui_dev.c'))
|
|
251
|
+
if (!srcs.some((f) => path.basename(f) === 'ui_dev.c' && f.startsWith(toolsDir + path.sep))) {
|
|
252
|
+
return { error: '没找到 ui/tools/ui_dev.c:照 HANDOFF.md 写一个只在电脑上用的切屏入口 `void ui_dev_show(const char *screen, const char *state)`(screen 是设计文件名去掉 .html,state 是状态名、没有就是空字符串),切到那一屏、那个状态,模拟数据也设好。' }
|
|
253
|
+
}
|
|
254
|
+
const uiIncs = [...new Set([uiDir, ...all.filter((f) => /\.h$/i.test(f)).map((f) => path.dirname(f))])]
|
|
255
|
+
const headers = sha1(all.filter((f) => /\.h$/i.test(f)).map((f) => f + '\0' + fs.readFileSync(f, 'utf8')).join('\0'))
|
|
256
|
+
const work = path.join(CACHE, 'ui-' + sha1(workKey).slice(0, 16))
|
|
257
|
+
fs.mkdirSync(work, { recursive: true })
|
|
258
|
+
const flags = lvFlags(lib.inc, lvglDir, uiIncs)
|
|
259
|
+
const used = new Set()
|
|
260
|
+
let failed = null
|
|
261
|
+
const objs = await pool([...srcs, HARNESS], jobs(), async (src) => {
|
|
262
|
+
const key = sha1([fs.readFileSync(src), headers, lib.inc, flags.join('\0')].join('\0')).slice(0, 20)
|
|
263
|
+
const obj = path.join(work, key + '.o')
|
|
264
|
+
used.add(path.basename(obj))
|
|
265
|
+
if (fs.existsSync(obj)) return obj
|
|
266
|
+
const tmp = obj + '.tmp-' + process.pid
|
|
267
|
+
const r = await run(cc.bin, [...flags, '-c', src, '-o', tmp], { timeout: COMPILE_MS, cwd: dir })
|
|
268
|
+
if (r.code !== 0) { if (!failed) failed = compileError(src === HARNESS ? '设计台的出图程序' : path.relative(dir, src).split(path.sep).join('/'), r); try { fs.rmSync(tmp, { force: true }) } catch {} return null }
|
|
269
|
+
fs.renameSync(tmp, obj)
|
|
270
|
+
return obj
|
|
271
|
+
})
|
|
272
|
+
// 旧的对象文件:一小时没用过才删(别的 DSH 进程可能正编着另一版)
|
|
273
|
+
for (const f of fs.readdirSync(work)) {
|
|
274
|
+
if (used.has(f)) { try { const t = new Date(); fs.utimesSync(path.join(work, f), t, t) } catch {} continue }
|
|
275
|
+
if (!/\.(o|rsp|exe)$|^shot-/.test(f)) continue
|
|
276
|
+
try { if (Date.now() - fs.statSync(path.join(work, f)).mtimeMs > 3600e3) fs.rmSync(path.join(work, f), { force: true }) } catch {}
|
|
277
|
+
}
|
|
278
|
+
if (failed) return { error: failed }
|
|
279
|
+
// 链接出的程序、响应文件每次自己一份(两个 DSH 同时比同一个工程也不会互相覆盖),跑完删掉
|
|
280
|
+
const tag = `${process.pid}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`
|
|
281
|
+
const bin = path.join(work, `shot-${tag}${process.platform === 'win32' ? '.exe' : ''}`)
|
|
282
|
+
const rsp = path.join(work, `shot-${tag}.rsp`)
|
|
283
|
+
try {
|
|
284
|
+
return await linkAndRun({ cc, lib, objs, bin, rsp, work, dir, w, h, out, screen, state, t0 })
|
|
285
|
+
} finally {
|
|
286
|
+
for (const f of [bin, rsp]) { try { fs.rmSync(f, { force: true }) } catch {} }
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async function linkAndRun({ cc, lib, objs, bin, rsp, work, dir, w, h, out, screen, state, t0 }) {
|
|
291
|
+
fs.writeFileSync(rsp, [...lib.objs, ...objs].map(rspArg).join('\n'))
|
|
292
|
+
const linked = await run(cc.bin, ['@' + rsp, '-o', bin, '-lm'], { timeout: LINK_MS, cwd: work })
|
|
293
|
+
if (linked.code !== 0) {
|
|
294
|
+
const msg = linked.stderr + linked.stdout
|
|
295
|
+
const missing = [...new Set([...msg.matchAll(/(?:undefined reference to|undefined symbol|Undefined symbols?[^\n]*\n\s*)[`'"]?_?(\w+)/g)].map((m) => m[1]))].slice(0, 8)
|
|
296
|
+
if (missing.includes('ui_dev_show')) return { error: '链接时找不到 ui_dev_show:照 HANDOFF.md 在 ui/tools/ui_dev.c 里实现 `void ui_dev_show(const char *screen, const char *state)`。' }
|
|
297
|
+
if (missing.includes('ui_init')) return { error: '链接时找不到 ui_init:ui/ 里要有 `void ui_init(void)`(建好所有屏、加载首屏)。' }
|
|
298
|
+
return { error: `链接出错${missing.length ? '(找不到:' + missing.join('、') + ')' : ''}:\n${short(msg, 1600)}\n(缺的多半是字库 / 图片的 .c 没放进 ui/、或者用了工程 lv_conf.h 里没开的 LVGL 功能)` }
|
|
299
|
+
}
|
|
300
|
+
fs.mkdirSync(path.dirname(out), { recursive: true })
|
|
301
|
+
try { fs.rmSync(out, { force: true }) } catch {}
|
|
302
|
+
const ran = await run(bin, [String(w), String(h), out, screen, state], { timeout: RUN_MS, cwd: dir })
|
|
303
|
+
if (ran.code !== 0 || !fs.existsSync(out)) {
|
|
304
|
+
if (ran.timedOut) return { error: `出图程序 ${RUN_MS / 1000} 秒没跑完,被停掉了:ui_init() / ui_dev_show() 里是不是有死循环、或者在等板子上的东西?` }
|
|
305
|
+
if (/DSH_UNSUPPORTED_FORMAT/.test(ran.stdout + ran.stderr)) return { error: `显示的颜色格式电脑上还解不了(${short((ran.stdout + ran.stderr).match(/DSH_UNSUPPORTED_FORMAT\s*(\S*)/)?.[1] || '', 40)}):单色 / 索引色屏请用户从模拟器或板子上截一张图,url 填图片路径。` }
|
|
306
|
+
return { error: `出图程序没跑成(退出码 ${ran.code}${ran.error ? ',' + ran.error : ''}):\n${short(ran.stderr + ran.stdout, 1200)}\n(多半是 ui_init() / ui_dev_show() 里访问了空指针,或者用到了板子上才有的东西)` }
|
|
307
|
+
}
|
|
308
|
+
return { file: out, ms: Date.now() - t0, built: lib.built }
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// ───────────────────────── QML ─────────────────────────
|
|
312
|
+
|
|
313
|
+
let pyCache
|
|
314
|
+
/** 装了 PySide6 的 Python:DSH_PYSIDE_PYTHON → python3 / python(Windows 先 py -3) */
|
|
315
|
+
export async function findPySide() {
|
|
316
|
+
if (pyCache !== undefined) return pyCache
|
|
317
|
+
const list = []
|
|
318
|
+
const env = String(process.env.DSH_PYSIDE_PYTHON || '').trim()
|
|
319
|
+
if (env) list.push([env])
|
|
320
|
+
list.push(...(process.platform === 'win32' ? [['py', '-3'], ['python'], ['python3']] : [['python3'], ['python']]))
|
|
321
|
+
pyCache = null
|
|
322
|
+
for (const [bin, ...pre] of list) {
|
|
323
|
+
const r = await run(bin, [...pre, '-c', 'import PySide6, sys; print(PySide6.__version__)'], { timeout: 20000, cwd: HERE })
|
|
324
|
+
if (r.code === 0) { pyCache = { bin, pre, version: r.stdout.trim() }; break }
|
|
325
|
+
}
|
|
326
|
+
return pyCache
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** qml/Main.qml(没有就找 qml/ 下的 main.qml,再找工程根上的) */
|
|
330
|
+
export function mainQml(dir) {
|
|
331
|
+
for (const rel of ['qml/Main.qml', 'qml/main.qml', 'Main.qml', 'main.qml']) {
|
|
332
|
+
const f = path.join(dir, rel)
|
|
333
|
+
if (fs.statSync(f, { throwIfNoEntry: false })?.isFile()) return f
|
|
334
|
+
}
|
|
335
|
+
return ''
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export async function renderQml({ dir, w, h, screen, state = '', out }) {
|
|
339
|
+
const t0 = Date.now()
|
|
340
|
+
const main = mainQml(dir)
|
|
341
|
+
if (!main) return { error: `${dir} 里没找到 qml/Main.qml:照 HANDOFF.md 把界面放在 qml/ 下再比。` }
|
|
342
|
+
const py = await findPySide()
|
|
343
|
+
if (!py) return { error: '这台电脑上的 Python 没装 PySide6,在电脑上出不了 QML 的图。先问用户能不能装(`python3 -m pip install PySide6`,几百 MB;也可以装在虚拟环境里,再把那个 python 的路径设到环境变量 DSH_PYSIDE_PYTHON)。不装就请用户从 Qt Creator / 板子上截一张图,url 填那张图。' }
|
|
344
|
+
fs.mkdirSync(path.dirname(out), { recursive: true })
|
|
345
|
+
try { fs.rmSync(out, { force: true }) } catch {}
|
|
346
|
+
// 软件渲染:没显示器 / 没 OpenGL 的 Linux 也能出图,也和没 GPU 的板子一致
|
|
347
|
+
const env = { ...process.env, QT_QPA_PLATFORM: 'offscreen', QT_QUICK_CONTROLS_STYLE: process.env.QT_QUICK_CONTROLS_STYLE || 'Basic', QT_QUICK_BACKEND: process.env.QT_QUICK_BACKEND || 'software', PYTHONDONTWRITEBYTECODE: '1' }
|
|
348
|
+
// 不加 -I:PySide6 装在用户目录(pip install --user)时要认用户包目录,和上面探测时一样
|
|
349
|
+
const r = await run(py.bin, [...py.pre, QML_SHOT, main, out, String(w), String(h), screen, state], { timeout: QML_MS, cwd: path.dirname(main), env })
|
|
350
|
+
const said = r.stdout + r.stderr
|
|
351
|
+
if (r.code === 4 || /DSH_NO_DEVSHOW/.test(said)) return { error: 'Main.qml 的根对象上没有 devShow:照 HANDOFF.md 在根窗口里加 `function devShow(screen, state) { … }`(screen 是设计文件名去掉 .html,state 是状态名、没有就是空字符串),切到那一屏、那个状态。' }
|
|
352
|
+
if (r.code !== 0 || !fs.existsSync(out)) {
|
|
353
|
+
if (r.timedOut) return { error: `QML ${QML_MS / 1000} 秒没出图,被停掉了:加载卡住了?\n${short(said, 1200)}` }
|
|
354
|
+
const hint = /is not installed|未安装/.test(said) ? '\n(插件出图是直接加载 qml/Main.qml 源码、不经过构建:自己的文件用相对目录导入,如 import "theme",单例写在那个目录的 qmldir 里;别用 qt_add_qml_module 的模块 URI 导入自己的文件)' : ''
|
|
355
|
+
return { error: `QML 没出成图(退出码 ${r.code}):\n${short(said.split(/\r?\n/).filter((l) => !/^qt\.\w+.*: (?:Warning|Info)/i.test(l)).join('\n'), 1800)}${hint}` }
|
|
356
|
+
}
|
|
357
|
+
return { file: out, ms: Date.now() - t0, warnings: short(said.split(/\r?\n/).filter((l) => /qrc:|file:|\.qml:\d+/.test(l)).slice(0, 8).join('\n'), 800) }
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// ───────────────────────── 入口 ─────────────────────────
|
|
361
|
+
|
|
362
|
+
/** 这个目录是不是嵌入式工程(交接的目标目录):LVGL / QML → { framework, project } */
|
|
363
|
+
export function embeddedTarget(dir) {
|
|
364
|
+
const st = fs.statSync(dir, { throwIfNoEntry: false })
|
|
365
|
+
if (!st?.isDirectory()) return null
|
|
366
|
+
const project = detectEmbeddedProject(dir)
|
|
367
|
+
if (project) return { framework: project.framework, project }
|
|
368
|
+
if (mainQml(dir)) return { framework: 'qml', project: { framework: 'qml' } }
|
|
369
|
+
return null
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* 在电脑上把工程的某一屏画出来 → { file, ms, note } 或 { error }
|
|
374
|
+
* out:图放哪(系统临时目录里),不往工程里写
|
|
375
|
+
*/
|
|
376
|
+
export const CONFIRM_RENDER = '需要你在设计台里确认后才能出图'
|
|
377
|
+
export async function renderEmbedded({ dir, w, h, screen, state = '', out }, { workspace, authorize } = {}) {
|
|
378
|
+
try {
|
|
379
|
+
return await withProjectCopy(dir, workspace, async project => {
|
|
380
|
+
const target = embeddedTarget(project.copy)
|
|
381
|
+
if (!target) return { error: `${dir} 不像 LVGL / QML 工程(没找到 LVGL 源码或 qml/Main.qml)。` }
|
|
382
|
+
const lv = target.framework === 'lvgl'
|
|
383
|
+
if (lv && !target.project.lvgl) return { error: '认不出这个工程的 LVGL 版本。' }
|
|
384
|
+
if (lv && (w > 4096 || h > 4096)) return { error: 'LVGL 出图上限为 4096×4096 像素。' }
|
|
385
|
+
const q = JSON.stringify
|
|
386
|
+
const args = [screen, state].map(x => q(x)).join(' ')
|
|
387
|
+
const cc = process.env.CC || (process.platform === 'win32' ? 'gcc' : 'cc')
|
|
388
|
+
const python = process.env.DSH_PYSIDE_PYTHON || (process.platform === 'win32' ? 'py -3' : 'python3')
|
|
389
|
+
const commands = lv ? [`${cc} -c <LVGL / UI / lvgl_shot.c>`, `${cc} @objects.rsp -o shot -lm`, `shot ${w} ${h} <BMP> ${args}`]
|
|
390
|
+
: [`${python} qml_shot.py ${q(path.relative(project.copy, mainQml(project.copy)))} <PNG> ${w} ${h} ${args}`]
|
|
391
|
+
const decision = await authorize?.(project, commands)
|
|
392
|
+
if (!decision?.allowed) return { error: CONFIRM_RENDER, ...decision }
|
|
393
|
+
const opts = { dir: project.copy, w, h, screen, state, out: out.replace(/\.(bmp|png)$/i, '') + (lv ? '.bmp' : '.png') }
|
|
394
|
+
return lv ? renderLvgl({ ...opts, project: target.project, workKey: project.dir,
|
|
395
|
+
sourceKey: [project.dir, project.fingerprint] }) : renderQml(opts)
|
|
396
|
+
})
|
|
397
|
+
} catch (e) { return { error: String(e.message || e) } }
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export const SHOT_DIR = path.join(CACHE, 'shots')
|