Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
296e220f20 | ||
|
|
e3ef359df4 | ||
|
|
be32efa806 | ||
|
|
8fde79c071 | ||
|
|
b4328b8be6 | ||
|
|
4149d203b0 | ||
|
|
264a0c74a6 | ||
|
|
190cf29aa5 | ||
|
|
d658fd459a | ||
|
|
b627f79dad | ||
|
|
c26d2cdbaa | ||
|
|
372cb6b7a0 | ||
|
|
68fb81fb13 | ||
|
|
733847a58c | ||
|
|
f594f60fdd | ||
|
|
e92fa9f349 | ||
|
|
fe4bca5a33 | ||
|
|
b58cdc42b6 | ||
|
|
21c1b7bcc1 | ||
|
|
144730fb3a | ||
|
|
ca898be299 | ||
|
|
511e7dfa44 | ||
|
|
6d1e2c6f8d | ||
|
|
a0d64c322a | ||
|
|
a666ed7c43 | ||
|
|
1f68665860 | ||
|
|
668a7e1ca5 | ||
|
|
bf9d70722c | ||
|
|
5d06e69a41 | ||
|
|
a3430d15e0 | ||
|
|
419c902a38 | ||
|
|
b1bb320b50 | ||
|
|
2d1d8f83b1 | ||
|
|
d991d57447 | ||
|
|
43d78de045 | ||
|
|
739fdeedf3 | ||
|
|
b7eda91ca7 | ||
|
|
763d80534c | ||
|
|
31fcd93607 | ||
|
|
df6a5f4343 | ||
|
|
32d0d26c5a | ||
|
|
afb6513e56 | ||
|
|
584fd32ebe |
@@ -8,8 +8,19 @@ dist/
|
||||
*.spec
|
||||
|
||||
# 发布 zip: 可由 src/package_release.py 重新生成, 只上传 Gitea Release
|
||||
HDMI-Tool/release/*.zip
|
||||
DLPilot/release/*.zip
|
||||
EDID-viewer/release/*.zip
|
||||
SerialMate/release/*.zip
|
||||
|
||||
# 源码模式运行时的配置写入(config.BASE_DIR=src/), 与 release/ 下入库的预置栏位区分
|
||||
DLPilot/src/pattern_slots.json
|
||||
# SerialMate 无预置栏位, 运行态配置(最近串口/通道等)一律不入库
|
||||
SerialMate/src/serial_mate.json
|
||||
SerialMate/**/serial_assistant.json
|
||||
SerialMate/release/serial_mate.json
|
||||
# 板型档案(board_profiles.json)是用户本机数据, 首次运行自动生成默认值
|
||||
SerialMate/src/board_profiles.json
|
||||
SerialMate/release/board_profiles.json
|
||||
|
||||
# ZCode 客户端本地会话数据(计划留档等), 非项目配置
|
||||
.zcode/
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
[submodule "gd32e230f8_firmware_merge_tool"]
|
||||
path = gd32e230f8_firmware_merge_tool
|
||||
url = https://gitea.hulk.wang/hulk/gd32e230f8_firmware_merge_tool.git
|
||||
@@ -0,0 +1,257 @@
|
||||
# AGENTS.md — DLPilot 工程档案(开发约束与进度)
|
||||
|
||||
> 人类文档 [README.md](README.md) 回答"这是什么、怎么用";本文记录"代码怎么组织、
|
||||
> 怎么构建发布、改动时哪些约束不能破坏",兼作本工具的进度记录。
|
||||
> 修改本目录代码前先读完本文。仓库整体的开发需求与进度管理见根目录 `agent.md`。
|
||||
|
||||
## 1. 项目定位
|
||||
|
||||
仓库 `HW-Debug-Tools` 是 LT8619C(HDMI→RGB888)→ DLPC3421 投影转接板的**调试上位机工具集**,
|
||||
上游主仓库(固件)为 `hulk/LT8619C_DLPC3421_HDMI`(同 Gitea 实例 `gitea.hulk.wang`),
|
||||
上游固件本机路径 `E:\Hulk-Coding\LT8619C_DLPC3421_HDMI`;工具仓库路径 `E:\Hulk-Coding\HW-Debug-Tools`。
|
||||
DLPilot 工作在两端:HDMI **源端**(PC 显卡侧,EDID/分辨率/图案)与**光机控制端**
|
||||
(RS485 → 板载 GD32E230 网关 → DLPC3421)。寄存器语义判读基线(0x606E 位交换 /
|
||||
0x606D 整组顺序)与光机协议规程都在上游仓库 `doc/architecture/` 与 `protocols.md`,不在本仓库。
|
||||
|
||||
## 2. 目录契约(重要)
|
||||
|
||||
```
|
||||
DLPilot/
|
||||
├── src/ 源代码区 —— 只有这里可以手改(logos/ 改图标源后重跑 make_ico.py)
|
||||
├── assets/ 生成资产区 —— gen_*.py 的产物(PNG 图案),可随时再生成,改动需提交
|
||||
├── release/ 产物区 —— 机器生成,禁止手改:DLPilot.exe、pattern_slots.json、
|
||||
│ bw/solid 图案(package_release.py 从 assets/ 平铺复制来,均入库)、
|
||||
│ *.zip(gitignore,只上传 Release)。release/ 本身=完整可直接运行的
|
||||
│ 发布文件夹(exe+附属平铺),内容与 zip 一致
|
||||
├── README.md 人类文档
|
||||
└── AGENTS.md 本文
|
||||
```
|
||||
|
||||
划分原则:**"人写的"在 src/,"生成的"按去向分 assets/(随包分发)与 release/(直接交付)**。
|
||||
新文件必须落对区域;不要在 src/ 外新建源码,不要手改 assets/ 下的 PNG(改生成脚本再跑)。
|
||||
|
||||
### 文件角色速查
|
||||
|
||||
| 文件 | 角色 |
|
||||
|---|---|
|
||||
| `src/hdmi_gui.py` | 入口: argparse 命令行分发(--dump/--edid-fields/--test-pattern/--dlpc-cmd/--seconds), GUI 委托 app_fluent |
|
||||
| `src/app_fluent.py` | PySide6-Fluent-Widgets 主界面: 双栏仪表盘(左 HDMI 源端五卡/右 光机五卡), 光强/定时快捷滑条 |
|
||||
| `src/display_win.py` | Win32 显示器枚举/分辨率切换/智能拓扑(纯 ctypes) |
|
||||
| `src/edid_parse.py` | EDID 1.4/CEA-861 解析(纯标准库, 上游 lt8619c_edid.c 以此为参考解码器) |
|
||||
| `src/patterns.py` | 测试图案全屏投屏窗口(tkinter, ESC 退出, 测试卡区域 1:1 居中) |
|
||||
| `src/config.py` | 运行目录定位(BASE_DIR)与 pattern_slots.json 读写(slots/area/serial 三键) |
|
||||
| `src/dlpc_rs485.py` | 光机 RS485 协议模块: 帧构造/增量解析/译码表/预设命令/串口线程(DLPC485) |
|
||||
| `src/selftest_rs485.py` | 光机协议自检(对照上游实测帧向量, 无硬件回归, 改协议代码后必跑) |
|
||||
| `src/selftest_theme.py` | 主题切换回归(离屏, swatch 底色/渲染像素/标题字号, 改样式后必跑) |
|
||||
| `src/selftest_log.py` | 收发日志上限与队列消费回归(离屏, 改 _dlpc_log/_poll_dlpc 后必跑) |
|
||||
| `src/build_exe.py` | PyInstaller 打包 → `release/DLPilot.exe`(onefile/noconsole, 内嵌图标+pyserial+PySide6-Fluent-Widgets) |
|
||||
| `src/package_release.py` | 复制图案到 release/(平铺) → `release/DLPilot-v<ver>-win64.zip`(校验栏位引用完整性; release/ 与 zip 内容一致) |
|
||||
| `src/publish_gitea.py` | 建/复用 Gitea Release 并上传 zip(tag 默认取 zip 文件名) |
|
||||
| `src/hdmi_source.ps1/.bat` | 独立 PowerShell 命令行工具(自包含,与 GUI 无代码共享) |
|
||||
| `src/gen_bw_patterns.py` | 生成 `assets/bw_*.png` ×5(640x360 黑白,需 Pillow) |
|
||||
| `src/gen_solid_colors.py` | 生成 `assets/solid_*.png` ×10(800x600 纯色,需 Pillow) |
|
||||
| `src/la_wave_analyzer*.py` | 逻辑分析仪 CSV 波形判读(2/3 通道,40MHz 像素时钟假设) |
|
||||
| `src/logos/make_ico.py` | svg/png → ico(写在其自身目录) |
|
||||
| `release/pattern_slots.json` | 预置栏位:西门子星/波带片/综合测试卡,area=640x360;`serial` 键记忆光机串口 |
|
||||
| `UI参考布局.svg/.png` | 界面布局设计稿(app_fluent.py 双栏布局的规格来源, 随分支入库) |
|
||||
|
||||
## 3. 代码不变量(改 hdmi_gui.py 必须维持)
|
||||
|
||||
1. **依赖分层**:CLI/显示/EDID/协议/配置模块(display_win/edid_parse/config/
|
||||
dlpc_rs485)纯标准库;PySide6-Fluent-Widgets 是 GUI(app_fluent)的**硬依赖**(装了
|
||||
才能开界面,CLI 不受影响),GUI 图案窗口使用 Qt,CLI 图案窗口由 patterns.py 使用 tkinter 创建。可选依赖
|
||||
仍走"try-import + HAS_* 标志 + 缺失降级"模式:Pillow、pyserial——缺失时对应功能
|
||||
禁用/提示安装,其余功能必须照常工作。
|
||||
2. **模块边界**:hdmi_gui.py 只是入口, 不放实现; GUI 的显示器/EDID 访问走 display_win/edid_parse;ctypes 仅用于
|
||||
单实例锁、Windows 标题栏与 frozen DLL 加载; pyserial 只准在 dlpc_rs485.py 里 import
|
||||
(hdmi_gui/app_fluent 经 `dlpc_rs485.HAS_SERIAL` 与 `DLPC485` 类间接使用)。
|
||||
3. **BASE_DIR 语义**(定义在 config.py):frozen(PyInstaller onefile)时
|
||||
`BASE_DIR=exe 所在目录`(`sys.executable`),源码运行时 `=config.py 所在目录`
|
||||
(即 src/)。所有用户数据(pattern_slots.json、自定义图片)都写/读自 BASE_DIR
|
||||
**平铺**存放,不建子目录。
|
||||
4. **自定义栏位 `file` 字段是裸文件名**:加载时 `os.path.join(BASE_DIR, file)` 解析,
|
||||
因此 pattern_slots.json 引用的图片必须与 exe 同目录 —— package_release.py 正是按此平铺打包。
|
||||
5. **exe 自包含**:图标经 `--add-data` 内嵌(运行时从 `_MEIPASS` 读);内置五种图案
|
||||
(红/绿/蓝/棋盘格/网格线)由程序绘制,运行时**不依赖** assets/;solid/bw PNG 只服务自定义栏位。
|
||||
6. **DPI 感知**:进程启动即 `SetProcessDpiAwareness(2)`,图案窗口按物理像素定位,勿移除。
|
||||
7. **智能显示拓扑(勿改回无条件扩展)**:启动时枚举"接入但不在桌面"的显示器,仅当其
|
||||
EDID 厂商字节为转接板签名 `61 93`(压缩码 "XLS",上游 lt8619c_edid.c)时才
|
||||
`SetDisplayConfig(SDC_TOPOLOGY_EXTEND|SDC_APPLY)` 拉回桌面,静默容错。动机:板卡
|
||||
热插拔后 Windows 可能停留在"仅电脑屏幕"导致枚举不到板卡。用户主动选择的拓扑
|
||||
(家里的"仅第二屏幕"等,未激活的是笔记本内屏,厂商非 XLS)一律不动。
|
||||
8. **分辨率切换是临时的**:走 `CHANGEDISPLAYSETTINGS`(不写注册表),"恢复"用会话开始时快照。
|
||||
9. **EDID 来源是注册表**(`HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\...\Device Parameters\EDID`),
|
||||
不是 WMI/DDC;exe 的 noconsole 版无 stdout,`--dump/--edid-fields` 只在源码/控制台版可用。
|
||||
10. **光机串口线程回调不直接碰 GUI**:DLPC485 的 on_event/on_status 在后台线程触发,
|
||||
必须经 `queue.Queue` + Qt 定时器轮询投递回主线程(现行 `_poll_dlpc` 模式,
|
||||
与 I2C-Inject 的 Injector 同源);退出路径(关窗与 `--seconds` 自动关)都会走到
|
||||
`App.closeEvent()`,在那里 `dlpc.close()` 收线程。
|
||||
11. **pattern_slots.json 格式**:`{'area', 'slots', 'serial'}` 三键共存;load 兼容旧版
|
||||
纯数组(无 area)与无 serial 键两种历史格式,save 永远写全三键。`serial` 子键为
|
||||
`{port, baud, bytesize(8/7/6/5), parity(N/E/O), stopbits(1/2)}`,旧配置缺子键按
|
||||
默认 8-N-1 补齐。
|
||||
12. **GUI = app_fluent.py 双栏仪表盘**(规格:`DLPilot/UI参考布局.svg`):左列 HDMI 源端
|
||||
五卡(显示器/模式/EDID 信息/测试图案/hex),右列光机五卡(串口/数据/电源/命令/滑条),
|
||||
支持的模式和 EDID 信息默认折叠;顶栏 Dark/Light/System 切换。Light/Dark 同时更新
|
||||
Fluent 主题、Qt 调色板、容器样式与 Windows DWM 标题栏,勿只调用 setTheme。
|
||||
**fluent 控件的自定义样式禁止直接 setStyleSheet**:setTheme 会用库自带 qss 重刷全部
|
||||
已注册控件,直写样式随之丢失(v0.4.0 swatch 丢底色的根因)。须走
|
||||
`setCustomStyleSheet(控件, lightQss, darkQss)`(qss 需覆盖 hover/pressed/disabled 态,
|
||||
否则悬停瞬间被自带态样式盖回);仅 PushButton 等无 themeChanged 钩子的控件可幸存。
|
||||
FluentLabelBase 系(StrongBodyLabel 等)例外:其 setTextColor 在每次切主题时整体重写
|
||||
自定义槽,任何 setCustomStyleSheet 都会被冲掉——字号等改用 QFont(自带 label.qss 无
|
||||
font-size 规则,QFont 不会被冲)。RGB swatch 底色回归测试见 selftest_theme.py。
|
||||
PD 协议成功显示绿色,FPDO 仍独立判定。打包必须收集 `qfluentwidgets` 资源,并加入 Windows 系统 `icuuc.dll`,否则 QtCore 可能被其它 ICU DLL 解析失败。
|
||||
|
||||
## 4. 领域语义(测试值都有含义,勿"顺手改")
|
||||
|
||||
- 纯色值 55/AA/FF:55(01010101) 与 AA(10101010) 互为字节镜像对(检出位序颠倒/位交换),
|
||||
FF(11111111) 全高基准;R/G/B 三行对应 RGB888 三字节组(R=D[23:16]/G=D[15:8]/B=D[7:0])。
|
||||
- 800x600@60:LT8619C **demo 板** shadow EDID 首选时序(solid 系列分辨率与之一致)。
|
||||
- 640x360:测试卡区域默认值(16:9 半分辨率,点对点检查用);full=铺满所选屏。
|
||||
**同时是转接板光机 DLPC3421 的 nHD 面板原生分辨率**(该板 shadow EDID 只声明 640x360@60),
|
||||
投 640x360 图案 + RS485 开光机 = 整链路 1:1 验证。
|
||||
- bw 系列图案各自目的见 `src/gen_bw_patterns.py` 顶部清单注释。
|
||||
- 光机 RS485 命令集(M730/M731/M732/M201/M202/M737/M999/M888/M7/M8/M1/**M303/M304**)语义、
|
||||
帧格式 `D5 01 LEN <ASCII> CRC`(累加和校验)、错误码与**就绪门禁**
|
||||
(DLPC 未就绪时 M730/M731/M732 被拒回 0xFF)以上游 `protocols.md` 为唯一权威,
|
||||
本仓不维护协议文档副本;注意 **M7S0 是"开启"TEC 自动控温**(方向反直觉)、
|
||||
M737 在定时投光中延迟应答(CLI 等待上限 35s)。
|
||||
- **M303/M304/M305 载荷是二进制例外**(SQ52205 电源实测):成功载荷为大端原始值,
|
||||
**不是 ASCII**——Frame.payload 解出来是乱码,必须走 `payload_bytes()` 取原始字节;
|
||||
M303=u16 mV(12V 轨窗口 11400~12600),M304=s16 补码 mA(正=正向,固件原样上总线,
|
||||
上位机按有符号解析,FF 06=−250),**M305=u32 mW(LEN=4,勿复用双字节解析;
|
||||
恒非负,量程 0~295000,能量方向看 M304 符号;显示 mW→W 两位小数)**。
|
||||
封装在 `payload_u16_be/payload_s16_be/payload_u32_be/format_power`,
|
||||
回归向量在 selftest_rs485.py(M303/M304 真机帧,M305 算法推演帧)。
|
||||
- **电源自检序列**(M301 协议→M302 挡位最大电流→M303 实测母线电压,帧驱动状态机
|
||||
`_pd_on_frame/_pd_seq`,超时 3s/步):FPDO 判定 = 电压就近挡(标准 PD 固定挡
|
||||
5/9/12/15/20/28V,±5% 容差)+ M302 挡位电流;**12V 且 ≥3A 绿底,挡位不符红底,
|
||||
无匹配挡 ERR**。应答按 TYPE=0xF0 判成功;
|
||||
CH224Q 电压配置寄存器(0x0A)只写不可读,挡位只能实测判定。
|
||||
- **功率检测** = M303+M304+M305 序列 → 读数框 电压V / 电流mA / 功率W(M305 u32 mW
|
||||
换算两位小数);各步载荷长度按 kind 校验(2/2/4 字节),坏帧中止显示 ERR。
|
||||
|
||||
## 5. 构建 / 发布流水线(全部在 src/ 下执行)
|
||||
|
||||
```powershell
|
||||
python gen_bw_patterns.py ; python gen_solid_colors.py # 仅当改了图案生成逻辑
|
||||
python build_exe.py # → ../release/DLPilot.exe(缺 PyInstaller 会自动 pip install)
|
||||
python build_exe.py --debug # 附加带控制台的 DLPilot-console.exe(调试 --dump 用)
|
||||
python package_release.py <版本> # → ../release/DLPilot-v<版本>-win64.zip
|
||||
python publish_gitea.py ../release/DLPilot-v<版本>-win64.zip --replace --insecure # 上传(需 GITEA_TOKEN)
|
||||
```
|
||||
|
||||
发布约定:
|
||||
- tag/release 命名 `DLPilot-vX.Y.Z`,zip 命名 `DLPilot-vX.Y.Z-win64.zip`(publish_gitea.py
|
||||
依赖此命名从文件名推 tag);
|
||||
- **exe、pattern_slots.json 与 release/ 下平铺的图案 png 改动跟随源码/资产生成提交入库;
|
||||
zip 永不入库**(.gitignore 已挡);
|
||||
- publish_gitea.py 幂等:release 已存在则复用,同名资产默认跳过,`--replace` 删旧重传;
|
||||
- token 读环境变量 `GITEA_TOKEN`:本机已用 setx 持久化为用户级变量(新开的会话/终端自动
|
||||
继承,值不入库;在 setx 之前启动的进程读不到,需重开终端),急用时也可临时传 `--token`;
|
||||
- Gitea 实例 `gitea.hulk.wang`,API 走 https(443),git 走 ssh(1234)——从 origin 远程自动解析;
|
||||
python urllib 连该实例会在部分请求上报 `SSL: UNEXPECTED_EOF`,**实际发布需加 `--insecure`**;
|
||||
- 本实例 Gitea 的 API 兼容性怪癖:`GET /releases/tags/{tag}` 返回的 `assets` 是纯数组,
|
||||
而 `GET /releases/{id}` 是 `{items:[...]}` —— publish_gitea.py 已按两种形状兼容,勿"简化"回去。
|
||||
|
||||
## 6. 已知坑(历史踩过,勿重蹈)
|
||||
|
||||
- onefile 运行时 `__file__` 指向临时解压目录 `_MEIPASS`,定位 exe 必须用 `sys.executable`(§3.3);
|
||||
- 重新打包前旧 exe 可能被残留进程占用 → build_exe.py 会 taskkill 同名进程,手改打包脚本时保留;
|
||||
- 打包后本机图标缓存不刷新:`ie4uinit -show`,不是产物问题;
|
||||
- 改图标流程:改 svg → `make_ico.py` 生成 ico → 重新打包(ico 同时是文件图标与运行时窗口图标);
|
||||
- GUI 与 hdmi_source.ps1 各自独立实现显示器枚举,行为可能微差(GUI 与 `-List` 序号一致,
|
||||
但与"设置"面板序号无保证);多屏操作前先确认序号;
|
||||
- `pattern_slots.json` 兼容两种历史格式,写出只写新格式(详见 §3.11);
|
||||
- `--seconds` 冒烟在已有 DLPilot 实例(含用户开着的 exe)运行时会"挂起":run_gui
|
||||
检测到单实例互斥后弹模态框等点击。无头验证改用直启 `App(5)` 的等效脚本,或先关实例;
|
||||
重打包同理——build_exe.py 会 taskkill 同名进程,等于替用户关掉开着的实例;
|
||||
- 旧版 `app_gui.py` 仅保留作历史对照,当前入口使用 `app_fluent.py`;新增或修改界面时
|
||||
应遵循 PySide6-Fluent-Widgets 的控件和 Qt 布局,不要把旧版 CustomTkinter 依赖带回入口。
|
||||
|
||||
## 7. 验证清单(改完代码后)
|
||||
|
||||
1. `python -m compileall -q src`(在 DLPilot/ 下) —— 全模块可编译;
|
||||
2. `python selftest_rs485.py` —— 光机协议回归(改 dlpc_rs485.py 后必跑,向量来自上游 protocols.md);
|
||||
3. `python selftest_theme.py` —— 主题切换回归(改 app_fluent.py 涉及样式/主题后必跑;
|
||||
离屏渲染,Dark/Light 往返后校验 swatch 底色样式与渲染像素、标题字号);
|
||||
3b. `python selftest_log.py` —— 收发日志上限/队列消费回归(改 `_dlpc_log`/`_poll_dlpc`
|
||||
后必跑;600 行封顶 500、坏条目不中断 drain);
|
||||
4. `python hdmi_gui.py --seconds 5` —— GUI 冒烟(自动开关);
|
||||
5. `python hdmi_gui.py --test-pattern Checker --area 800x600 --seconds 3` —— 投图链路;
|
||||
6. `python hdmi_gui.py --dump` —— EDID 解算不抛异常;
|
||||
7. `python hdmi_gui.py --dlpc-cmd M999`(不带 --port)—— 应明确报错而非崩溃(无硬件时的优雅降级);
|
||||
8. `python build_exe.py` → 双击 release/DLPilot.exe 确认图标/双栏布局/投图/光机区渲染;
|
||||
9. `python package_release.py <版本>` —— 不报"引用图片缺失"即栏位完整性 OK。
|
||||
|
||||
## 8. v0.4.0 进度记录(2026-09-24)
|
||||
|
||||
- 入口已切换 `app_fluent.py`;历史 `app_gui.py` 保留,不改其历史版本号。
|
||||
- 本次验证:源码编译通过、RS485 自测 ALL PASS、Qt 离屏浅色渲染、正式 EXE 定时退出码 0。
|
||||
原生桌面自动化不可用,未完成成品 Light 截图;未将硬件功能标记为本次实机验证通过。
|
||||
- 发布已将本次源码、文档、EXE 纳入同一个提交(`74b64dc`),远端标签 `DLPilot-v0.4.0`
|
||||
指向该提交、附件已核对;zip 不入库。
|
||||
- `release/pattern_slots.json` 的本机串口记忆改动属于运行态配置,勿随提交悄悄带入;
|
||||
发布使用仓库预置配置,临时打包后恢复本机文件。
|
||||
- 关联动态:EDID-Viewer 已于 2026-09-25 从本工具的"源端 EDID 查看"需求独立成工具
|
||||
入库并发布 v0.1.0,与本目录无代码共享;I2C-Inject 已标记暂停开发(详见根 `agent.md`)。
|
||||
|
||||
## 9. v0.4.0 后修复记录
|
||||
|
||||
- 2026-09-28 修复"切换 Light 后 R/G/B hex 按钮底色丢失、切回 Dark 也不恢复":根因是
|
||||
fluent 控件直接 `setStyleSheet` 的自定义样式在 `setTheme` 时被库重刷的自带 qss 整体
|
||||
覆盖(任何方向的切换都会丢,非 Light 特有)。swatch 改走 `setCustomStyleSheet`(qss
|
||||
覆盖 hover/pressed/disabled 态),同病的顶栏标题 24px 字号改用 QFont(FluentLabelBase
|
||||
的自定义槽被库的 setTextColor 每次切主题重写,见 §3.12)。新增 `src/selftest_theme.py`
|
||||
离屏回归(样式表存活 + 渲染像素比对),本次验证:compileall / selftest_rs485 /
|
||||
selftest_theme / GUI 冒烟全部通过。
|
||||
- 2026-09-28 以 v0.4.1 重新打包:APP_VERSION → 0.4.1,`build_exe.py` 生成新
|
||||
release/DLPilot.exe(67.1 MB,exe `--seconds 5` 定时退出冒烟 exit 0),按 §8 约定
|
||||
临时还原预置 pattern_slots.json 后 `package_release.py 0.4.1` 生成
|
||||
`DLPilot-v0.4.1-win64.zip`(66.8 MB,zip 内为预置 COM15 配置,本机 COM5 运行态
|
||||
已还原未入库)。Gitea Release 已发布:tag `DLPilot-v0.4.1` 指向提交 `62b325c`
|
||||
(源码+exe+文档同一提交),资产 `DLPilot-v0.4.1-win64.zip`(66.8 MB),
|
||||
https://gitea.hulk.wang/hulk/HW-Debug-Tools/releases/tag/DLPilot-v0.4.1 。
|
||||
发布说明用 --notes-file 传入(内置 DEFAULT_NOTES 模板还是 v0.1.0 旧内容,下次
|
||||
发布记得先写说明文件)。
|
||||
- 2026-09-28 第二修:"串口未选/选错点连接后窗口被拉长、刷新按钮够不到"。根因:
|
||||
pyserial 原始异常串(`could not open port '': FileNotFoundError...`)整段塞进
|
||||
状态 BodyLabel,QLabel 不换行时最小宽度=整行文本宽,把右列参数行最小宽度撑爆。
|
||||
三层修复:①`_dlpc_toggle` 空串口直接短提示返回(不再先写 SERIAL_CFG/save_slots
|
||||
再 open——旧代码这顺序还会把本机串口记忆覆写成空串,本机 COM5 记忆即这样丢失过,
|
||||
已手工修回);②dlpc_rs485 open 失败消息分类为短提示(被占用/不存在/其它),
|
||||
完整异常改走 on_event 进收发日志;③`lbl_dlpc_st.setWordWrap(True)` 兜底。
|
||||
验证:compileall / selftest_rs485 ALL PASS / 离屏断言(空串口提示、长文本下标签
|
||||
最小宽度<300 可换行)/ GUI 冒烟 / 新 exe `--seconds 5` exit 0;v0.4.1 exe(15:05)
|
||||
与 zip 均已用该修复重打。
|
||||
- 2026-09-28 v0.4.2 两处 UI 小修:①"串口数据 · 收发日志"卡的"清空"按钮原本自占
|
||||
一行(_card 的标题行是独立 row,按钮行加在其下),与标题错位且多占一行高度——
|
||||
`_card()` 增加 `trailing` 参数把按钮并入标题行右端;②v0.4.0 fluent 重写把旧版
|
||||
app_gui.py 光机命令卡首行的快捷按钮排(开光机/关光机/查版本/软件重启/开TEC/
|
||||
关TEC/TEC33.0°C)整行丢失,开/关光机只能走预设下拉——本次按旧版排布原样恢复,
|
||||
位于电流行与预设行之间(命令直发 `_dlpc_send`,无新增协议逻辑)。
|
||||
验证:compileall / selftest_rs485 / selftest_theme ALL PASS;离屏渲染断言"清空"
|
||||
与标题垂直中心差 0px、7 个快捷按钮齐全;真实桌面冒烟 exit 0。APP_VERSION → 0.4.2
|
||||
并重打包。v0.4.2 已发布:tag `DLPilot-v0.4.2` 指向提交 `7bd9943`(源码+exe+文档
|
||||
同一提交),资产 `DLPilot-v0.4.2-win64.zip`(66.8 MB,zip 内为预置 COM15 配置,
|
||||
本机 COM5 运行态已还原未入库),
|
||||
https://gitea.hulk.wang/hulk/HW-Debug-Tools/releases/tag/DLPilot-v0.4.2 。
|
||||
本次发布说明已用 --notes-file 传入(临时文件,未入库)。
|
||||
- 2026-10-13 v0.4.3 修复"长会话越跑越卡、命令点了没反应"(FilmForge 同案):
|
||||
根因是 `_dlpc_log` 的手工 textCursor 裁剪用了**实例级枚举访问**
|
||||
(`cursor.Start`/`cursor.BlockUnderCursor`),PySide6 6.11 移除该形式,收发日志
|
||||
超 500 行后每次追加必抛 AttributeError;异常又逃出 `_poll_dlpc` 的 drain 循环
|
||||
(旧 try 只捕获 queue.Empty),每 tick 最多消费到第一条 event,`_dlpc_log_q`
|
||||
棘轮积压、日志裁剪/自动滚动全失效;电源自检/功率检测序列在 `_pd_step_next()`
|
||||
之前的 `_dlpc_log` 调用处被打断,`_pd_seq` 永不清空,后续所有手动命令被
|
||||
"序列进行中"拦截直到断开重连。整改:①改用 `setMaximumBlockCount(500)` 环形
|
||||
裁剪(O(1),不依赖枚举写法);②`_poll_dlpc` 改逐事件兜底 try/except,单条异常
|
||||
只打栈放弃该条、不再中断本轮消费;③新增 `selftest_log.py` 回归(600 行封顶 +
|
||||
坏条目 drain 不中断)。验证:compileall / selftest_rs485 / selftest_theme /
|
||||
selftest_log ALL PASS;GUI 冒烟 exit 0;`--dump` / `--dlpc-cmd`(无串口)正常。
|
||||
APP_VERSION → 0.4.3 重打包(67.1 MB),按 §8 约定临时还原预置 pattern_slots.json
|
||||
后 `package_release.py 0.4.3` 生成 `DLPilot-v0.4.3-win64.zip`(66.8 MB,zip 内
|
||||
为预置 COM15 配置,本机 COM5 运行态已还原未入库)。遗留(未随本版处理):
|
||||
`dlpc_rs485.py` 的 `except OSError` 把写超时(SerialTimeoutException)与设备
|
||||
拔出混判,一次转换器停滞即断链误报"设备拔出"。
|
||||
@@ -4,11 +4,11 @@
|
||||
> HDMI **源端**(EDID 查看、分辨率切换、纯色/测试图案投屏)+ **光机控制**
|
||||
> (RS485 直连板上 GD32 网关,开关光机/设光强/查温度电流)。
|
||||
>
|
||||
> - **只想用工具**:到 [Gitea Releases](https://gitea.hulk.wang/hulk/LT8619C_Debug_Tools/releases)
|
||||
> - **只想用工具**:到 [Gitea Releases](https://gitea.hulk.wang/hulk/HW-Debug-Tools/releases)
|
||||
> 下载 `DLPilot-vX.Y.Z-win64.zip`,解压双击 `DLPilot.exe` 即可(Windows 10/11 x64,免安装、无需 Python)。
|
||||
> - **要改代码/重新打包**:见 §8、§9。
|
||||
>
|
||||
> 更新:2026-09-11
|
||||
> 更新:2026-09-24
|
||||
|
||||
---
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
| EDID 逐字节解析 | "EDID 原始数据"框右上"逐字节解析"按钮:按偏移逐字段展开基础块与 CTA-861 扩展块,每字段附原始字节 hex;命令行等价 `--edid-fields` |
|
||||
| 分辨率切换 | "分辨率"下拉列出显卡按该屏 EDID 提供的全部模式;**应用**=临时切换(不写注册表,重启/恢复即还原),**恢复**=回到本次会话切改前的模式 |
|
||||
| 测试图案投屏 | 全屏投到所选显示器,测试卡区域可选 `640x360 / 800x600 / full 铺满`;内置 纯红/纯绿/纯蓝/黑白棋盘格/网格线 + R/G/B 三行 55/AA/FF 纯色值按钮 + 3 个自定义图片栏位 |
|
||||
| 界面 | CustomTkinter 深色双栏仪表盘(左列 HDMI 源端 / 右列 光机控制),顶栏可切换 Dark/Light/System |
|
||||
| 界面 | PySide6-Fluent-Widgets 双栏仪表盘(左列 HDMI 源端 / 右列 光机控制),顶栏可切换 Dark/Light/System |
|
||||
| 光机控制 | RS485 → 板载 GD32E230 网关 → DLPC3421:开关光机(可定时)、设光强、查电流/温度/版本、TEC 控制、软件重启;光强/定时提供快捷滑条;收发日志带协议译码(见 §5) |
|
||||
| 智能显示拓扑 | 仅当检测到转接板(EDID 厂商 "XLS")接入但未进入桌面(Windows 卡在"仅电脑屏幕")时才强制扩展把它拉回;你主动选的"仅第二屏幕"等拓扑不会被改动 |
|
||||
| 命令行模式 | 全部功能可脚本化调用,供自动化测试(见 §6、§7) |
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
## 2. 下载与安装
|
||||
|
||||
1. 打开 [Releases 页面](https://gitea.hulk.wang/hulk/LT8619C_Debug_Tools/releases),取最新的
|
||||
1. 打开 [Releases 页面](https://gitea.hulk.wang/hulk/HW-Debug-Tools/releases),取最新的
|
||||
`DLPilot-vX.Y.Z-win64.zip`;
|
||||
2. 解压到**任意可写目录**(自定义图片与栏位配置会写到 exe 旁边);
|
||||
3. 双击 `DLPilot.exe`。首次启动比脚本慢一两秒(onefile 解压),属正常现象。
|
||||
@@ -52,16 +52,18 @@ DLPilot/
|
||||
```
|
||||
左列(HDMI 源端) 右列(光机控制 RS485)
|
||||
┌ 显示器选择区域 [刷新] ┐ ┌ 串口选择 + 波特率/8-N-1 参数/连接 ┐
|
||||
├ 支持的模式: 分辨率[应用][恢复] + 明细 ┐ ├ 串口数据 — 收发日志(译码+hex) ┤
|
||||
├ EDID 信息(表格) ┘ ├ 光机命令 — 快捷按钮+TEC │
|
||||
├ 测试图案 / 纯色 / 自定义 / 测试卡区域 │ 预设下拉 / 自定义 / 温度读取 │
|
||||
├ EDID 原始数据 [逐字节解析] ┘ └ 快捷滑条 — 光强/定时/TEC温度 ┘
|
||||
├ 支持的模式: 分辨率[应用][恢复] + 明细 ┐ ├ 电源检查 — PD自检/FPDO挡位/功率读数 ┤
|
||||
├ EDID 信息 ┘ ├ 串口数据 — 收发日志(译码+hex) ┤
|
||||
├ 测试图案 / 纯色 / 校准图案 / 测试卡区域 │ ├ 光机命令 — 快捷按钮+TEC │
|
||||
├ EDID 原始数据 [逐字节解析] ┘ │ 预设下拉 / 温度电流读取 / 自定义 │
|
||||
└─────────────────────────────┘ └ 快捷滑条 — 光强/定时/TEC温度 ┘
|
||||
```
|
||||
|
||||
1. 左上显示器下拉选择目标屏(多屏时注意别选成主屏),"刷新"重新枚举;
|
||||
2. **切分辨率**:"支持的模式"卡片里选模式 → "应用";测完点"恢复";
|
||||
3. **投测试图**:"测试图案"卡片先选**测试卡区域**(640x360 / 800x600 / full)→
|
||||
点图案按钮全屏投放,按 **ESC** 或点击退出;R/G/B 纯色按钮(55/AA/FF,按通道着色)
|
||||
点图案按钮全屏投放(新图案自动替换旧图案),按 **ESC** 或点"停止测试图像"退出;
|
||||
R/G/B 纯色按钮(55/AA/FF,按通道着色)
|
||||
用于 RGB 位交换类测试;自定义图片点齿轮按钮配置(图片自动复制到 exe 旁),
|
||||
"校准图案"一排为 3D 光固化测试/校准图预留槽位;
|
||||
4. **光机控制**:右列选串口与参数(波特率/数据位/校验/停止位,默认 115200 8-N-1)→ 连接 →
|
||||
@@ -98,6 +100,12 @@ GUI"光机控制"区:选串口 → 连接 → 点快捷按钮或命令下拉/
|
||||
多口描述相同时自动附物理位置消歧。日志区实时显示 `→ 命令` / `← 译码结果 (原始 hex)`,
|
||||
错误自动附释义(如 `err:3(I2C NACK)`)。
|
||||
|
||||
"电源检查"卡:**电源自检**依序发 M301(协议)→M302(挡位最大电流)→M303(实测母线电压),
|
||||
按实测电压就近判定 PD 固定挡(5/9/12/15/20/28V,容差 ±5%):**12V 挡且 ≥3A 绿底
|
||||
"FPDO: 12V@3A"**;挡位不符(如 9V 挡)**红底**显示实际挡位;不落在任何标准挡显示
|
||||
**ERR**(CH224Q 电压配置寄存器只写不可读,挡位只能靠实测判定)。**功率检测**依序发
|
||||
M303+M304+M305,读数框显示 电压(V) / 电流(mA) / 功率(W,mW 换算两位小数)。
|
||||
|
||||
| 命令 | 功能 | 响应示例 |
|
||||
|---|---|---|
|
||||
| `M730S0` / `M730S1` | 开 / 关光机 | `ok` |
|
||||
@@ -105,6 +113,11 @@ GUI"光机控制"区:选串口 → 连接 → 点快捷按钮或命令下拉/
|
||||
| `M731S100` | 设光强 54-800(RGB 同值,写后读回复核) | `ok` / `err:R..G..B..` |
|
||||
| `M732` | 查三路电流设置值(0-65535) | `okR110G110B110` |
|
||||
| `M201` / `M202` | 查 DMD / LAMP 温度(0.1°C) | `okTL:246` = 24.6°C |
|
||||
| `M301` | 查电源协议(CH224Q 握手结果) | ASCII:`PD` / `QC3.0` / `EPR` … |
|
||||
| `M302` | 查 PD 挡位最大电流(u16 大端 **mA**,50mA/LSB 固件已换算) | 0x0BB8 = 3000 mA = 3 A |
|
||||
| `M303` | 查母线电压(SQ52205 实测,**2 字节大端二进制载荷**) | 0x2EF4 = 12020 mV = 12.02 V(12V 轨窗口 11400~12600) |
|
||||
| `M304` | 查负载电流(SQ52205 实测,**2 字节大端二进制载荷**) | s16 补码 mA:0x0034=+52;FF 06=−250(正=正向) |
|
||||
| `M305` | 查负载功率(SQ52205 实测,**4 字节大端二进制载荷** u32) | mW→显示 W 两位小数:0x00008CA0=36000 mW=36.00 W(量程 0~295000 mW) |
|
||||
| `M999` | 查固件版本 | `okv20.0.0.1` |
|
||||
| `M737` | 查投光是否结束(投光中延迟应答) | `ok` |
|
||||
| `M7S0` / `M7S1` | TEC 自动控温开 / 关(注意 S0=开) | `ok` |
|
||||
@@ -185,7 +198,8 @@ python la_wave_analyzer3.py <capture.csv> # 3 通道(RGB 三组同拍, ch8/
|
||||
DLPilot/
|
||||
├── src/ # 源代码(人工维护区)
|
||||
│ ├── hdmi_gui.py # 入口与命令行模式(argparse 分发)
|
||||
│ ├── app_gui.py # CustomTkinter 主界面(双栏仪表盘)
|
||||
│ ├── app_fluent.py # PySide6-Fluent-Widgets 主界面(双栏仪表盘)
|
||||
│ ├── app_gui.py # 历史 CustomTkinter 界面(保留,不由入口加载)
|
||||
│ ├── display_win.py # Win32 显示器枚举/分辨率/智能拓扑(纯标准库)
|
||||
│ ├── edid_parse.py # EDID 1.4/CEA-861 解析(纯标准库)
|
||||
│ ├── patterns.py # 测试图案全屏投屏窗口
|
||||
@@ -210,11 +224,11 @@ DLPilot/
|
||||
│ └── *.zip # 发布包(不入库, 上传 Gitea Release)
|
||||
├── README.md # 本说明
|
||||
├── AGENTS.md # 面向 AI/Agent 的工程档案(结构/约定/构建规程)
|
||||
└── UI参考布局.svg/.png # 界面布局设计稿(app_gui.py 按此实现)
|
||||
└── UI参考布局.svg/.png # 界面布局设计稿(app_fluent.py 双栏布局参考)
|
||||
```
|
||||
|
||||
从源码运行:`python src/hdmi_gui.py`,需 Python ≥3.10;EDID/命令行纯标准库;
|
||||
GUI 需 customtkinter(`py -m pip install customtkinter`);光机控制需 pyserial;
|
||||
GUI 需 PySide6-Fluent-Widgets(`py -m pip install PySide6-Fluent-Widgets`);光机控制需 pyserial;
|
||||
自定义图片要 JPG/BMP/WebP 需可选 Pillow。
|
||||
|
||||
## 9. 构建与发布
|
||||
@@ -223,7 +237,7 @@ GUI 需 customtkinter(`py -m pip install customtkinter`);光机控制需 p
|
||||
cd src
|
||||
python selftest_rs485.py # 光机协议回归(改 dlpc_rs485.py 后必跑)
|
||||
python build_exe.py # 打包 → ../release/DLPilot.exe(自动装 PyInstaller;
|
||||
# 内置 pyserial/customtkinter, CTk 主题数据自动收集)
|
||||
# 内置 pyserial/PySide6-Fluent-Widgets, Fluent 主题资源自动收集)
|
||||
python build_exe.py --debug # 额外出一个带控制台的调试变体(--dump 可见输出)
|
||||
python package_release.py 0.2.0 # 组装 release/DLPilot-v0.2.0-win64.zip
|
||||
python publish_gitea.py DLPilot-v0.2.0-win64.zip --insecure # 上传 Gitea Release(需 GITEA_TOKEN)
|
||||
|
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 7.2 KiB |
|
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 51 KiB |
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 7.9 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
@@ -4,11 +4,11 @@
|
||||
> HDMI **源端**(EDID 查看、分辨率切换、纯色/测试图案投屏)+ **光机控制**
|
||||
> (RS485 直连板上 GD32 网关,开关光机/设光强/查温度电流)。
|
||||
>
|
||||
> - **只想用工具**:到 [Gitea Releases](https://gitea.hulk.wang/hulk/LT8619C_Debug_Tools/releases)
|
||||
> - **只想用工具**:到 [Gitea Releases](https://gitea.hulk.wang/hulk/HW-Debug-Tools/releases)
|
||||
> 下载 `DLPilot-vX.Y.Z-win64.zip`,解压双击 `DLPilot.exe` 即可(Windows 10/11 x64,免安装、无需 Python)。
|
||||
> - **要改代码/重新打包**:见 §8、§9。
|
||||
>
|
||||
> 更新:2026-09-11
|
||||
> 更新:2026-09-24
|
||||
|
||||
---
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
| EDID 逐字节解析 | "EDID 原始数据"框右上"逐字节解析"按钮:按偏移逐字段展开基础块与 CTA-861 扩展块,每字段附原始字节 hex;命令行等价 `--edid-fields` |
|
||||
| 分辨率切换 | "分辨率"下拉列出显卡按该屏 EDID 提供的全部模式;**应用**=临时切换(不写注册表,重启/恢复即还原),**恢复**=回到本次会话切改前的模式 |
|
||||
| 测试图案投屏 | 全屏投到所选显示器,测试卡区域可选 `640x360 / 800x600 / full 铺满`;内置 纯红/纯绿/纯蓝/黑白棋盘格/网格线 + R/G/B 三行 55/AA/FF 纯色值按钮 + 3 个自定义图片栏位 |
|
||||
| 界面 | CustomTkinter 深色双栏仪表盘(左列 HDMI 源端 / 右列 光机控制),顶栏可切换 Dark/Light/System |
|
||||
| 界面 | PySide6-Fluent-Widgets 双栏仪表盘(左列 HDMI 源端 / 右列 光机控制),顶栏可切换 Dark/Light/System |
|
||||
| 光机控制 | RS485 → 板载 GD32E230 网关 → DLPC3421:开关光机(可定时)、设光强、查电流/温度/版本、TEC 控制、软件重启;光强/定时提供快捷滑条;收发日志带协议译码(见 §5) |
|
||||
| 智能显示拓扑 | 仅当检测到转接板(EDID 厂商 "XLS")接入但未进入桌面(Windows 卡在"仅电脑屏幕")时才强制扩展把它拉回;你主动选的"仅第二屏幕"等拓扑不会被改动 |
|
||||
| 命令行模式 | 全部功能可脚本化调用,供自动化测试(见 §6、§7) |
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
## 2. 下载与安装
|
||||
|
||||
1. 打开 [Releases 页面](https://gitea.hulk.wang/hulk/LT8619C_Debug_Tools/releases),取最新的
|
||||
1. 打开 [Releases 页面](https://gitea.hulk.wang/hulk/HW-Debug-Tools/releases),取最新的
|
||||
`DLPilot-vX.Y.Z-win64.zip`;
|
||||
2. 解压到**任意可写目录**(自定义图片与栏位配置会写到 exe 旁边);
|
||||
3. 双击 `DLPilot.exe`。首次启动比脚本慢一两秒(onefile 解压),属正常现象。
|
||||
@@ -52,16 +52,18 @@ DLPilot/
|
||||
```
|
||||
左列(HDMI 源端) 右列(光机控制 RS485)
|
||||
┌ 显示器选择区域 [刷新] ┐ ┌ 串口选择 + 波特率/8-N-1 参数/连接 ┐
|
||||
├ 支持的模式: 分辨率[应用][恢复] + 明细 ┐ ├ 串口数据 — 收发日志(译码+hex) ┤
|
||||
├ EDID 信息(表格) ┘ ├ 光机命令 — 快捷按钮+TEC │
|
||||
├ 测试图案 / 纯色 / 自定义 / 测试卡区域 │ 预设下拉 / 自定义 / 温度读取 │
|
||||
├ EDID 原始数据 [逐字节解析] ┘ └ 快捷滑条 — 光强/定时/TEC温度 ┘
|
||||
├ 支持的模式: 分辨率[应用][恢复] + 明细 ┐ ├ 电源检查 — PD自检/FPDO挡位/功率读数 ┤
|
||||
├ EDID 信息 ┘ ├ 串口数据 — 收发日志(译码+hex) ┤
|
||||
├ 测试图案 / 纯色 / 校准图案 / 测试卡区域 │ ├ 光机命令 — 快捷按钮+TEC │
|
||||
├ EDID 原始数据 [逐字节解析] ┘ │ 预设下拉 / 温度电流读取 / 自定义 │
|
||||
└─────────────────────────────┘ └ 快捷滑条 — 光强/定时/TEC温度 ┘
|
||||
```
|
||||
|
||||
1. 左上显示器下拉选择目标屏(多屏时注意别选成主屏),"刷新"重新枚举;
|
||||
2. **切分辨率**:"支持的模式"卡片里选模式 → "应用";测完点"恢复";
|
||||
3. **投测试图**:"测试图案"卡片先选**测试卡区域**(640x360 / 800x600 / full)→
|
||||
点图案按钮全屏投放,按 **ESC** 或点击退出;R/G/B 纯色按钮(55/AA/FF,按通道着色)
|
||||
点图案按钮全屏投放(新图案自动替换旧图案),按 **ESC** 或点"停止测试图像"退出;
|
||||
R/G/B 纯色按钮(55/AA/FF,按通道着色)
|
||||
用于 RGB 位交换类测试;自定义图片点齿轮按钮配置(图片自动复制到 exe 旁),
|
||||
"校准图案"一排为 3D 光固化测试/校准图预留槽位;
|
||||
4. **光机控制**:右列选串口与参数(波特率/数据位/校验/停止位,默认 115200 8-N-1)→ 连接 →
|
||||
@@ -98,6 +100,12 @@ GUI"光机控制"区:选串口 → 连接 → 点快捷按钮或命令下拉/
|
||||
多口描述相同时自动附物理位置消歧。日志区实时显示 `→ 命令` / `← 译码结果 (原始 hex)`,
|
||||
错误自动附释义(如 `err:3(I2C NACK)`)。
|
||||
|
||||
"电源检查"卡:**电源自检**依序发 M301(协议)→M302(挡位最大电流)→M303(实测母线电压),
|
||||
按实测电压就近判定 PD 固定挡(5/9/12/15/20/28V,容差 ±5%):**12V 挡且 ≥3A 绿底
|
||||
"FPDO: 12V@3A"**;挡位不符(如 9V 挡)**红底**显示实际挡位;不落在任何标准挡显示
|
||||
**ERR**(CH224Q 电压配置寄存器只写不可读,挡位只能靠实测判定)。**功率检测**依序发
|
||||
M303+M304+M305,读数框显示 电压(V) / 电流(mA) / 功率(W,mW 换算两位小数)。
|
||||
|
||||
| 命令 | 功能 | 响应示例 |
|
||||
|---|---|---|
|
||||
| `M730S0` / `M730S1` | 开 / 关光机 | `ok` |
|
||||
@@ -105,6 +113,11 @@ GUI"光机控制"区:选串口 → 连接 → 点快捷按钮或命令下拉/
|
||||
| `M731S100` | 设光强 54-800(RGB 同值,写后读回复核) | `ok` / `err:R..G..B..` |
|
||||
| `M732` | 查三路电流设置值(0-65535) | `okR110G110B110` |
|
||||
| `M201` / `M202` | 查 DMD / LAMP 温度(0.1°C) | `okTL:246` = 24.6°C |
|
||||
| `M301` | 查电源协议(CH224Q 握手结果) | ASCII:`PD` / `QC3.0` / `EPR` … |
|
||||
| `M302` | 查 PD 挡位最大电流(u16 大端 **mA**,50mA/LSB 固件已换算) | 0x0BB8 = 3000 mA = 3 A |
|
||||
| `M303` | 查母线电压(SQ52205 实测,**2 字节大端二进制载荷**) | 0x2EF4 = 12020 mV = 12.02 V(12V 轨窗口 11400~12600) |
|
||||
| `M304` | 查负载电流(SQ52205 实测,**2 字节大端二进制载荷**) | s16 补码 mA:0x0034=+52;FF 06=−250(正=正向) |
|
||||
| `M305` | 查负载功率(SQ52205 实测,**4 字节大端二进制载荷** u32) | mW→显示 W 两位小数:0x00008CA0=36000 mW=36.00 W(量程 0~295000 mW) |
|
||||
| `M999` | 查固件版本 | `okv20.0.0.1` |
|
||||
| `M737` | 查投光是否结束(投光中延迟应答) | `ok` |
|
||||
| `M7S0` / `M7S1` | TEC 自动控温开 / 关(注意 S0=开) | `ok` |
|
||||
@@ -185,7 +198,8 @@ python la_wave_analyzer3.py <capture.csv> # 3 通道(RGB 三组同拍, ch8/
|
||||
DLPilot/
|
||||
├── src/ # 源代码(人工维护区)
|
||||
│ ├── hdmi_gui.py # 入口与命令行模式(argparse 分发)
|
||||
│ ├── app_gui.py # CustomTkinter 主界面(双栏仪表盘)
|
||||
│ ├── app_fluent.py # PySide6-Fluent-Widgets 主界面(双栏仪表盘)
|
||||
│ ├── app_gui.py # 历史 CustomTkinter 界面(保留,不由入口加载)
|
||||
│ ├── display_win.py # Win32 显示器枚举/分辨率/智能拓扑(纯标准库)
|
||||
│ ├── edid_parse.py # EDID 1.4/CEA-861 解析(纯标准库)
|
||||
│ ├── patterns.py # 测试图案全屏投屏窗口
|
||||
@@ -210,11 +224,11 @@ DLPilot/
|
||||
│ └── *.zip # 发布包(不入库, 上传 Gitea Release)
|
||||
├── README.md # 本说明
|
||||
├── AGENTS.md # 面向 AI/Agent 的工程档案(结构/约定/构建规程)
|
||||
└── UI参考布局.svg/.png # 界面布局设计稿(app_gui.py 按此实现)
|
||||
└── UI参考布局.svg/.png # 界面布局设计稿(app_fluent.py 双栏布局参考)
|
||||
```
|
||||
|
||||
从源码运行:`python src/hdmi_gui.py`,需 Python ≥3.10;EDID/命令行纯标准库;
|
||||
GUI 需 customtkinter(`py -m pip install customtkinter`);光机控制需 pyserial;
|
||||
GUI 需 PySide6-Fluent-Widgets(`py -m pip install PySide6-Fluent-Widgets`);光机控制需 pyserial;
|
||||
自定义图片要 JPG/BMP/WebP 需可选 Pillow。
|
||||
|
||||
## 9. 构建与发布
|
||||
@@ -223,7 +237,7 @@ GUI 需 customtkinter(`py -m pip install customtkinter`);光机控制需 p
|
||||
cd src
|
||||
python selftest_rs485.py # 光机协议回归(改 dlpc_rs485.py 后必跑)
|
||||
python build_exe.py # 打包 → ../release/DLPilot.exe(自动装 PyInstaller;
|
||||
# 内置 pyserial/customtkinter, CTk 主题数据自动收集)
|
||||
# 内置 pyserial/PySide6-Fluent-Widgets, Fluent 主题资源自动收集)
|
||||
python build_exe.py --debug # 额外出一个带控制台的调试变体(--dump 可见输出)
|
||||
python package_release.py 0.2.0 # 组装 release/DLPilot-v0.2.0-win64.zip
|
||||
python publish_gitea.py DLPilot-v0.2.0-win64.zip --insecure # 上传 Gitea Release(需 GITEA_TOKEN)
|
||||
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 7.9 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"area": "640x360",
|
||||
"slots": [
|
||||
{
|
||||
"name": "西门子星",
|
||||
"file": "bw_star.png"
|
||||
},
|
||||
{
|
||||
"name": "BW_ZONE",
|
||||
"file": "bw_zoneplate.png"
|
||||
},
|
||||
{
|
||||
"name": "BW_TEST",
|
||||
"file": "bw_testcard.png"
|
||||
},
|
||||
{
|
||||
"name": "自定义4",
|
||||
"file": null
|
||||
},
|
||||
{
|
||||
"name": "自定义5",
|
||||
"file": null
|
||||
},
|
||||
{
|
||||
"name": "自定义6",
|
||||
"file": null
|
||||
},
|
||||
{
|
||||
"name": "自定义7",
|
||||
"file": null
|
||||
},
|
||||
{
|
||||
"name": "自定义8",
|
||||
"file": null
|
||||
},
|
||||
{
|
||||
"name": "自定义9",
|
||||
"file": null
|
||||
},
|
||||
{
|
||||
"name": "自定义10",
|
||||
"file": null
|
||||
}
|
||||
],
|
||||
"serial": {
|
||||
"port": "COM15",
|
||||
"baud": 115200,
|
||||
"bytesize": 8,
|
||||
"parity": "N",
|
||||
"stopbits": 1
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
@@ -0,0 +1,901 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""DLPilot Fluent UI.
|
||||
|
||||
The device, EDID and RS485 modules deliberately remain unchanged. This file
|
||||
is the presentation layer for the current desktop application and uses
|
||||
PySide6-Fluent-Widgets for the cards, controls and dialogs.
|
||||
"""
|
||||
|
||||
import ctypes
|
||||
import os
|
||||
import queue
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
|
||||
# PyInstaller keeps Shiboken's ABI DLLs in a sibling directory. Register both
|
||||
# Qt and Shiboken before importing QtCore; this is required by one-file builds
|
||||
# on Windows/Python 3.14 where the normal package import hook is unavailable.
|
||||
if getattr(sys, "frozen", False) and os.name == "nt":
|
||||
_frozen_dll_dirs = []
|
||||
for _dll_dir in (os.path.join(getattr(sys, "_MEIPASS", ""), "PySide6"),
|
||||
os.path.join(getattr(sys, "_MEIPASS", ""), "shiboken6")):
|
||||
if os.path.isdir(_dll_dir):
|
||||
_frozen_dll_dirs.append(_dll_dir)
|
||||
try:
|
||||
os.add_dll_directory(_dll_dir)
|
||||
except (AttributeError, OSError):
|
||||
pass
|
||||
# Python 3.14 extension loading may ignore AddDllDirectory for a pyd's
|
||||
# transitive dependencies; PATH keeps QtCore.pyd compatible with both
|
||||
# Python 3.11-3.14 and PyInstaller one-file extraction.
|
||||
if _frozen_dll_dirs:
|
||||
os.environ["PATH"] = os.pathsep.join(_frozen_dll_dirs + [os.environ.get("PATH", "")])
|
||||
# Preload the two libraries used by QtCore.pyd. This also covers Windows
|
||||
# loader configurations that do not apply PATH/AddDllDirectory to a pyd's
|
||||
# transitive dependencies after PyInstaller extraction.
|
||||
try:
|
||||
ctypes.WinDLL(os.path.join(getattr(sys, "_MEIPASS", ""), "shiboken6",
|
||||
"shiboken6.abi3.dll"))
|
||||
ctypes.WinDLL(os.path.join(getattr(sys, "_MEIPASS", ""), "PySide6",
|
||||
"Qt6Core.dll"))
|
||||
except (AttributeError, OSError):
|
||||
pass
|
||||
|
||||
from PySide6.QtCore import QPoint, QRect, Qt, QTimer
|
||||
from PySide6.QtGui import QColor, QFont, QIcon, QImage, QPainter, QPen, QPalette
|
||||
from PySide6.QtWidgets import (
|
||||
QApplication, QDialog, QFileDialog, QFormLayout, QGridLayout, QHBoxLayout,
|
||||
QLabel, QMainWindow, QMessageBox, QPlainTextEdit, QScrollArea, QSplitter,
|
||||
QToolButton, QVBoxLayout, QWidget,
|
||||
)
|
||||
from qfluentwidgets import (
|
||||
BodyLabel, CardWidget, ComboBox, LineEdit, PlainTextEdit,
|
||||
PrimaryPushButton, PushButton, Slider, StrongBodyLabel, Theme,
|
||||
setCustomStyleSheet, setTheme,
|
||||
)
|
||||
|
||||
import config
|
||||
import display_win
|
||||
import dlpc_rs485
|
||||
import edid_parse
|
||||
import patterns
|
||||
|
||||
APP_NAME = "DLPilot"
|
||||
APP_VERSION = "0.4.3"
|
||||
REPO_URL = "https://gitea.hulk.wang/hulk/HW-Debug-Tools"
|
||||
MONO = QFont("Consolas", 10)
|
||||
CHIP_IDLE = "#666666"
|
||||
CHIP_OK = "#2FA574"
|
||||
CHIP_ERR = "#D9534F"
|
||||
|
||||
_QT_PATTERNS = set()
|
||||
|
||||
|
||||
def close_qt_patterns():
|
||||
for window in list(_QT_PATTERNS):
|
||||
window.close()
|
||||
_QT_PATTERNS.clear()
|
||||
patterns.close_all()
|
||||
|
||||
|
||||
def _area_box(spec, width, height):
|
||||
if spec == "full":
|
||||
return 0, 0, width, height
|
||||
try:
|
||||
aw, ah = (int(v) for v in spec.lower().split("x", 1))
|
||||
except Exception:
|
||||
aw, ah = config.PAT_W, config.PAT_H
|
||||
return (width - aw) // 2, (height - ah) // 2, aw, ah
|
||||
|
||||
|
||||
class PatternWindow(QWidget):
|
||||
"""Borderless Qt equivalent of the old tkinter test-pattern window."""
|
||||
|
||||
def __init__(self, rect, kind, area, image_path=None, parent=None):
|
||||
super().__init__(parent)
|
||||
self.kind = kind
|
||||
self.area = area
|
||||
self.image = QImage(image_path) if image_path else None
|
||||
x, y, width, height = rect
|
||||
self.setGeometry(x, y, width, height)
|
||||
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint |
|
||||
Qt.Tool)
|
||||
self.setAttribute(Qt.WA_DeleteOnClose)
|
||||
_QT_PATTERNS.add(self)
|
||||
self.show()
|
||||
self.activateWindow()
|
||||
self.setFocus()
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
if event.key() == Qt.Key_Escape:
|
||||
self.close()
|
||||
else:
|
||||
super().keyPressEvent(event)
|
||||
|
||||
def closeEvent(self, event):
|
||||
_QT_PATTERNS.discard(self)
|
||||
super().closeEvent(event)
|
||||
|
||||
def paintEvent(self, _event):
|
||||
painter = QPainter(self)
|
||||
painter.fillRect(self.rect(), Qt.black)
|
||||
x0, y0, aw, ah = _area_box(self.area, self.width(), self.height())
|
||||
if self.image and not self.image.isNull():
|
||||
painter.drawImage(QPoint(x0 + (aw - self.image.width()) // 2,
|
||||
y0 + (ah - self.image.height()) // 2),
|
||||
self.image)
|
||||
return
|
||||
if self.kind.startswith("#"):
|
||||
painter.fillRect(x0, y0, aw, ah, QColor(self.kind))
|
||||
elif self.kind in {"Red", "Green", "Blue"}:
|
||||
painter.fillRect(x0, y0, aw, ah,
|
||||
QColor({"Red": "#ff0000", "Green": "#00ff00",
|
||||
"Blue": "#0000ff"}[self.kind]))
|
||||
elif self.kind == "Checker":
|
||||
for gy in range((ah + 39) // 40):
|
||||
for gx in range((aw + 39) // 40):
|
||||
if (gx + gy) % 2 == 0:
|
||||
painter.fillRect(x0 + gx * 40, y0 + gy * 40, 40, 40,
|
||||
Qt.white)
|
||||
elif self.kind == "Grid":
|
||||
painter.setPen(QPen(Qt.white, 1))
|
||||
for x in range(0, aw + 1, 20):
|
||||
painter.drawLine(x0 + x, y0, x0 + x, y0 + ah)
|
||||
for y in range(0, ah + 1, 20):
|
||||
painter.drawLine(x0, y0 + y, x0 + aw, y0 + y)
|
||||
|
||||
|
||||
def _single_instance():
|
||||
if os.name != "nt":
|
||||
return True
|
||||
try:
|
||||
ctypes.windll.kernel32.CreateMutexW(None, False, "hulk.DLPilot.single")
|
||||
return ctypes.windll.kernel32.GetLastError() != 183
|
||||
except Exception:
|
||||
return True
|
||||
|
||||
|
||||
class App(QMainWindow):
|
||||
def __init__(self, auto_close=0):
|
||||
super().__init__()
|
||||
app = QApplication.instance()
|
||||
self._system_palette = app.palette() if app else QPalette()
|
||||
self._system_style = app.styleSheet() if app else ""
|
||||
self.setWindowTitle(f"{APP_NAME} v{APP_VERSION} — 3D 光固化光机调试台")
|
||||
icon_path = self._icon_path()
|
||||
if icon_path:
|
||||
self.setWindowIcon(QIcon(icon_path))
|
||||
self.resize(1440, 960)
|
||||
self.setMinimumSize(1180, 760)
|
||||
self.displays = []
|
||||
self._disp_labels = []
|
||||
self._modes = {}
|
||||
self._orig_modes = {}
|
||||
self._cur_label = ""
|
||||
self.slots, self.area = config.load_slots()
|
||||
self._dlpc_log_q = queue.Queue()
|
||||
self.dlpc = dlpc_rs485.DLPC485(self._dlpc_on_event, self._dlpc_on_status,
|
||||
on_frame=self._dlpc_on_frame)
|
||||
self._dlpc_connected = False
|
||||
self._tl_order = []
|
||||
self._pd_seq = []
|
||||
self._pd_values = {}
|
||||
self._pd_timer = None
|
||||
self._pwr_seq = []
|
||||
self._pwr_values = {}
|
||||
self._pwr_timer = None
|
||||
self._build()
|
||||
self._load_displays()
|
||||
self._timer = QTimer(self)
|
||||
self._timer.timeout.connect(self._poll_dlpc)
|
||||
if dlpc_rs485.HAS_SERIAL:
|
||||
self._timer.start(80)
|
||||
if auto_close > 0:
|
||||
QTimer.singleShot(auto_close * 1000, self.close)
|
||||
|
||||
@staticmethod
|
||||
def _icon_path():
|
||||
base = getattr(sys, "_MEIPASS", os.path.dirname(os.path.abspath(__file__)))
|
||||
path = os.path.join(base, "logo_dlpilot.ico")
|
||||
if os.path.exists(path):
|
||||
return path
|
||||
path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
|
||||
"logos", "logo_dlpilot.ico")
|
||||
return path if os.path.exists(path) else None
|
||||
|
||||
def _button(self, text, callback, primary=False):
|
||||
button = PrimaryPushButton(text) if primary else PushButton(text)
|
||||
button.clicked.connect(callback)
|
||||
return button
|
||||
|
||||
def _card(self, title, parent, trailing=None):
|
||||
card = CardWidget(parent)
|
||||
layout = QVBoxLayout(card)
|
||||
layout.setContentsMargins(14, 12, 14, 14)
|
||||
layout.setSpacing(8)
|
||||
row = QHBoxLayout()
|
||||
row.addWidget(StrongBodyLabel(title, card))
|
||||
row.addStretch(1)
|
||||
if trailing is not None:
|
||||
row.addWidget(trailing)
|
||||
layout.addLayout(row)
|
||||
return card, layout
|
||||
|
||||
def _collapsible_card(self, title, parent, expanded=False):
|
||||
"""Card whose body starts collapsed to keep the dashboard compact."""
|
||||
card = CardWidget(parent)
|
||||
layout = QVBoxLayout(card)
|
||||
layout.setContentsMargins(8, 6, 8, 8)
|
||||
layout.setSpacing(4)
|
||||
header = QToolButton(card)
|
||||
header.setText(title)
|
||||
header.setCheckable(True)
|
||||
header.setChecked(expanded)
|
||||
header.setAutoRaise(True)
|
||||
header.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
|
||||
header.setArrowType(Qt.DownArrow if expanded else Qt.RightArrow)
|
||||
header.setStyleSheet("QToolButton { text-align: left; font-weight: 700; padding: 6px; }")
|
||||
layout.addWidget(header)
|
||||
body = QWidget(card)
|
||||
body_layout = QVBoxLayout(body)
|
||||
body_layout.setContentsMargins(6, 0, 6, 4)
|
||||
body_layout.setSpacing(8)
|
||||
body.setVisible(expanded)
|
||||
layout.addWidget(body)
|
||||
|
||||
def toggle(checked):
|
||||
body.setVisible(checked)
|
||||
header.setArrowType(Qt.DownArrow if checked else Qt.RightArrow)
|
||||
card.adjustSize()
|
||||
|
||||
header.clicked.connect(toggle)
|
||||
return card, body_layout
|
||||
|
||||
def _text(self, read_only=True, mono=True):
|
||||
text = PlainTextEdit(self)
|
||||
text.setReadOnly(read_only)
|
||||
if mono:
|
||||
text.setFont(MONO)
|
||||
text.setLineWrapMode(QPlainTextEdit.NoWrap)
|
||||
return text
|
||||
|
||||
def _build(self):
|
||||
root = QWidget(self)
|
||||
root.setObjectName("root")
|
||||
outer = QVBoxLayout(root)
|
||||
outer.setContentsMargins(18, 14, 18, 18)
|
||||
outer.setSpacing(12)
|
||||
header = QHBoxLayout()
|
||||
title = StrongBodyLabel("DLPilot", root)
|
||||
# 标题字号走 QFont:FluentLabelBase 在每次主题切换时会用自带的颜色规则
|
||||
# 重写自定义 qss 槽,setStyleSheet/setCustomStyleSheet 写的字号都会被冲掉
|
||||
title_font = title.font()
|
||||
title_font.setPixelSize(24)
|
||||
title_font.setBold(True)
|
||||
title.setFont(title_font)
|
||||
header.addWidget(title)
|
||||
header.addWidget(BodyLabel("EDID · 测试图案 · RS485 光机控制", root))
|
||||
header.addStretch(1)
|
||||
self.theme = ComboBox(root)
|
||||
self.theme.addItems(["Dark", "Light", "System"])
|
||||
self.theme.setCurrentText("System")
|
||||
self.theme.currentTextChanged.connect(self._set_theme)
|
||||
header.addWidget(self.theme)
|
||||
header.addWidget(self._button("关于", self._show_about))
|
||||
outer.addLayout(header)
|
||||
|
||||
split = QSplitter(Qt.Horizontal, root)
|
||||
split.setChildrenCollapsible(False)
|
||||
split.addWidget(self._scroll_column(self._build_left))
|
||||
split.addWidget(self._scroll_column(self._build_right))
|
||||
split.setStretchFactor(0, 1)
|
||||
split.setStretchFactor(1, 1)
|
||||
outer.addWidget(split, 1)
|
||||
self.setCentralWidget(root)
|
||||
|
||||
def _scroll_column(self, builder):
|
||||
host = QWidget()
|
||||
layout = QVBoxLayout(host)
|
||||
layout.setContentsMargins(2, 2, 8, 2)
|
||||
layout.setSpacing(10)
|
||||
builder(layout)
|
||||
layout.addStretch(1)
|
||||
scroll = QScrollArea()
|
||||
scroll.setWidgetResizable(True)
|
||||
scroll.setFrameShape(QScrollArea.NoFrame)
|
||||
scroll.setWidget(host)
|
||||
if builder.__name__ == '_build_left':
|
||||
self.left_scroll = scroll
|
||||
else:
|
||||
self.right_scroll = scroll
|
||||
return scroll
|
||||
|
||||
def _build_left(self, layout):
|
||||
card, body = self._card("显示器选择", self)
|
||||
row = QHBoxLayout()
|
||||
self.cbo_display = ComboBox(card)
|
||||
self.cbo_display.currentTextChanged.connect(self._on_select)
|
||||
self.lbl_cur = BodyLabel("当前输出: —", card)
|
||||
row.addWidget(self.cbo_display, 1)
|
||||
row.addWidget(self._button("刷新", self._load_displays))
|
||||
body.addLayout(row)
|
||||
body.addWidget(self.lbl_cur)
|
||||
layout.addWidget(card)
|
||||
|
||||
card, body = self._collapsible_card("支持的模式(EDID 解算)", self)
|
||||
row = QHBoxLayout()
|
||||
self.cbo_mode = ComboBox(card)
|
||||
row.addWidget(BodyLabel("分辨率:", card))
|
||||
row.addWidget(self.cbo_mode, 1)
|
||||
row.addWidget(self._button("应用", self._apply_mode, True))
|
||||
row.addWidget(self._button("恢复", self._restore_mode))
|
||||
body.addLayout(row)
|
||||
self.txt_modes = self._text()
|
||||
self.txt_modes.setMinimumHeight(135)
|
||||
body.addWidget(self.txt_modes)
|
||||
layout.addWidget(card)
|
||||
|
||||
card, body = self._collapsible_card("EDID 信息", self)
|
||||
self.txt_edid = self._text()
|
||||
self.txt_edid.setMinimumHeight(150)
|
||||
body.addWidget(self.txt_edid)
|
||||
layout.addWidget(card)
|
||||
|
||||
card, body = self._card("测试图案", self)
|
||||
row = QHBoxLayout()
|
||||
for key, name in patterns.PATTERN_NAMES.items():
|
||||
row.addWidget(self._button(name, lambda checked=False, k=key: self._show_pattern(k)))
|
||||
row.addWidget(self._button("停止", close_qt_patterns))
|
||||
body.addLayout(row)
|
||||
area_row = QHBoxLayout()
|
||||
area_row.addWidget(BodyLabel("测试卡区域:", card))
|
||||
self.cbo_area = ComboBox(card)
|
||||
self.cbo_area.addItems(list(config.AREA_OPTIONS))
|
||||
self.cbo_area.setCurrentText(self.area)
|
||||
self.cbo_area.currentTextChanged.connect(self._save_area)
|
||||
area_row.addWidget(self.cbo_area)
|
||||
area_row.addStretch(1)
|
||||
body.addLayout(area_row)
|
||||
for channel, items in patterns.SOLID_ROWS:
|
||||
row = QHBoxLayout()
|
||||
row.addWidget(BodyLabel(f"{channel}: 0x", card))
|
||||
for label, color in items:
|
||||
button = PushButton(label, card)
|
||||
# fluent 控件的样式须走 setCustomStyleSheet:直接 setStyleSheet 的内容
|
||||
# 会在 setTheme 时被库重刷的自带 qss 冲掉;且须覆盖 hover/pressed 态,
|
||||
# 否则悬停瞬间底色仍会被自带态样式盖回
|
||||
fg = 'black' if color == '#00FF00' else 'white'
|
||||
qss = ("PushButton, PushButton:hover, PushButton:pressed, "
|
||||
f"PushButton:disabled {{ background-color: {color}; color: {fg}; border: none; }}")
|
||||
setCustomStyleSheet(button, qss, qss)
|
||||
button.clicked.connect(lambda checked=False, c=color: self._show_solid(c))
|
||||
row.addWidget(button)
|
||||
row.addStretch(1)
|
||||
body.addLayout(row)
|
||||
self.slot_buttons = []
|
||||
grid = QGridLayout()
|
||||
for i in range(config.SLOT_COUNT):
|
||||
cell = QWidget(card)
|
||||
cell_layout = QHBoxLayout(cell)
|
||||
cell_layout.setContentsMargins(0, 0, 0, 0)
|
||||
button = self._button(self.slots[i]["name"], lambda checked=False, n=i: self._show_custom(n))
|
||||
gear = self._button("⚙", lambda checked=False, n=i: self._configure_slot(n))
|
||||
cell_layout.addWidget(button, 1)
|
||||
cell_layout.addWidget(gear)
|
||||
grid.addWidget(cell, i // 2, i % 2)
|
||||
self.slot_buttons.append(button)
|
||||
body.addLayout(grid)
|
||||
layout.addWidget(card)
|
||||
|
||||
card, body = self._card("EDID 原始数据", self)
|
||||
self.txt_hex = self._text()
|
||||
self.txt_hex.setMinimumHeight(130)
|
||||
body.addWidget(self.txt_hex)
|
||||
body.addWidget(self._button("逐字节解析", self._show_edid_fields))
|
||||
layout.addWidget(card)
|
||||
|
||||
def _build_right(self, layout):
|
||||
if not dlpc_rs485.HAS_SERIAL:
|
||||
card, body = self._card("光机控制不可用", self)
|
||||
body.addWidget(BodyLabel("未安装 pyserial,请执行 py -m pip install pyserial。"))
|
||||
layout.addWidget(card)
|
||||
return
|
||||
card, body = self._card("串口 · RS485 → GD32 网关 → DLPC3421", self)
|
||||
row = QHBoxLayout()
|
||||
self._dlpc_ports = dlpc_rs485.DLPC485.list_ports_info()
|
||||
self.cbo_dlpc = ComboBox(card)
|
||||
self.cbo_dlpc.addItems([label for _device, label in self._dlpc_ports])
|
||||
if config.SERIAL_CFG["port"]:
|
||||
self._dlpc_pick(config.SERIAL_CFG["port"])
|
||||
row.addWidget(self.cbo_dlpc, 1)
|
||||
row.addWidget(self._button("刷新", self._dlpc_refresh))
|
||||
self.btn_dlpc = self._button("连接", self._dlpc_toggle, True)
|
||||
row.addWidget(self.btn_dlpc)
|
||||
body.addLayout(row)
|
||||
params = QHBoxLayout()
|
||||
for caption, attr, values, default in (
|
||||
("波特率", "cbo_baud", ["115200", "57600", "38400", "9600"], str(config.SERIAL_CFG["baud"])),
|
||||
("数据位", "cbo_databits", ["8", "7", "6", "5"], str(config.SERIAL_CFG["bytesize"])),
|
||||
("校验", "cbo_parity", ["N", "E", "O"], str(config.SERIAL_CFG["parity"])),
|
||||
("停止位", "cbo_stopbits", ["1", "2"], str(config.SERIAL_CFG["stopbits"])),
|
||||
):
|
||||
params.addWidget(BodyLabel(caption, card))
|
||||
combo = ComboBox(card)
|
||||
combo.addItems(values)
|
||||
combo.setCurrentText(default)
|
||||
setattr(self, attr, combo)
|
||||
params.addWidget(combo)
|
||||
self.lbl_dlpc_st = BodyLabel("未连接", card)
|
||||
# 状态标签允许换行兜底: 任何长错误串都不得撑大参数行最小宽度(否则窗口拉长,
|
||||
# 刷新/连接按钮被挤出可视区)
|
||||
self.lbl_dlpc_st.setWordWrap(True)
|
||||
params.addWidget(self.lbl_dlpc_st)
|
||||
params.addStretch(1)
|
||||
body.addLayout(params)
|
||||
layout.addWidget(card)
|
||||
|
||||
card, body = self._card("串口数据 · 收发日志(译码 + 原始 hex)", self,
|
||||
trailing=self._button("清空", self._dlpc_clear))
|
||||
self.txt_dlpc = self._text()
|
||||
self.txt_dlpc.setMinimumHeight(230)
|
||||
# 收发日志环形裁剪: 超 500 行自动丢最旧(O(1))。勿改回 textCursor 手工裁剪——
|
||||
# PySide6 6.11 移除实例级枚举访问, cursor.Start 必抛 AttributeError 且异常会
|
||||
# 打断 _poll_dlpc 的队列消费(事件棘轮积压), 回归见 selftest_log.py
|
||||
self.txt_dlpc.document().setMaximumBlockCount(500)
|
||||
body.addWidget(self.txt_dlpc)
|
||||
self._dlpc_log("帧格式: D5 01 LEN <命令> CRC / B5 TYPE LEN <payload> CRC")
|
||||
layout.addWidget(card)
|
||||
|
||||
card, body = self._card("电源检查 · PD 自检 / 功率读数", self)
|
||||
self.chip_pd = QLabel("PD", card)
|
||||
self.chip_fpdo = QLabel("FPDO: —", card)
|
||||
self.var_pwr = "电压: — 电流: — 功率: —"
|
||||
self.box_pwr = QLabel(self.var_pwr, card)
|
||||
for widget in (self.chip_pd, self.chip_fpdo, self.box_pwr):
|
||||
widget.setMinimumHeight(30)
|
||||
widget.setAlignment(Qt.AlignCenter | Qt.AlignVCenter)
|
||||
widget.setStyleSheet(f"background: {CHIP_IDLE}; color: white; border-radius: 6px; padding: 4px 8px;")
|
||||
row = QHBoxLayout()
|
||||
row.addWidget(self._button("电源自检", self._pd_selftest))
|
||||
row.addWidget(self.chip_pd)
|
||||
row.addWidget(self.chip_fpdo, 1)
|
||||
body.addLayout(row)
|
||||
row = QHBoxLayout()
|
||||
row.addWidget(self._button("功率检测", self._pwr_query))
|
||||
row.addWidget(self.box_pwr, 1)
|
||||
body.addLayout(row)
|
||||
layout.addWidget(card)
|
||||
|
||||
card, body = self._card("光机命令 · 预设 / 自定义 / 温度", self)
|
||||
row = QHBoxLayout()
|
||||
self.var_current = BodyLabel("电流: —", card)
|
||||
row.addWidget(self.var_current)
|
||||
row.addStretch(1)
|
||||
row.addWidget(self._button("查电流", self._query_current))
|
||||
body.addLayout(row)
|
||||
# 快捷命令行: v0.4.0 重写时从旧版 app_gui.py 丢失, 开关光机等一发命令
|
||||
# 不应只能走预设下拉
|
||||
quick = QHBoxLayout()
|
||||
for name, cmd in (("开光机", "M730S0"), ("关光机", "M730S1"), ("查版本", "M999"),
|
||||
("软件重启", "M888"), ("开TEC", "M7S0"), ("关TEC", "M7S1"),
|
||||
("TEC33.0°C", "M8S330")):
|
||||
quick.addWidget(self._button(name, lambda checked=False, c=cmd: self._dlpc_send(c)))
|
||||
body.addLayout(quick)
|
||||
preset_row = QHBoxLayout()
|
||||
self._dlpc_presets = [(n, cmd) for n, cmd, _ in dlpc_rs485.PRESETS]
|
||||
self.cbo_dlpc_cmd = ComboBox(card)
|
||||
self.cbo_dlpc_cmd.addItems([f"{n} {cmd}" for n, cmd in self._dlpc_presets])
|
||||
preset_row.addWidget(BodyLabel("预设:", card))
|
||||
preset_row.addWidget(self.cbo_dlpc_cmd, 1)
|
||||
preset_row.addWidget(self._button("发送", self._dlpc_send_preset, True))
|
||||
preset_row.addWidget(self._button("查 DMD 温度", self._query_dmd))
|
||||
self.var_dmd = BodyLabel("DMD: —", card)
|
||||
preset_row.addWidget(self.var_dmd)
|
||||
body.addLayout(preset_row)
|
||||
custom_row = QHBoxLayout()
|
||||
self.var_custom_cmd = LineEdit(card)
|
||||
self.var_custom_cmd.setPlaceholderText("如 M730S0T2000")
|
||||
self.var_custom_cmd.returnPressed.connect(self._dlpc_send_custom)
|
||||
custom_row.addWidget(BodyLabel("自定义:", card))
|
||||
custom_row.addWidget(self.var_custom_cmd, 1)
|
||||
custom_row.addWidget(self._button("发送", self._dlpc_send_custom))
|
||||
custom_row.addWidget(self._button("查 LAMP 温度", self._query_lamp))
|
||||
self.var_lamp = BodyLabel("LAMP: —", card)
|
||||
custom_row.addWidget(self.var_lamp)
|
||||
body.addLayout(custom_row)
|
||||
layout.addWidget(card)
|
||||
|
||||
card, body = self._card("快捷滑条 · 光强 / 定时投光 / TEC 温度", self)
|
||||
self.sld_light, self.ent_light = self._slider_row(body, "光强 (54-800)", 54, 800, 100, self._dlpc_send_light, "下发电流值")
|
||||
self.sld_timer, self.ent_timer = self._slider_row(body, "定时投光 (毫秒)", 0, 32700, 2000, self._dlpc_send_timer, "开光机(定时)")
|
||||
self.sld_tec, self.ent_tec = self._slider_row(body, "TEC 凝露点 (0.1°C)", 200, 350, 330, self._dlpc_send_tec, "下发温度值")
|
||||
layout.addWidget(card)
|
||||
|
||||
def _slider_row(self, layout, text, low, high, value, callback, button_text):
|
||||
row = QHBoxLayout()
|
||||
row.addWidget(BodyLabel(text, self))
|
||||
slider = Slider(Qt.Horizontal, self)
|
||||
slider.setRange(low, high)
|
||||
slider.setValue(value)
|
||||
entry = LineEdit(self)
|
||||
entry.setText(str(value))
|
||||
entry.setFixedWidth(65)
|
||||
slider.valueChanged.connect(lambda v: entry.setText(str(v)))
|
||||
entry.returnPressed.connect(lambda: self._sync_slider(slider, entry, low, high))
|
||||
row.addWidget(slider, 1)
|
||||
row.addWidget(entry)
|
||||
row.addWidget(self._button(button_text, callback))
|
||||
layout.addLayout(row)
|
||||
return slider, entry
|
||||
|
||||
@staticmethod
|
||||
def _sync_slider(slider, entry, low, high):
|
||||
try:
|
||||
value = int(entry.text())
|
||||
except ValueError:
|
||||
value = slider.value()
|
||||
value = max(low, min(high, value))
|
||||
slider.setValue(value)
|
||||
entry.setText(str(value))
|
||||
|
||||
def _set_theme(self, value):
|
||||
app = QApplication.instance()
|
||||
setTheme({"Dark": Theme.DARK, "Light": Theme.LIGHT, "System": Theme.AUTO}[value])
|
||||
if value == "System":
|
||||
app.setPalette(self._system_palette)
|
||||
app.setStyleSheet(self._system_style)
|
||||
is_dark = app.palette().color(QPalette.Window).value() < 128
|
||||
else:
|
||||
is_dark = value == "Dark"
|
||||
self._apply_palette(is_dark)
|
||||
self._apply_native_titlebar(is_dark)
|
||||
|
||||
def _apply_palette(self, is_dark):
|
||||
"""Keep native Qt widgets and Fluent cards on the same surface colors."""
|
||||
app = QApplication.instance()
|
||||
palette = QPalette()
|
||||
if is_dark:
|
||||
window, base, text, border = "#202020", "#2b2b2b", "#f5f5f5", "#3a3a3a"
|
||||
accent = "#00c8d7"
|
||||
else:
|
||||
window, base, text, border = "#f4f6f8", "#ffffff", "#1f2328", "#d8dee4"
|
||||
accent = "#0f6cbd"
|
||||
for role in (QPalette.Window, QPalette.Base, QPalette.AlternateBase):
|
||||
palette.setColor(role, QColor(window if role == QPalette.Window else base))
|
||||
palette.setColor(QPalette.Text, QColor(text))
|
||||
palette.setColor(QPalette.WindowText, QColor(text))
|
||||
palette.setColor(QPalette.Button, QColor(base))
|
||||
palette.setColor(QPalette.ButtonText, QColor(text))
|
||||
palette.setColor(QPalette.PlaceholderText, QColor("#8b949e" if not is_dark else "#8a8a8a"))
|
||||
palette.setColor(QPalette.Highlight, QColor(accent))
|
||||
palette.setColor(QPalette.HighlightedText, QColor("#ffffff"))
|
||||
palette.setColor(QPalette.ToolTipBase, QColor(base))
|
||||
palette.setColor(QPalette.ToolTipText, QColor(text))
|
||||
app.setPalette(palette)
|
||||
app.setStyleSheet(f"""
|
||||
QMainWindow, QWidget#root {{ background-color: {window}; color: {text}; }}
|
||||
QScrollArea, QScrollArea > QWidget > QWidget {{ background: transparent; border: 0; }}
|
||||
CardWidget {{ background-color: {base}; border: 1px solid {border}; border-radius: 8px; }}
|
||||
QPlainTextEdit, QTextEdit, QLineEdit, QComboBox {{
|
||||
background-color: {base}; color: {text};
|
||||
border: 1px solid {border}; border-radius: 5px;
|
||||
selection-background-color: {accent};
|
||||
}}
|
||||
QToolButton {{ color: {text}; }}
|
||||
""")
|
||||
|
||||
def _apply_native_titlebar(self, is_dark):
|
||||
if os.name != "nt" or not hasattr(ctypes, "windll"):
|
||||
return
|
||||
try:
|
||||
hwnd = int(self.winId())
|
||||
dwm = ctypes.windll.dwmapi
|
||||
dark = ctypes.c_int(1 if is_dark else 0)
|
||||
dwm.DwmSetWindowAttribute(hwnd, 20, ctypes.byref(dark), ctypes.sizeof(dark))
|
||||
color = QColor("#202020" if is_dark else "#f4f6f8")
|
||||
colorref = ctypes.c_int(color.red() | (color.green() << 8) | (color.blue() << 16))
|
||||
text = QColor("#f5f5f5" if is_dark else "#1f2328")
|
||||
textref = ctypes.c_int(text.red() | (text.green() << 8) | (text.blue() << 16))
|
||||
dwm.DwmSetWindowAttribute(hwnd, 35, ctypes.byref(colorref), ctypes.sizeof(colorref))
|
||||
dwm.DwmSetWindowAttribute(hwnd, 36, ctypes.byref(textref), ctypes.sizeof(textref))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _cur_display(self):
|
||||
try:
|
||||
return self.displays[self._disp_labels.index(self.cbo_display.currentText())]
|
||||
except (ValueError, IndexError, AttributeError):
|
||||
return None
|
||||
|
||||
def _load_displays(self):
|
||||
previous = self._cur_label
|
||||
try:
|
||||
self.displays = display_win.get_displays()
|
||||
except Exception as exc:
|
||||
self.displays = []
|
||||
self.notice("显示器枚举失败", str(exc), error=True)
|
||||
self._disp_labels = [f"{d['device']} {d['adapter']} [{d['mon_name']}]" for d in self.displays]
|
||||
self.cbo_display.blockSignals(True)
|
||||
self.cbo_display.clear()
|
||||
self.cbo_display.addItems(self._disp_labels)
|
||||
if self._disp_labels:
|
||||
self.cbo_display.setCurrentText(previous if previous in self._disp_labels else self._disp_labels[0])
|
||||
self.cbo_display.blockSignals(False)
|
||||
if self._disp_labels:
|
||||
self._cur_label = self.cbo_display.currentText()
|
||||
self._on_select(self._cur_label)
|
||||
self.left_scroll.verticalScrollBar().setValue(0)
|
||||
self.right_scroll.verticalScrollBar().setValue(0)
|
||||
else:
|
||||
self.lbl_cur.setText("未找到活动显示器")
|
||||
self.txt_modes.clear(); self.txt_edid.clear(); self.txt_hex.clear()
|
||||
|
||||
def _on_select(self, _value=None):
|
||||
d = self._cur_display()
|
||||
if d is None:
|
||||
return
|
||||
self._cur_label = self.cbo_display.currentText()
|
||||
self.lbl_cur.setText(f"当前输出: {d['cur_mode']}")
|
||||
keys, self._modes = display_win.enum_modes(d['device'])
|
||||
self.cbo_mode.clear(); self.cbo_mode.addItems(keys)
|
||||
if d['cur_mode'] in self._modes:
|
||||
self.cbo_mode.setCurrentText(d['cur_mode'])
|
||||
if not d['edid']:
|
||||
self.txt_edid.setPlainText("EDID 读取失败(注册表无 EDID 数据)")
|
||||
self.txt_modes.clear(); self.txt_hex.clear(); return
|
||||
parsed = edid_parse.parse_edid(d['edid'])
|
||||
self.txt_edid.setPlainText("\n".join(f"{k:<16}{v}" for k, v in edid_parse.edid_info_lines(parsed)))
|
||||
lines = [f"{t['hact']}x{t['vact']} @{t['refresh']:g}Hz {t['clk_khz'] / 1000:.2f}MHz {'DTD 首选' if i == 0 else 'DTD'}" for i, t in enumerate(parsed['dtds'])]
|
||||
lines += [f"{m} [CEA-VIC]" for m in parsed['cea_video']]
|
||||
lines += [f"{m} [已建立时序]" for m in parsed['est']]
|
||||
lines += [f"{m} [标准时序]" for m in parsed['std']]
|
||||
self.txt_modes.setPlainText("\n".join(lines))
|
||||
self.txt_hex.setPlainText(edid_parse.hex_dump(d['edid']))
|
||||
|
||||
def _apply_mode(self):
|
||||
d = self._cur_display()
|
||||
if d is None or self.cbo_mode.currentText() not in self._modes:
|
||||
return
|
||||
device = d['device']
|
||||
if device not in self._orig_modes:
|
||||
current = display_win.DEVMODEW(); current.dmSize = ctypes.sizeof(current)
|
||||
if display_win.user32.EnumDisplaySettingsW(device, display_win.ENUM_CURRENT_SETTINGS, ctypes.byref(current)):
|
||||
self._orig_modes[device] = current
|
||||
ok, result = display_win.apply_mode(device, self._modes[self.cbo_mode.currentText()])
|
||||
if not ok:
|
||||
self.notice("切换失败", f"ChangeDisplaySettingsEx 返回码 {result}", error=True)
|
||||
return
|
||||
QTimer.singleShot(500, self._load_displays)
|
||||
|
||||
def _restore_mode(self):
|
||||
d = self._cur_display()
|
||||
if d is None: return
|
||||
mode = self._orig_modes.pop(d['device'], None)
|
||||
if mode is None:
|
||||
self.notice("无可恢复", "该显示器没有记录切改前的模式")
|
||||
return
|
||||
display_win.apply_mode(d['device'], mode)
|
||||
QTimer.singleShot(500, self._load_displays)
|
||||
|
||||
def _show_pattern(self, kind):
|
||||
d = self._cur_display()
|
||||
if d and d['rect']:
|
||||
close_qt_patterns(); PatternWindow(d['rect'], kind, self.cbo_area.currentText(), parent=self)
|
||||
|
||||
def _show_solid(self, color):
|
||||
self._show_pattern(color)
|
||||
|
||||
def _save_area(self, value):
|
||||
self.area = value
|
||||
config.save_slots(self.slots, value)
|
||||
|
||||
def _show_custom(self, index):
|
||||
slot = self.slots[index]
|
||||
if not slot['file']:
|
||||
self.notice("未配置图片", f"请先配置“{slot['name']}”的图片")
|
||||
return
|
||||
path = os.path.join(config.BASE_DIR, slot['file'])
|
||||
d = self._cur_display()
|
||||
if not os.path.exists(path):
|
||||
self.notice("图片不存在", path, error=True); return
|
||||
if d and d['rect']:
|
||||
close_qt_patterns(); PatternWindow(d['rect'], "", self.cbo_area.currentText(), path, self)
|
||||
|
||||
def _configure_slot(self, index):
|
||||
dialog = QDialog(self); dialog.setWindowTitle(f"配置自定义栏位 {index + 1}")
|
||||
form = QFormLayout(dialog)
|
||||
name = LineEdit(dialog); name.setText(self.slots[index]['name'])
|
||||
file_label = BodyLabel(self.slots[index]['file'] or "(未设置)", dialog)
|
||||
form.addRow("按钮名称", name); form.addRow("图片文件", file_label)
|
||||
buttons = QHBoxLayout(); choose = PushButton("选择图片...", dialog); clear = PushButton("清除图片", dialog); save = PrimaryPushButton("保存", dialog); cancel = PushButton("取消", dialog)
|
||||
buttons.addWidget(choose); buttons.addWidget(clear); buttons.addStretch(1); buttons.addWidget(save); buttons.addWidget(cancel); form.addRow(buttons)
|
||||
selected = [self.slots[index]['file']]
|
||||
def choose_file():
|
||||
path, _ = QFileDialog.getOpenFileName(dialog, "选择图片", config.BASE_DIR, f"图片文件 ({' '.join('*' + e for e in config.IMG_EXTS)})")
|
||||
if path:
|
||||
try: selected[0] = config.copy_image_into_script_dir(path); file_label.setText(selected[0])
|
||||
except OSError as exc: self.notice("复制图片失败", str(exc), error=True)
|
||||
choose.clicked.connect(choose_file); clear.clicked.connect(lambda: (selected.__setitem__(0, None), file_label.setText("(未设置)")))
|
||||
cancel.clicked.connect(dialog.reject)
|
||||
def save_slot():
|
||||
self.slots[index] = {'name': name.text().strip() or f'自定义{index + 1}', 'file': selected[0]}
|
||||
config.save_slots(self.slots, self.cbo_area.currentText()); self.slot_buttons[index].setText(self.slots[index]['name']); dialog.accept()
|
||||
save.clicked.connect(save_slot); dialog.exec()
|
||||
|
||||
def _show_about(self):
|
||||
QMessageBox.about(self, f"关于 {APP_NAME}", f"{APP_NAME} v{APP_VERSION}\n\nEDID / 测试图案 / RS485 光机控制\nPySide6-Fluent-Widgets UI\n\n{REPO_URL}")
|
||||
|
||||
def _show_edid_fields(self):
|
||||
d = self._cur_display()
|
||||
if d is None or not d['edid']:
|
||||
self.notice("无 EDID", "该显示器没有可解析的 EDID 数据"); return
|
||||
dialog = QDialog(self); dialog.setWindowTitle("EDID 逐字节解析"); dialog.resize(1120, 700)
|
||||
layout = QVBoxLayout(dialog); text = self._text(); text.setLineWrapMode(QPlainTextEdit.WidgetWidth)
|
||||
lines = []
|
||||
for off, hx, meaning, value, note in edid_parse.edid_field_rows(d['edid']):
|
||||
lines.append(f"{off} {meaning} {value}")
|
||||
if hx: lines.append(f" 原始: {hx}")
|
||||
if note: lines.append(f" {note}")
|
||||
text.setPlainText("\n".join(lines)); layout.addWidget(text); layout.addWidget(self._button("关闭", dialog.accept)); dialog.exec()
|
||||
|
||||
# ---------------- RS485 ----------------
|
||||
def _dlpc_on_frame(self, frame):
|
||||
if self._pd_seq: self._dlpc_log_q.put(('pdframe', frame))
|
||||
elif self._pwr_seq: self._dlpc_log_q.put(('pwrframe', frame))
|
||||
|
||||
def _dlpc_on_event(self, line):
|
||||
match = re.search(r'← okTL:(-?\d+)', line)
|
||||
if match and self._tl_order:
|
||||
which = self._tl_order.pop(0); self._dlpc_log_q.put(('temp', f"{which}: {int(match.group(1)) / 10:.1f}°C"))
|
||||
match = re.search(r'← okR(\d+)G(\d+)B(\d+)', line)
|
||||
if match: self._dlpc_log_q.put(('current', f"电流 R:{match.group(1)} G:{match.group(2)} B:{match.group(3)}"))
|
||||
self._dlpc_log_q.put(('event', line))
|
||||
|
||||
def _dlpc_on_status(self, message): self._dlpc_log_q.put(('status', message))
|
||||
def _query_current(self): self._dlpc_send('M732')
|
||||
def _query_dmd(self): self._tl_order.append('DMD'); self._dlpc_send('M201')
|
||||
def _query_lamp(self): self._tl_order.append('LAMP'); self._dlpc_send('M202')
|
||||
|
||||
def _poll_dlpc(self):
|
||||
while True:
|
||||
try:
|
||||
kind, value = self._dlpc_log_q.get_nowait()
|
||||
except queue.Empty:
|
||||
break
|
||||
try:
|
||||
if kind == 'status':
|
||||
self.lbl_dlpc_st.setText(value)
|
||||
if value.startswith(('已断开', '串口丢失')): self._serial_reset_state()
|
||||
elif kind == 'temp': (self.var_dmd if value.startswith('DMD') else self.var_lamp).setText(value)
|
||||
elif kind == 'current': self.var_current.setText(value)
|
||||
elif kind == 'pdframe': self._pd_step_done(value.type_code == 0xF0, value)
|
||||
elif kind == 'pwrframe': self._pwr_step_done(value)
|
||||
else: self._dlpc_log(value)
|
||||
except Exception:
|
||||
# 单条事件处理异常只打栈放弃该条, 不得中断本轮消费——否则积压随事件流
|
||||
# 单调增长(v0.4.3 前日志裁剪异常即此路径, 显示延迟越跑越大)
|
||||
traceback.print_exc()
|
||||
connected = self.dlpc.is_connected()
|
||||
if connected != self._dlpc_connected:
|
||||
self._dlpc_connected = connected; self.btn_dlpc.setText("断开" if connected else "连接")
|
||||
|
||||
def _dlpc_log(self, line):
|
||||
self.txt_dlpc.appendPlainText(time.strftime('%H:%M:%S ') + line)
|
||||
self.txt_dlpc.verticalScrollBar().setValue(self.txt_dlpc.verticalScrollBar().maximum())
|
||||
|
||||
def _dlpc_clear(self): self.txt_dlpc.clear()
|
||||
def _dlpc_refresh(self):
|
||||
self._dlpc_ports = dlpc_rs485.DLPC485.list_ports_info(); self.cbo_dlpc.clear(); self.cbo_dlpc.addItems([label for _d, label in self._dlpc_ports])
|
||||
if self._dlpc_ports: self._dlpc_pick(config.SERIAL_CFG['port'] or self._dlpc_ports[0][0])
|
||||
def _dlpc_pick(self, device):
|
||||
for dev, label in self._dlpc_ports:
|
||||
if dev == device: self.cbo_dlpc.setCurrentText(label); return
|
||||
def _dlpc_selected_port(self):
|
||||
label = self.cbo_dlpc.currentText()
|
||||
for device, shown in self._dlpc_ports:
|
||||
if shown == label: return device
|
||||
return label.strip()
|
||||
def _dlpc_toggle(self):
|
||||
if self.dlpc.is_connected(): self.dlpc.close(); self._serial_reset_state(); return
|
||||
port = self._dlpc_selected_port()
|
||||
if not port: self.lbl_dlpc_st.setText('未选择串口,请先选择或刷新'); return
|
||||
try: baud, bytesize, stopbits = int(self.cbo_baud.currentText()), int(self.cbo_databits.currentText()), int(self.cbo_stopbits.currentText())
|
||||
except ValueError: self.lbl_dlpc_st.setText("串口参数非法"); return
|
||||
parity = self.cbo_parity.currentText()[:1] or 'N'; config.SERIAL_CFG.update(port=port, baud=baud, bytesize=bytesize, parity=parity, stopbits=stopbits); config.save_slots(self.slots, self.cbo_area.currentText()); self.dlpc.open(port, baud, bytesize=bytesize, parity=parity, stopbits=stopbits)
|
||||
def _serial_reset_state(self):
|
||||
self._pd_seq.clear(); self._pwr_seq.clear(); self._tl_order.clear()
|
||||
for timer in (self._pd_timer, self._pwr_timer):
|
||||
if timer: timer.stop()
|
||||
self._pd_timer = self._pwr_timer = None
|
||||
def _dlpc_send(self, command):
|
||||
if not self.dlpc.is_connected(): self.lbl_dlpc_st.setText('未连接串口'); return
|
||||
if self._pd_seq or self._pwr_seq: self._dlpc_log(f'序列进行中, 命令已忽略: {command}'); return
|
||||
self.dlpc.send(command)
|
||||
def _dlpc_send_preset(self):
|
||||
label = self.cbo_dlpc_cmd.currentText()
|
||||
for name, command in self._dlpc_presets:
|
||||
if label.startswith(name + ' '): self._dlpc_send(command); return
|
||||
def _dlpc_send_custom(self):
|
||||
if self.var_custom_cmd.text().strip(): self._dlpc_send(self.var_custom_cmd.text().strip())
|
||||
|
||||
def _pd_selftest(self):
|
||||
if not self.dlpc.is_connected(): self.lbl_dlpc_st.setText('未连接串口'); return
|
||||
if self._pd_seq: return
|
||||
self._pd_seq = [('M301', 'pd'), ('M302', 'fpdo_ma'), ('M303', 'meas_mv')]; self._pd_values = {}; self._pd_chip_reset(); self._dlpc_log('电源自检: 开始'); self._pd_step_next()
|
||||
def _pd_chip_reset(self):
|
||||
self.chip_pd.setText('PD'); self.chip_pd.setStyleSheet(f'background: {CHIP_IDLE}; color: white; border-radius: 6px; padding: 4px 8px;'); self.chip_fpdo.setText('FPDO: —'); self.chip_fpdo.setStyleSheet(f'background: {CHIP_IDLE}; color: white; border-radius: 6px; padding: 4px 8px;')
|
||||
def _pd_step_next(self):
|
||||
if not self._pd_seq: self._pd_fpdo_verdict(); self._dlpc_log('电源自检: 完成'); return
|
||||
self.dlpc.send(self._pd_seq[0][0]); self._pd_timer = QTimer(self); self._pd_timer.setSingleShot(True); self._pd_timer.timeout.connect(lambda: self._pd_step_done(False, None)); self._pd_timer.start(3000)
|
||||
def _pd_step_done(self, ok, frame):
|
||||
if not self._pd_seq: return
|
||||
if self._pd_timer: self._pd_timer.stop(); self._pd_timer = None
|
||||
_command, kind = self._pd_seq.pop(0); raw = dlpc_rs485.payload_bytes(frame) if frame is not None else b''
|
||||
if ok and kind == 'pd':
|
||||
proto = raw.decode('ascii', 'replace').strip()
|
||||
good = proto in ('PD', 'EPR')
|
||||
self.chip_pd.setText(proto or 'PD')
|
||||
self.chip_pd.setStyleSheet(
|
||||
f'background: {CHIP_OK if good else CHIP_ERR}; color: white; '
|
||||
'border-radius: 6px; padding: 4px 8px;')
|
||||
elif ok and kind == 'fpdo_ma' and len(raw) == 2: self._pd_values['ma'] = dlpc_rs485.payload_u16_be(raw)
|
||||
elif ok and kind == 'meas_mv' and len(raw) == 2: self._pd_values['mv'] = dlpc_rs485.payload_u16_be(raw)
|
||||
if ok: self._pd_step_next()
|
||||
else: self._pd_seq.clear(); self._pd_chip_error(kind); self._dlpc_log('电源自检: 应答错误/超时, 序列中止')
|
||||
def _pd_chip_error(self, kind):
|
||||
widget = self.chip_pd if kind == 'pd' else self.chip_fpdo
|
||||
if kind == 'pd': widget.setText('ERR')
|
||||
else: widget.setText('FPDO: ERR')
|
||||
widget.setStyleSheet(f'background: {CHIP_ERR}; color: white; border-radius: 6px; padding: 4px 8px;')
|
||||
def _pd_fpdo_verdict(self):
|
||||
mv, ma = self._pd_values.get('mv'), self._pd_values.get('ma')
|
||||
if mv is None or ma is None: self._pd_chip_error('fpdo_ma'); return
|
||||
gear = next((g for g in (5, 9, 12, 15, 20, 28) if abs(mv - g * 1000) <= g * 50), None); text = 'FPDO: ERR' if gear is None else f'FPDO: {gear}V@{ma / 1000:g}A'; self.chip_fpdo.setText(text); good = gear == 12 and ma >= 3000; self.chip_fpdo.setStyleSheet(f'background: {CHIP_OK if good else CHIP_ERR}; color: white; border-radius: 6px; padding: 4px 8px;')
|
||||
|
||||
def _pwr_query(self):
|
||||
if not self.dlpc.is_connected(): self.lbl_dlpc_st.setText('未连接串口'); return
|
||||
if self._pwr_seq: return
|
||||
self._pwr_seq = [('M303', 'mv'), ('M304', 'ma'), ('M305', 'mw')]; self._pwr_values = {}; self._dlpc_log('功率检测: 开始'); self._pwr_step_next()
|
||||
def _pwr_step_next(self):
|
||||
if not self._pwr_seq: self._pwr_update(self._pwr_values.get('mv'), self._pwr_values.get('ma'), self._pwr_values.get('mw')); self._dlpc_log('功率检测: 完成'); return
|
||||
self.dlpc.send(self._pwr_seq[0][0]); self._pwr_timer = QTimer(self); self._pwr_timer.setSingleShot(True); self._pwr_timer.timeout.connect(lambda: self._pwr_step_done(None)); self._pwr_timer.start(3000)
|
||||
def _pwr_step_done(self, frame):
|
||||
if not self._pwr_seq: return
|
||||
if self._pwr_timer: self._pwr_timer.stop(); self._pwr_timer = None
|
||||
_command, kind = self._pwr_seq.pop(0); raw = dlpc_rs485.payload_bytes(frame) if frame is not None else b''; want = {'mv': 2, 'ma': 2, 'mw': 4}[kind]
|
||||
if frame is None or frame.type_code != 0xF0 or len(raw) != want: self._pwr_seq.clear(); self.box_pwr.setText('电压: ERR 电流: — 功率: —'); return
|
||||
self._pwr_values[kind] = {'mv': dlpc_rs485.payload_u16_be, 'ma': dlpc_rs485.payload_s16_be, 'mw': dlpc_rs485.payload_u32_be}[kind](raw); self._pwr_step_next()
|
||||
def _pwr_update(self, mv, ma, mw):
|
||||
voltage = f'{mv / 1000:.2f} V' if mv is not None else '—'
|
||||
current = f'{ma} mA' if ma is not None else '—'
|
||||
power = f'{mw / 1000:.2f} W' if mw is not None else '—'
|
||||
self.box_pwr.setText(f'电压: {voltage} 电流: {current} 功率: {power}')
|
||||
def _dlpc_send_light(self): self._sync_slider(self.sld_light, self.ent_light, 54, 800); self._dlpc_send(f'M731S{self.sld_light.value()}')
|
||||
def _dlpc_send_timer(self): self._sync_slider(self.sld_timer, self.ent_timer, 0, 32700); self._dlpc_send('M730S0' if self.sld_timer.value() <= 0 else f'M730S0T{self.sld_timer.value()}')
|
||||
def _dlpc_send_tec(self): self._sync_slider(self.sld_tec, self.ent_tec, 200, 350); self._dlpc_send(f'M8S{self.sld_tec.value()}')
|
||||
|
||||
def notice(self, title, text, error=False):
|
||||
box = QMessageBox(self); box.setWindowTitle(title); box.setText(text); box.setIcon(QMessageBox.Critical if error else QMessageBox.Information); box.exec()
|
||||
|
||||
def closeEvent(self, event):
|
||||
close_qt_patterns()
|
||||
self._serial_reset_state()
|
||||
try: self.dlpc.close()
|
||||
except Exception: pass
|
||||
super().closeEvent(event)
|
||||
|
||||
|
||||
def run_gui(auto_close=0):
|
||||
if not _single_instance():
|
||||
app = QApplication.instance() or QApplication(sys.argv)
|
||||
QMessageBox.information(None, "DLPilot 已在运行", "检测到另一个 DLPilot 实例正在运行。")
|
||||
return
|
||||
app = QApplication.instance() or QApplication(sys.argv)
|
||||
app.setApplicationName(APP_NAME)
|
||||
setTheme(Theme.AUTO)
|
||||
window = App(auto_close)
|
||||
window.show()
|
||||
app.exec()
|
||||
@@ -33,9 +33,15 @@ MONO = ('Consolas', 12)
|
||||
BOLD = ('Microsoft YaHei UI', 13, 'bold')
|
||||
TITLE_FONT = ('Microsoft YaHei UI', 18, 'bold')
|
||||
|
||||
# 电源自检状态位配色: 灰=未检测, 绿=正常回包, 红=错误/超时
|
||||
CHIP_IDLE = ('gray78', 'gray34')
|
||||
CHIP_IDLE_TEXT = ('#333333', '#E8E8E8')
|
||||
CHIP_OK = '#2FA574'
|
||||
CHIP_ERR = '#D9534F'
|
||||
|
||||
APP_NAME = 'DLPilot'
|
||||
APP_VERSION = '0.3.0'
|
||||
REPO_URL = 'https://gitea.hulk.wang/hulk/LT8619C_Debug_Tools'
|
||||
APP_VERSION = '0.3.6'
|
||||
REPO_URL = 'https://gitea.hulk.wang/hulk/HW-Debug-Tools'
|
||||
|
||||
|
||||
def get_icon_path():
|
||||
@@ -57,23 +63,44 @@ def _apply_dropdown_theme():
|
||||
ctk.ThemeManager.theme['DropdownMenu']['text_color'] = ('#1A1A1A', '#DADADA')
|
||||
|
||||
|
||||
def _ensure_single_instance():
|
||||
"""单实例锁(Windows 命名互斥体): 已有实例在运行时返回 False。
|
||||
|
||||
双击 exe 开多个实例时, 只有先启动的能连串口, 后续实例连接报"拒绝访问",
|
||||
且用户往往只看到后开的窗口 —— 表现为"连不上/断不开"。互斥体句柄随
|
||||
进程存活, 进程退出自动释放。"""
|
||||
ERROR_ALREADY_EXISTS = 183
|
||||
ctypes.windll.kernel32.CreateMutexW(None, False, 'hulk.DLPilot.single')
|
||||
return ctypes.windll.kernel32.GetLastError() != ERROR_ALREADY_EXISTS
|
||||
|
||||
|
||||
def run_gui(auto_close=0):
|
||||
"""入口: 配置外观并启动主窗口"""
|
||||
ctk.set_appearance_mode('System')
|
||||
_apply_dropdown_theme()
|
||||
if not _ensure_single_instance():
|
||||
from tkinter import messagebox
|
||||
import tkinter as tk
|
||||
r = tk.Tk()
|
||||
r.withdraw()
|
||||
messagebox.showinfo('DLPilot 已在运行',
|
||||
'检测到另一个 DLPilot 实例正在运行。\n'
|
||||
'请使用已打开的窗口(串口同时只能被一个实例占用)。')
|
||||
return
|
||||
App(auto_close).mainloop()
|
||||
|
||||
|
||||
class App(ctk.CTk):
|
||||
def __init__(self, auto_close=0):
|
||||
super().__init__()
|
||||
self.title('DLPilot — 3D 光固化光机调试台 (EDID · 测试图案 · RS485 光机控制)')
|
||||
self.title(f'DLPilot v{APP_VERSION} — 3D 光固化光机调试台 '
|
||||
f'(EDID · 测试图案 · RS485 光机控制)')
|
||||
try: # 任务栏独立分组
|
||||
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('hulk.DLPilot')
|
||||
except Exception:
|
||||
pass
|
||||
self.geometry('1440x920')
|
||||
self.minsize(1180, 800)
|
||||
self.geometry('1440x1010') # 右列新增电源检查卡, 窗口加高
|
||||
self.minsize(1180, 860)
|
||||
ic = get_icon_path()
|
||||
if ic:
|
||||
try:
|
||||
@@ -88,12 +115,21 @@ class App(ctk.CTk):
|
||||
self._orig_modes = {} # device -> 切改前的原始 DEVMODEW
|
||||
# 光机控制链路: 回调发生在串口线程, 经队列投递回 GUI 主线程轮询
|
||||
self._dlpc_log_q = queue.Queue()
|
||||
self.dlpc = dlpc_rs485.DLPC485(self._dlpc_on_event, self._dlpc_on_status)
|
||||
self.dlpc = dlpc_rs485.DLPC485(self._dlpc_on_event, self._dlpc_on_status,
|
||||
on_frame=self._dlpc_on_frame)
|
||||
self._dlpc_connected = False
|
||||
self._poll_job = None
|
||||
self._tl_order = [] # 温度查询应答顺序: 'DMD'/'LAMP' 先到先得
|
||||
self._pd_seq = [] # 电源自检待执行步骤: [(命令, kind), ...]
|
||||
self._pd_values = {} # 自检采集值: {'ma': 挡位电流, 'mv': 实测电压}
|
||||
self._pd_timer = None # 自检单步超时定时器
|
||||
self._pwr_seq = [] # 功率检测待执行步骤
|
||||
self._pwr_values = {} # 功率检测采集值: {'mv', 'ma'}
|
||||
self._pwr_timer = None
|
||||
self._build()
|
||||
self._load_displays()
|
||||
# 主窗口按 ESC 也能关闭所有投屏(投屏窗口失焦时的兜底出口)
|
||||
self.bind('<Escape>', lambda _e: patterns.close_all())
|
||||
if dlpc_rs485.HAS_SERIAL:
|
||||
self._poll_dlpc()
|
||||
if auto_close > 0:
|
||||
@@ -202,13 +238,17 @@ class App(ctk.CTk):
|
||||
self.txt_modes.configure(state='disabled')
|
||||
|
||||
# -- EDID 信息 --
|
||||
# CTkTextbox 而非 CTkScrollableFrame+逐行 Label: 后者 40+ 个画布控件,
|
||||
# 窗口最大化时逐个重绘是卡顿主因; 文本框整体重排, 开销低一个量级
|
||||
card, c = self._card(col, 'EDID 信息')
|
||||
card.grid(row=2, column=0, sticky='nsew', pady=(10, 0))
|
||||
self.edid_scroll = ctk.CTkScrollableFrame(c, height=150)
|
||||
self.edid_scroll.pack(fill='both', expand=True)
|
||||
self.txt_edid = ctk.CTkTextbox(c, font=MONO, wrap='none')
|
||||
self.txt_edid.pack(fill='both', expand=True)
|
||||
self.txt_edid.configure(state='disabled')
|
||||
|
||||
# -- 测试图案 --
|
||||
card, c = self._card(col,'测试图案 — 黑底 1:1 居中, 按 ESC 退出')
|
||||
card, c = self._card(col,'测试图案 — 黑底 1:1 居中, 投屏按 ESC 或"停止测试图像"退出',
|
||||
button='停止测试图像', command=patterns.close_all)
|
||||
card.grid(row=3, column=0, sticky='ew', pady=(10, 0))
|
||||
row1 = ctk.CTkFrame(c, fg_color='transparent')
|
||||
row1.pack(fill='x')
|
||||
@@ -315,6 +355,39 @@ class App(ctk.CTk):
|
||||
self._dlpc_log('帧格式: D5 01 LEN <命令> CRC / B5 TYPE LEN <payload> CRC, '
|
||||
'累加和校验; 全部命令见 README"光机控制"')
|
||||
|
||||
# -- 电源检查 --
|
||||
# 网格对齐两行: col2 为读数框列(weight=1) -> FPDO 色框与功率黑框
|
||||
# 起止位置完全一致(等长), 且随窗口拉伸自适应
|
||||
card, c = self._card(col, '电源检查 — PD 自检 / 功率读数')
|
||||
card.grid(row=2, column=0, sticky='ew', pady=(10, 0))
|
||||
pwr_grid = ctk.CTkFrame(c, fg_color='transparent')
|
||||
pwr_grid.pack(fill='x')
|
||||
pwr_grid.grid_columnconfigure(2, weight=1)
|
||||
ctk.CTkButton(pwr_grid, text='电源自检', width=90,
|
||||
command=self._pd_selftest).grid(row=0, column=0, sticky='w')
|
||||
proto_cell = ctk.CTkFrame(pwr_grid, fg_color='transparent')
|
||||
proto_cell.grid(row=0, column=1, sticky='w', padx=(10, 0))
|
||||
ctk.CTkLabel(proto_cell, text='协议:').pack(side='left', padx=(0, 4))
|
||||
self.chip_pd = ctk.CTkLabel(proto_cell, text='PD', width=60, height=26,
|
||||
corner_radius=6, fg_color=CHIP_IDLE,
|
||||
text_color=CHIP_IDLE_TEXT)
|
||||
self.chip_pd.pack(side='left')
|
||||
self.var_fpdo = tk.StringVar(value='FPDO: —')
|
||||
self.chip_fpdo = ctk.CTkLabel(pwr_grid, textvariable=self.var_fpdo,
|
||||
height=26, corner_radius=6,
|
||||
fg_color=CHIP_IDLE,
|
||||
text_color=CHIP_IDLE_TEXT, anchor='w', padx=8)
|
||||
self.chip_fpdo.grid(row=0, column=2, sticky='ew', padx=(12, 0))
|
||||
ctk.CTkButton(pwr_grid, text='功率检测', width=90,
|
||||
command=self._pwr_query).grid(row=1, column=0,
|
||||
sticky='w', pady=(6, 0))
|
||||
self.var_pwr = tk.StringVar(value='电压: — 电流: — 功率: —')
|
||||
self.box_pwr = ctk.CTkLabel(pwr_grid, textvariable=self.var_pwr,
|
||||
height=26, corner_radius=6,
|
||||
fg_color=('#F2F2F2', '#181818'),
|
||||
anchor='w', padx=8)
|
||||
self.box_pwr.grid(row=1, column=2, sticky='ew', padx=(8, 0), pady=(6, 0))
|
||||
|
||||
# -- 光机命令 --
|
||||
# 标题行右侧: 电流实时读数 + 查电流按钮(okR..G..B.. 应答解析)
|
||||
cur_frame = ctk.CTkFrame(self, fg_color='transparent')
|
||||
@@ -325,7 +398,7 @@ class App(ctk.CTk):
|
||||
command=self._query_current).pack(side='left', padx=(6, 0))
|
||||
card, c = self._card(col,'光机命令 — 预设 / 自定义 / TEC',
|
||||
right_widget=cur_frame)
|
||||
card.grid(row=2, column=0, sticky='ew', pady=(10, 0))
|
||||
card.grid(row=3, column=0, sticky='ew', pady=(10, 0))
|
||||
row1 = ctk.CTkFrame(c, fg_color='transparent')
|
||||
row1.pack(fill='x')
|
||||
for name, cmd in (('开光机', 'M730S0'), ('关光机', 'M730S1'),
|
||||
@@ -382,7 +455,7 @@ class App(ctk.CTk):
|
||||
|
||||
# -- 快捷滑条 --
|
||||
card, c = self._card(col,'快捷滑条 — 光强 / 定时投光 / TEC 温度')
|
||||
card.grid(row=3, column=0, sticky='ew', pady=(10, 0))
|
||||
card.grid(row=4, column=0, sticky='ew', pady=(10, 0))
|
||||
rowa = ctk.CTkFrame(c, fg_color='transparent')
|
||||
rowa.pack(fill='x')
|
||||
ctk.CTkLabel(rowa, text='光强(54-800):').pack(side='left')
|
||||
@@ -499,16 +572,13 @@ class App(ctk.CTk):
|
||||
self._set_text(self.txt_hex, edid_parse.hex_dump(d['edid']))
|
||||
|
||||
def _clear_edid_rows(self):
|
||||
for w in self.edid_scroll.winfo_children():
|
||||
w.destroy()
|
||||
self._set_text(self.txt_edid, '')
|
||||
|
||||
def _add_edid_row(self, k, v):
|
||||
row = ctk.CTkFrame(self.edid_scroll, fg_color='transparent')
|
||||
row.pack(fill='x', pady=1)
|
||||
ctk.CTkLabel(row, text=k, width=132, anchor='w',
|
||||
text_color='gray60').pack(side='left')
|
||||
ctk.CTkLabel(row, text=v, anchor='w').pack(side='left',
|
||||
fill='x', expand=True)
|
||||
self.txt_edid.configure(state='normal')
|
||||
self.txt_edid.insert('end', f'{k:<16}{v}\n')
|
||||
self.txt_edid.see('end')
|
||||
self.txt_edid.configure(state='disabled')
|
||||
|
||||
def _apply_mode(self):
|
||||
d = self._cur_display()
|
||||
@@ -676,6 +746,13 @@ class App(ctk.CTk):
|
||||
# ============================================================
|
||||
# 光机控制(RS485)
|
||||
# ============================================================
|
||||
def _dlpc_on_frame(self, fr):
|
||||
"""结构化应答帧(串口线程): 电源自检/功率检测序列进行中时路由给状态机"""
|
||||
if self._pd_seq:
|
||||
self._dlpc_log_q.put(('pdframe', fr))
|
||||
elif self._pwr_seq:
|
||||
self._dlpc_log_q.put(('pwrframe', fr))
|
||||
|
||||
def _dlpc_on_event(self, line):
|
||||
# 温度查询应答: okTL:<0.1°C>, 依发送顺序归入 DMD/LAMP 实时显示框
|
||||
m = re.search(r'← okTL:(-?\d+)', line)
|
||||
@@ -721,6 +798,8 @@ class App(ctk.CTk):
|
||||
else:
|
||||
color = 'gray60'
|
||||
self.lbl_dlpc_st.configure(text=text, text_color=color)
|
||||
if text.startswith(('已断开', '串口丢失')):
|
||||
self._serial_reset_state()
|
||||
elif kind == 'temp':
|
||||
if text.startswith('DMD'):
|
||||
self.var_dmd.set(text)
|
||||
@@ -728,6 +807,11 @@ class App(ctk.CTk):
|
||||
self.var_lamp.set(text)
|
||||
elif kind == 'current':
|
||||
self.var_current.set(text)
|
||||
elif kind == 'pdframe':
|
||||
self._pd_step_done(text.type_code == 0xF0, text)
|
||||
elif kind == 'pwrframe':
|
||||
self._pwr_step_done(text)
|
||||
else:
|
||||
self._dlpc_log(text)
|
||||
except queue.Empty:
|
||||
pass
|
||||
@@ -774,6 +858,7 @@ class App(ctk.CTk):
|
||||
def _dlpc_toggle(self):
|
||||
if self.dlpc.is_connected():
|
||||
self.dlpc.close()
|
||||
self._serial_reset_state() # 断开时清序列/定时器/应答归位, 防旧账错配
|
||||
return
|
||||
port = self._dlpc_selected_port()
|
||||
if not port:
|
||||
@@ -792,10 +877,28 @@ class App(ctk.CTk):
|
||||
config.save_slots(self.slots, self.area_var.get()) # 记住本次串口
|
||||
self.dlpc.open(port, baud, bytesize=bytesize, parity=parity, stopbits=stopbits)
|
||||
|
||||
def _serial_reset_state(self):
|
||||
"""断开/失连时清理进行中的序列与应答归位队列(不碰串口线程本身)"""
|
||||
self._pd_seq.clear()
|
||||
self._pwr_seq.clear()
|
||||
for t in (self._pd_timer, self._pwr_timer):
|
||||
if t:
|
||||
try:
|
||||
self.after_cancel(t)
|
||||
except Exception:
|
||||
pass
|
||||
self._pd_timer = self._pwr_timer = None
|
||||
self._tl_order.clear()
|
||||
|
||||
def _dlpc_send(self, cmd):
|
||||
if not self.dlpc.is_connected():
|
||||
self.lbl_dlpc_st.configure(text='未连接串口', text_color='#E07A3F')
|
||||
return
|
||||
if self._pd_seq or self._pwr_seq:
|
||||
# 序列进行中: 手动命令的应答帧会被序列错认领(它不区分应答属于哪条
|
||||
# 命令, 来一帧消费一步), 值会错位 —— 拒绝并提示, 序列结束再发
|
||||
self._dlpc_log(f'序列进行中, 命令已忽略: {cmd}')
|
||||
return
|
||||
self.dlpc.send(cmd)
|
||||
|
||||
def _dlpc_send_preset(self):
|
||||
@@ -810,6 +913,141 @@ class App(ctk.CTk):
|
||||
if cmd:
|
||||
self._dlpc_send(cmd)
|
||||
|
||||
# -- 电源检查: 自检序列 + 功率读数 --
|
||||
|
||||
def _pd_selftest(self):
|
||||
"""电源自检: 依序 M301(协议) → M302(挡位最大电流) → M303(实测母线电压),
|
||||
应答帧驱动序列前进(成功=TYPE 0xF0), 结束后按 _pd_fpdo_verdict 判定 FPDO"""
|
||||
if not self.dlpc.is_connected():
|
||||
self.lbl_dlpc_st.configure(text='未连接串口', text_color='#E07A3F')
|
||||
return
|
||||
if self._pd_seq:
|
||||
return # 进行中, 忽略重复触发
|
||||
self._pd_seq = [('M301', 'pd'), ('M302', 'fpdo_ma'), ('M303', 'meas_mv')]
|
||||
self._pd_values = {}
|
||||
self._pd_chip_reset()
|
||||
self._dlpc_log('电源自检: 开始')
|
||||
self._pd_step_next()
|
||||
|
||||
def _pd_chip_reset(self):
|
||||
self.chip_pd.configure(fg_color=CHIP_IDLE,
|
||||
text_color=CHIP_IDLE_TEXT, text='PD')
|
||||
self.chip_fpdo.configure(fg_color=CHIP_IDLE, text_color=CHIP_IDLE_TEXT)
|
||||
self.var_fpdo.set('FPDO: —')
|
||||
|
||||
def _pd_step_next(self):
|
||||
if not self._pd_seq:
|
||||
self._pd_fpdo_verdict()
|
||||
self._dlpc_log('电源自检: 完成')
|
||||
return
|
||||
self.dlpc.send(self._pd_seq[0][0])
|
||||
self._pd_timer = self.after(3000, lambda: self._pd_step_done(False, None))
|
||||
|
||||
def _pd_step_done(self, ok, fr):
|
||||
if not self._pd_seq:
|
||||
return
|
||||
if self._pd_timer:
|
||||
self.after_cancel(self._pd_timer)
|
||||
self._pd_timer = None
|
||||
cmd, kind = self._pd_seq.pop(0)
|
||||
raw = dlpc_rs485.payload_bytes(fr) if fr is not None else b''
|
||||
if ok and kind == 'pd':
|
||||
proto = raw.decode('ascii', 'replace').strip()
|
||||
good = proto in ('PD', 'EPR')
|
||||
self.chip_pd.configure(fg_color=CHIP_OK if good else CHIP_ERR,
|
||||
text_color='#FFFFFF', text=proto or 'PD')
|
||||
elif ok and kind == 'fpdo_ma' and len(raw) == 2:
|
||||
self._pd_values['ma'] = dlpc_rs485.payload_u16_be(raw)
|
||||
elif ok and kind == 'meas_mv' and len(raw) == 2:
|
||||
self._pd_values['mv'] = dlpc_rs485.payload_u16_be(raw)
|
||||
if ok:
|
||||
self._pd_step_next()
|
||||
else: # 出错即中止
|
||||
self._pd_seq.clear()
|
||||
if kind == 'pd':
|
||||
self.chip_pd.configure(fg_color=CHIP_ERR, text_color='#FFFFFF',
|
||||
text='ERR')
|
||||
elif kind == 'fpdo_ma':
|
||||
self.chip_fpdo.configure(fg_color=CHIP_ERR, text_color='#FFFFFF')
|
||||
self.var_fpdo.set('FPDO: ERR')
|
||||
self._dlpc_log('电源自检: 应答错误/超时, 序列中止')
|
||||
|
||||
def _pd_fpdo_verdict(self):
|
||||
"""FPDO 判定: 电压挡位由 M303 实测母线电压就近判定(标准 PD 固定挡
|
||||
5/9/12/15/20/28V, 容差 ±5%; CH224Q 0x0A 只写不可读, 挡位只能实测判定),
|
||||
电流为 M302 挡位最大电流。默认挡 12V 且 ≥3A -> 绿底;
|
||||
挡位不符(如 9V 挡) -> 红底; 实测电压不落在任何标准挡 -> ERR"""
|
||||
mv = self._pd_values.get('mv')
|
||||
ma = self._pd_values.get('ma')
|
||||
if mv is None or ma is None:
|
||||
self.chip_fpdo.configure(fg_color=CHIP_ERR, text_color='#FFFFFF')
|
||||
self.var_fpdo.set('FPDO: ERR')
|
||||
return
|
||||
gear = next((g for g in (5, 9, 12, 15, 20, 28)
|
||||
if abs(mv - g * 1000) <= g * 50), None) # ±5% = g*50 mV
|
||||
a_txt = f'{ma / 1000:g}'
|
||||
if gear is None:
|
||||
self.chip_fpdo.configure(fg_color=CHIP_ERR, text_color='#FFFFFF')
|
||||
self.var_fpdo.set('FPDO: ERR')
|
||||
elif gear == 12 and ma >= 3000:
|
||||
self.chip_fpdo.configure(fg_color=CHIP_OK, text_color='#FFFFFF')
|
||||
self.var_fpdo.set(f'FPDO: 12V@{a_txt}A')
|
||||
else:
|
||||
self.chip_fpdo.configure(fg_color=CHIP_ERR, text_color='#FFFFFF')
|
||||
self.var_fpdo.set(f'FPDO: {gear}V@{a_txt}A')
|
||||
|
||||
def _pwr_query(self):
|
||||
"""功率检测: M303 电压 + M304 电流(按有符号) + M305 功率(u32 mW)"""
|
||||
if not self.dlpc.is_connected():
|
||||
self.lbl_dlpc_st.configure(text='未连接串口', text_color='#E07A3F')
|
||||
return
|
||||
if self._pwr_seq:
|
||||
return
|
||||
self._pwr_seq = [('M303', 'mv'), ('M304', 'ma'), ('M305', 'mw')]
|
||||
self._pwr_values = {}
|
||||
self._dlpc_log('功率检测: 开始')
|
||||
self._pwr_step_next()
|
||||
|
||||
def _pwr_step_next(self):
|
||||
if not self._pwr_seq:
|
||||
self._pwr_update(self._pwr_values.get('mv'),
|
||||
self._pwr_values.get('ma'),
|
||||
self._pwr_values.get('mw'))
|
||||
self._dlpc_log('功率检测: 完成')
|
||||
return
|
||||
self.dlpc.send(self._pwr_seq[0][0])
|
||||
self._pwr_timer = self.after(3000, lambda: self._pwr_step_done(None))
|
||||
|
||||
def _pwr_step_done(self, fr):
|
||||
if not self._pwr_seq:
|
||||
return
|
||||
if self._pwr_timer:
|
||||
self.after_cancel(self._pwr_timer)
|
||||
self._pwr_timer = None
|
||||
cmd, kind = self._pwr_seq.pop(0)
|
||||
# 各步载荷长度: 电压/电流 2 字节, 功率 4 字节(u32)
|
||||
want_len = {'mv': 2, 'ma': 2, 'mw': 4}[kind]
|
||||
raw = dlpc_rs485.payload_bytes(fr) if fr is not None else b''
|
||||
if fr is None or fr.type_code != 0xF0 or len(raw) != want_len:
|
||||
self._pwr_seq.clear()
|
||||
self.var_pwr.set('电压: ERR 电流: — 功率: —')
|
||||
self._dlpc_log('功率检测: 应答错误/超时, 中止')
|
||||
return
|
||||
if kind == 'mv':
|
||||
self._pwr_values['mv'] = dlpc_rs485.payload_u16_be(raw)
|
||||
elif kind == 'ma':
|
||||
self._pwr_values['ma'] = dlpc_rs485.payload_s16_be(raw)
|
||||
elif kind == 'mw':
|
||||
self._pwr_values['mw'] = dlpc_rs485.payload_u32_be(raw)
|
||||
self._pwr_step_next()
|
||||
|
||||
def _pwr_update(self, v_mv, ma, mw):
|
||||
"""功率读数框更新: 电压 V / 电流 mA / 功率 W(mW 换算, 两位小数; 缺项显示 —)"""
|
||||
v = f'{v_mv / 1000:.2f} V' if v_mv is not None else '—'
|
||||
a = f'{ma} mA' if ma is not None else '—'
|
||||
w = f'{mw / 1000:.2f} W' if mw is not None else '—'
|
||||
self.var_pwr.set(f'电压: {v} 电流: {a} 功率: {w}')
|
||||
|
||||
def _light_entry_apply(self, _evt=None):
|
||||
"""滑条数值输入框回车: 校验并限幅 54-800, 同步回滑条"""
|
||||
try:
|
||||
@@ -875,9 +1113,13 @@ class App(ctk.CTk):
|
||||
self._dlpc_send(f'M8S{v}')
|
||||
|
||||
def destroy(self):
|
||||
try: # 取消待触发的轮询回调, 避免销毁后 Tcl 报错
|
||||
try: # 取消待触发的轮询/自检/功率超时回调, 避免销毁后 Tcl 报错
|
||||
if self._poll_job:
|
||||
self.after_cancel(self._poll_job)
|
||||
if self._pd_timer:
|
||||
self.after_cancel(self._pd_timer)
|
||||
if self._pwr_timer:
|
||||
self.after_cancel(self._pwr_timer)
|
||||
except Exception:
|
||||
pass
|
||||
try: # 两种退出路径(关窗/--seconds 自动关)都收掉串口线程
|
||||
@@ -3,8 +3,8 @@
|
||||
"""
|
||||
把 hdmi_gui.py 打包成单文件 exe(工具名: DLPilot)
|
||||
================================
|
||||
使用 PyInstaller --onefile --noconsole: Python 解释器 + 标准库 + tkinter
|
||||
全部打进一个 exe, 目标机器无需安装任何依赖。
|
||||
使用 PyInstaller --onefile --noconsole: Python 解释器、PySide6 和
|
||||
PySide6-Fluent-Widgets 全部打进一个 exe, 目标机器无需安装依赖。
|
||||
|
||||
用法:
|
||||
python build_exe.py 自动安装 PyInstaller(如缺)并打包
|
||||
@@ -35,12 +35,21 @@ def ensure_pyinstaller():
|
||||
|
||||
|
||||
def extra_collect_args():
|
||||
"""CustomTkinter 的主题/字体等数据文件必须显式收集, 否则打包后 GUI 启动报错"""
|
||||
"""Fluent Widgets 的主题资源必须收集; PyInstaller 自带 Qt hooks 会处理 PySide6。"""
|
||||
try:
|
||||
import customtkinter # noqa: F401
|
||||
return ['--collect-all', 'customtkinter']
|
||||
import qfluentwidgets # noqa: F401
|
||||
except ImportError:
|
||||
print('警告: 未安装 customtkinter, 打包产物将无法启动 GUI!')
|
||||
print('警告: 未安装 PySide6-Fluent-Widgets, 请先执行 pip install PySide6-Fluent-Widgets')
|
||||
return []
|
||||
return ['--collect-all', 'qfluentwidgets']
|
||||
|
||||
|
||||
def qt_icu_args():
|
||||
"""Qt6Core imports the unversioned Windows ICU API. PyInstaller can
|
||||
otherwise pick Poppler's ICU 78 from PATH, whose suffixed exports make
|
||||
QtCore.pyd fail with WinError 127 on startup."""
|
||||
if os.name == 'nt' and os.path.exists(r'C:\Windows\System32\icuuc.dll'):
|
||||
return ['--add-binary', r'C:\Windows\System32\icuuc.dll;.']
|
||||
return []
|
||||
|
||||
|
||||
@@ -68,7 +77,7 @@ def build(name, extra_args):
|
||||
cmd = [sys.executable, '-m', 'PyInstaller',
|
||||
'--onefile', '--clean', '--name', name,
|
||||
'--distpath', dist, '--workpath', work, '--specpath', work,
|
||||
] + extra_args + extra_collect_args() + [os.path.join(SRC, 'hdmi_gui.py')]
|
||||
] + extra_args + extra_collect_args() + qt_icu_args() + [os.path.join(SRC, 'hdmi_gui.py')]
|
||||
if os.path.exists(ICO):
|
||||
# exe 文件图标 + 运行时窗口图标资源(从 _MEIPASS 读取)
|
||||
cmd += ['--icon', ICO, '--add-data', f'{ICO};.']
|
||||
@@ -7,7 +7,9 @@ DLPC3421 光机 RS485 控制链路(板上 GD32E230 作 RS485→I2C 网关)
|
||||
响应语义/错误码/就绪门禁与实测帧示例):
|
||||
物理层 RS485 半双工 115200 8N1(PC 经 USB-RS485 转换器接板, DE 由 MCU 硬件换向)
|
||||
命令帧 D5 01 LEN <ASCII命令> CRC 01=板类型, LEN=命令字节数
|
||||
响应帧 B5 TYPE LEN <payload> CRC payload 为 ASCII(ok / err:OL / okTL:246 ...)
|
||||
响应帧 B5 TYPE LEN <payload> CRC payload 为 ASCII(ok / err:OL / okTL:246 ...),
|
||||
例外: M303/M304/M305 载荷为大端二进制
|
||||
(SQ52205 电源实测, 见 POWER_COMMANDS)
|
||||
CRC 帧内第 2 字节(板类型)起累加到最后一个 payload 字节, 取低 8 位
|
||||
帧长 最小 6 字节, 最大 32 字节
|
||||
就绪门禁: DLPC3421 启动完成前 M730/M731/M732 被拒(回 0xFF), 属预期。
|
||||
@@ -81,6 +83,53 @@ PRESETS = (
|
||||
Frame = collections.namedtuple('Frame', 'type_code payload raw')
|
||||
|
||||
|
||||
# --- M303/M304/M305(SQ52205 电源实测值查询): 成功载荷为原始二进制(非 ASCII) ---
|
||||
# M303 母线电压: u16 大端, 单位 mV; 12V 轨正常窗口 11400~12600(标称 ±5%)
|
||||
# M304 负载电流: s16 大端补码, 单位 mA; 正=正向, 负=反向(固件原样上总线,
|
||||
# 上位机必须按有符号解析)。例: 载荷 FF 06 = -250 mA
|
||||
# M305 负载功率: u32 大端(LEN=4, 勿复用双字节解析), 单位 mW, 恒非负;
|
||||
# 量程约 0~295000 mW; 能量方向看 M304 符号
|
||||
# 错误时 TYPE=0xFF, 载荷为错误信息字节串(走通用译码路径)
|
||||
POWER_COMMANDS = ('M303', 'M304', 'M305')
|
||||
|
||||
|
||||
def payload_bytes(fr):
|
||||
"""响应帧的原始载荷字节(Frame.payload 是 ASCII 解码视图, 二进制载荷请用本函数)"""
|
||||
return fr.raw[3:-1]
|
||||
|
||||
|
||||
def payload_u16_be(raw):
|
||||
return (raw[0] << 8) | raw[1]
|
||||
|
||||
|
||||
def payload_s16_be(raw):
|
||||
v = payload_u16_be(raw)
|
||||
return v - 0x10000 if v & 0x8000 else v
|
||||
|
||||
|
||||
def payload_u32_be(raw):
|
||||
return (raw[0] << 24) | (raw[1] << 16) | (raw[2] << 8) | raw[3]
|
||||
|
||||
|
||||
def format_power(cmd, fr):
|
||||
"""电源实测命令成功应答 -> 人读文本; 非电源命令/失败/载荷异常返回 None"""
|
||||
if cmd not in POWER_COMMANDS:
|
||||
return None
|
||||
raw = payload_bytes(fr)
|
||||
if cmd == 'M305':
|
||||
if fr.type_code != 0xF0 or len(raw) != 4:
|
||||
return None
|
||||
mw = payload_u32_be(raw)
|
||||
return f'{mw} mW ({mw / 1000:.2f} W)'
|
||||
if fr.type_code != 0xF0 or len(raw) != 2:
|
||||
return None
|
||||
if cmd == 'M303':
|
||||
mv = payload_u16_be(raw)
|
||||
return f'{mv} mV ({mv / 1000:.2f} V)'
|
||||
ma = payload_s16_be(raw)
|
||||
return f'{ma:+d} mA'
|
||||
|
||||
|
||||
def sum_crc(data):
|
||||
"""帧内第 2 字节(板类型)起累加到末 payload 字节, 取低 8 位(不含包头与 CRC)"""
|
||||
return sum(data) & 0xFF
|
||||
@@ -136,15 +185,29 @@ class FrameParser:
|
||||
del self._buf[:1]
|
||||
|
||||
|
||||
def _clean(s):
|
||||
"""控制字符 -> '·': 二进制载荷按 ASCII 解出的 NUL 等会污染日志行,
|
||||
且 Windows 剪贴板遇 NUL 直接截断复制内容"""
|
||||
return ''.join(c if ord(c) >= 0x20 and ord(c) != 0x7F else '·' for c in s)
|
||||
|
||||
|
||||
def describe(fr):
|
||||
"""响应帧 -> 人读文本: TYPE 译码 + payload, err:N 追加 DLPC 错误释义"""
|
||||
"""响应帧 -> 人读文本: TYPE 译码 + payload, err:N 追加 DLPC 错误释义。
|
||||
|
||||
二进制载荷(M303/M304/M305 电源实测)不以 ASCII 展示 —— 改显 hex,
|
||||
避免乱码与 NUL 截断剪贴板(值由 GUI 读数框/CLI format_power 译码)。"""
|
||||
pl = fr.payload
|
||||
if any(ord(c) < 0x20 or ord(c) == 0x7F for c in pl):
|
||||
pl = f'[二进制载荷 {fr.raw[3:-1].hex(" ").upper()}]'
|
||||
else:
|
||||
pl = _clean(pl)
|
||||
if fr.type_code == 0xF0:
|
||||
text = fr.payload or 'ok'
|
||||
text = pl or 'ok'
|
||||
else:
|
||||
text = TYPE_NAMES.get(fr.type_code, f'TYPE=0x{fr.type_code:02X}')
|
||||
if fr.payload:
|
||||
text += f' {fr.payload}'
|
||||
m = re.search(r'err:(\d+)', fr.payload)
|
||||
if pl:
|
||||
text += f' {pl}'
|
||||
m = re.search(r'err:(\d+)', pl)
|
||||
if m:
|
||||
text += f'({DLPC_ERR_NAMES.get(int(m.group(1)), "未知错误码")})'
|
||||
return text
|
||||
@@ -158,8 +221,8 @@ class DLPC485:
|
||||
回调在后台线程触发, GUI 侧需自行投递回主线程(见 hdmi_gui 的轮询队列)。
|
||||
"""
|
||||
|
||||
def __init__(self, on_event, on_status):
|
||||
self.on_event, self.on_status = on_event, on_status
|
||||
def __init__(self, on_event, on_status, on_frame=None):
|
||||
self.on_event, self.on_status, self.on_frame = on_event, on_status, on_frame
|
||||
self.q = queue.Queue()
|
||||
self._target = None # 想态 (port, baud, bytesize, parity, stopbits)
|
||||
self._open_key = None # 当前已打开串口的参数元组
|
||||
@@ -252,7 +315,9 @@ class DLPC485:
|
||||
port, baud, bytesize=bytesizes.get(dbsize, serial.EIGHTBITS),
|
||||
parity=parities.get(parity, serial.PARITY_NONE),
|
||||
stopbits=stopbits.get(sbits, serial.STOPBITS_ONE),
|
||||
timeout=0.15)
|
||||
timeout=0.15,
|
||||
write_timeout=1.0) # 写超时: 转换器停滞时 write 会
|
||||
# 永久阻塞并卡死线程, 必须设上限
|
||||
self.parser = FrameParser()
|
||||
self._open_key = target
|
||||
self.on_status(f'已连接 {port} @ {baud} '
|
||||
@@ -261,7 +326,19 @@ class DLPC485:
|
||||
self.ser = None
|
||||
with self._lock:
|
||||
self._target = None
|
||||
self.on_status(f'连接失败: {e}')
|
||||
blob = str(e) + repr(e)
|
||||
if 'PermissionError' in blob or '拒绝访问' in blob \
|
||||
or 'Access is denied' in blob:
|
||||
hint = '串口被占用(串口助手/另一实例?)'
|
||||
elif 'FileNotFoundError' in blob or '找不到指定的' in blob \
|
||||
or 'No such file' in blob:
|
||||
hint = '串口不存在,请刷新后重选'
|
||||
else:
|
||||
hint = '无法打开,详情见日志'
|
||||
# 状态标签只放短提示(长异常串会撑爆参数行把窗口拉长),
|
||||
# 完整异常走 on_event 进收发日志
|
||||
self.on_status(f'连接失败: {hint}')
|
||||
self.on_event(f'连接失败: {e!r}')
|
||||
if self.ser is not None:
|
||||
try:
|
||||
item = None
|
||||
@@ -276,10 +353,17 @@ class DLPC485:
|
||||
data = self.ser.read(256)
|
||||
if data:
|
||||
for fr in self.parser.feed(data):
|
||||
if self.on_frame is not None:
|
||||
self.on_frame(fr) # 结构化帧(二进制载荷场景用)
|
||||
self.on_event(f'← {describe(fr)} '
|
||||
f'[{fr.raw.hex(" ").upper()}]')
|
||||
except OSError:
|
||||
try:
|
||||
self.ser.close()
|
||||
except Exception:
|
||||
pass
|
||||
self.ser = None
|
||||
self._open_key = None # 必须同步清除, 否则同参数重连被当作已打开而跳过
|
||||
with self._lock:
|
||||
self._target = None
|
||||
self.on_status('串口丢失(设备拔出?), 请重新连接')
|
||||
@@ -5,7 +5,7 @@
|
||||
================================================================
|
||||
配合 demo 板当前 EDID 首选时序 800x600@60, 全屏纯色输出。
|
||||
用法: python gen_solid_colors.py → 输出到 ../assets/solid_*.png
|
||||
在 HDMI-Tool 中通过自定义栏位(⚙ 换图)加载, 发布包随附。
|
||||
在 DLPilot 中通过自定义栏位(⚙ 换图)加载, 发布包随附。
|
||||
"""
|
||||
|
||||
import os
|
||||
@@ -6,7 +6,7 @@ HDMI EDID 查看器 + 测试图案投屏 + 光机控制 — 入口与命令行
|
||||
配合 LT8619C(HDMI 转 RGB888)→ DLPC3421 转接板调试使用。
|
||||
|
||||
模块划分(重构自原单文件):
|
||||
app_gui.py CustomTkinter 主界面(双栏仪表盘)
|
||||
app_fluent.py PySide6-Fluent-Widgets 主界面(双栏仪表盘)
|
||||
display_win.py Win32 显示器枚举/分辨率/拓扑
|
||||
edid_parse.py EDID 1.4 / CEA-861 解析
|
||||
patterns.py 测试图案全屏投屏窗口
|
||||
@@ -45,9 +45,9 @@ from patterns import PATTERN_NAMES, show_pattern, show_pattern_image
|
||||
|
||||
|
||||
def run_gui(auto_close=0):
|
||||
"""启动 CustomTkinter 主界面(实现在 app_gui.py)"""
|
||||
import app_gui
|
||||
app_gui.run_gui(auto_close)
|
||||
"""启动 PySide6-Fluent-Widgets 主界面(实现在 app_fluent.py)"""
|
||||
import app_fluent
|
||||
app_fluent.run_gui(auto_close)
|
||||
|
||||
|
||||
def run_dump(edid_fields=False):
|
||||
@@ -121,7 +121,8 @@ def run_dlpc(port, baud, cmds):
|
||||
print('← (35s 超时无响应)')
|
||||
rc = 1
|
||||
else:
|
||||
print(f'← {dlpc_rs485.describe(got)} [{got.raw.hex(" ").upper()}]')
|
||||
nice = dlpc_rs485.format_power(cmd, got) # 电源命令二进制载荷译码
|
||||
print(f'← {nice or dlpc_rs485.describe(got)} [{got.raw.hex(" ").upper()}]')
|
||||
if got.type_code != 0xF0:
|
||||
rc = 1
|
||||
ser.close()
|
||||
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 8.9 KiB After Width: | Height: | Size: 8.9 KiB |
@@ -9,6 +9,19 @@
|
||||
|
||||
from config import DEFAULT_AREA, HAS_PIL, Image, ImageTk, PAT_W, PAT_H
|
||||
|
||||
# 当前打开的投屏窗口集合: 支持"新图案替换旧图案"与 close_all() 一键恢复桌面
|
||||
_OPEN = set()
|
||||
|
||||
|
||||
def close_all():
|
||||
"""关闭所有打开的投屏窗口, 恢复桌面"""
|
||||
for top in list(_OPEN):
|
||||
try:
|
||||
top.destroy()
|
||||
except Exception:
|
||||
pass
|
||||
_OPEN.clear()
|
||||
|
||||
|
||||
PATTERN_NAMES = {'Red': '纯红', 'Green': '纯绿', 'Blue': '纯蓝',
|
||||
'Checker': '黑白棋盘格', 'Grid': '网格线'}
|
||||
@@ -43,8 +56,9 @@ def _area_box(spec, w, h):
|
||||
def _open_fullscreen(parent, rect, auto_close=0):
|
||||
"""创建覆盖 rect(x,y,w,h) 的无边框全屏黑底窗口, 返回 (top, cv)
|
||||
|
||||
只支持 ESC 退出: overrideredirect 窗口必须 focus_force 强取键盘焦点,
|
||||
否则收不到按键(Windows 上该组合有效)。
|
||||
ESC 退出(需窗口持有键盘焦点); overrideredirect 窗口必须 focus_force
|
||||
强取键盘焦点, 否则收不到按键(Windows 上该组合有效)。
|
||||
窗口登记进 _OPEN: 打开新投屏前会关旧的(替换语义), close_all() 一键全关。
|
||||
"""
|
||||
import tkinter as tk
|
||||
rx, ry, rw, rh = rect
|
||||
@@ -58,9 +72,16 @@ def _open_fullscreen(parent, rect, auto_close=0):
|
||||
cv.pack(fill='both', expand=True)
|
||||
|
||||
def close(_evt=None):
|
||||
_OPEN.discard(top)
|
||||
top.destroy()
|
||||
|
||||
def _on_destroy(e):
|
||||
if e.widget is top: # 子控件销毁也冒泡到此, 只认窗口本身
|
||||
_OPEN.discard(top)
|
||||
|
||||
top.bind('<Escape>', close)
|
||||
top.bind('<Destroy>', _on_destroy)
|
||||
_OPEN.add(top)
|
||||
if auto_close > 0:
|
||||
top.after(auto_close * 1000, close)
|
||||
top.focus_force()
|
||||
@@ -68,7 +89,9 @@ def _open_fullscreen(parent, rect, auto_close=0):
|
||||
|
||||
|
||||
def show_pattern(parent, rect, kind, auto_close=0, area=DEFAULT_AREA):
|
||||
"""在 rect 指定的屏幕上全屏出居中测试卡(无任何 OSD 修饰), 区域由 area 指定"""
|
||||
"""在 rect 指定的屏幕上全屏出居中测试卡(无任何 OSD 修饰), 区域由 area 指定。
|
||||
打开前先关闭已有投屏窗口(替换语义, 不会多层叠罗汉)。"""
|
||||
close_all()
|
||||
top, cv = _open_fullscreen(parent, rect, auto_close)
|
||||
|
||||
def draw(_evt=None):
|
||||
@@ -107,7 +130,9 @@ def show_pattern(parent, rect, kind, auto_close=0, area=DEFAULT_AREA):
|
||||
def show_pattern_image(parent, rect, path, auto_close=0, area=DEFAULT_AREA):
|
||||
"""全屏黑底, 图片 1:1 居中于 area 指定的测试卡区域:
|
||||
小于区域 -> 真实像素居中, 四周黑边;
|
||||
大于区域 -> 等效从中心截取(区域外用黑矩形遮挡)"""
|
||||
大于区域 -> 等效从中心截取(区域外用黑矩形遮挡)。
|
||||
打开前先关闭已有投屏窗口(替换语义)。"""
|
||||
close_all()
|
||||
top, cv = _open_fullscreen(parent, rect, auto_close)
|
||||
|
||||
def draw(_evt=None):
|
||||
@@ -23,6 +23,7 @@ import re
|
||||
import ssl
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
import uuid
|
||||
@@ -59,7 +60,10 @@ class Api:
|
||||
self.headers = {'Authorization': f'token {token}'}
|
||||
self.ctx = ssl._create_unverified_context() if insecure else None
|
||||
|
||||
def request(self, method, path, data=None, headers=None):
|
||||
def request(self, method, path, data=None, headers=None, retries=4):
|
||||
"""发请求; 实例 TLS 间歇性抽风(SSL UNEXPECTED_EOF), 连接级错误自动重试"""
|
||||
last = None
|
||||
for attempt in range(retries):
|
||||
req = urllib.request.Request(self.api + path, data=data, method=method,
|
||||
headers={**self.headers, **(headers or {})})
|
||||
try:
|
||||
@@ -68,6 +72,10 @@ class Api:
|
||||
return resp.status, json.loads(body) if body else None
|
||||
except urllib.error.HTTPError as e:
|
||||
return e.code, json.loads(e.read() or b'{}')
|
||||
except (urllib.error.URLError, ssl.SSLError, OSError) as e:
|
||||
last = e
|
||||
time.sleep(1.0 + attempt)
|
||||
raise RuntimeError(f'Gitea 请求连续 {retries} 次失败: {last}')
|
||||
|
||||
def get_json(self, path):
|
||||
status, data = self.request('GET', path)
|
||||
@@ -0,0 +1,70 @@
|
||||
# coding: utf-8
|
||||
"""收发日志上限与队列消费回归自检(无窗口, 离屏渲染)。
|
||||
|
||||
背景: v0.4.3 之前收发日志用 textCursor 手工裁剪, 其中 `cursor.Start` /
|
||||
`cursor.BlockUnderCursor` 是实例级枚举访问 —— PySide6 6.11 移除了该形式,
|
||||
日志一旦超过 500 行, 每次 _dlpc_log 追加后必抛 AttributeError; 且异常会
|
||||
逃出 _poll_dlpc 的 drain 循环(旧 try 只捕获 queue.Empty), 每 tick 最多
|
||||
消费到第一条 event, `_dlpc_log_q` 棘轮积压、日志裁剪与自动滚动全部失效,
|
||||
电源自检/功率检测序列还会被异常打断在启动处(之后所有命令被"序列进行中"
|
||||
拦截)。v0.4.3 改为 setMaximumBlockCount 环形裁剪 + 逐事件异常兜底。
|
||||
|
||||
本测试保证:
|
||||
1. 连续追加 600 行日志不抛异常, document().blockCount() 环形封顶 500, 末行在;
|
||||
2. 单条异常事件(模拟未来引入的坏数据)不中断 _poll_dlpc 本轮队列消费
|
||||
—— 其后的事件仍全部入日志、队列清空。
|
||||
|
||||
运行: python selftest_log.py (依赖 PySide6-Fluent-Widgets 与 pyserial ——
|
||||
串口卡构建后 txt_dlpc 才存在)
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
from PySide6.QtWidgets import QApplication
|
||||
from qfluentwidgets import Theme, setTheme
|
||||
|
||||
import app_fluent
|
||||
import dlpc_rs485
|
||||
|
||||
|
||||
def check_cap(win):
|
||||
for i in range(600):
|
||||
win._dlpc_log(f"cap-line-{i}")
|
||||
blocks = win.txt_dlpc.document().blockCount()
|
||||
has_last = "cap-line-599" in win.txt_dlpc.toPlainText()
|
||||
print(f" 追加 600 行: blockCount={blocks}(封顶 500), 末行在: {has_last}")
|
||||
return blocks <= 500 and has_last
|
||||
|
||||
|
||||
def check_drain_resilience(win):
|
||||
win._timer.stop() # 排除 80ms 轮询定时器干扰
|
||||
win._dlpc_log_q.put(("pdframe", "poison-not-a-frame")) # 该条分发必抛异常
|
||||
win._dlpc_log_q.put(("event", "after-poison-1"))
|
||||
win._dlpc_log_q.put(("event", "after-poison-2"))
|
||||
win._poll_dlpc() # 单次手动驱动(不进事件循环)
|
||||
left = win._dlpc_log_q.qsize()
|
||||
text = win.txt_dlpc.toPlainText()
|
||||
drained = left == 0 and "after-poison-1" in text and "after-poison-2" in text
|
||||
print(f" 坏条目后消费不中断: 残留队列={left}, 后续事件全部写入: {drained}")
|
||||
return drained
|
||||
|
||||
|
||||
def main():
|
||||
if not dlpc_rs485.HAS_SERIAL:
|
||||
print("FAILED 缺少 pyserial: 串口卡未构建, txt_dlpc 不存在")
|
||||
return 1
|
||||
app = QApplication.instance() or QApplication(sys.argv)
|
||||
setTheme(Theme.AUTO)
|
||||
win = app_fluent.App(0)
|
||||
passed = check_cap(win)
|
||||
passed &= check_drain_resilience(win)
|
||||
win.close()
|
||||
print("ALL PASS" if passed else "FAILED")
|
||||
return 0 if passed else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -73,5 +73,35 @@ for _name, cmd, _note in d.PRESETS:
|
||||
d.build_frame(cmd)
|
||||
print(f'预设 {len(d.PRESETS)} 条全部可组帧: PASS')
|
||||
|
||||
# 8) M303/M304(SQ52205 电源实测)回归向量: 上游真机抓取帧
|
||||
check('build_frame(M303)', d.build_frame('M303').hex(' ').upper(),
|
||||
'D5 01 04 4D 33 30 33 E8')
|
||||
check('build_frame(M304)', d.build_frame('M304').hex(' ').upper(),
|
||||
'D5 01 04 4D 33 30 34 E9')
|
||||
frames = d.FrameParser().feed(bytes.fromhex('B5 F0 02 2E F4 14'))
|
||||
check('M303 应答帧', len(frames), 1)
|
||||
check('M303 电压(0x2EF4=12020mV)', d.format_power('M303', frames[0]),
|
||||
'12020 mV (12.02 V)')
|
||||
frames = d.FrameParser().feed(bytes.fromhex('B5 F0 02 00 34 26'))
|
||||
check('M304 应答帧', len(frames), 1)
|
||||
check('M304 电流(0x0034=+52mA)', d.format_power('M304', frames[0]), '+52 mA')
|
||||
check('M304 负值(FF06=-250mA 补码)', d.payload_s16_be(bytes.fromhex('FF 06')), -250)
|
||||
|
||||
# 9) M305(SQ52205 实测功率)回归向量: u32 大端 mW(LEN=4, 算法推演帧)
|
||||
check('build_frame(M305)', d.build_frame('M305').hex(' ').upper(),
|
||||
'D5 01 04 4D 33 30 35 EA')
|
||||
frames = d.FrameParser().feed(bytes.fromhex('B5 F0 04 00 00 8C A0 20'))
|
||||
check('M305 应答帧', len(frames), 1)
|
||||
check('M305 功率(0x8CA0=36000mW)', d.format_power('M305', frames[0]),
|
||||
'36000 mW (36.00 W)')
|
||||
check('M305 拒绝双字节载荷', d.format_power(
|
||||
'M305', d.FrameParser().feed(bytes.fromhex('B5 F0 02 8C A0 1E'))[0]), None)
|
||||
|
||||
# 10) 二进制载荷的日志行安全: 无控制字符(NUL 会截断 Windows 剪贴板), 以 hex 展示
|
||||
frames = d.FrameParser().feed(bytes.fromhex('B5 F0 02 00 34 26')) # M304 应答(含 NUL)
|
||||
desc = d.describe(frames[0])
|
||||
check('二进制载荷 hex 展示', desc, '[二进制载荷 00 34]')
|
||||
check('日志行无控制字符', any(ord(c) < 0x20 for c in desc), False)
|
||||
|
||||
print('RESULT:', 'FAIL:' + ','.join(fails) if fails else 'ALL PASS')
|
||||
sys.exit(1 if fails else 0)
|
||||
@@ -0,0 +1,82 @@
|
||||
# coding: utf-8
|
||||
"""主题切换回归自检(无窗口, 离屏渲染)。
|
||||
|
||||
背景: fluent 控件直接 setStyleSheet 的样式会在 setTheme 时被库重刷的自带 qss 冲掉
|
||||
(v0.4.0 RGB swatch 按钮切主题丢底色的根因)。swatch 改走 setCustomStyleSheet、
|
||||
标题字号走 QFont 后,本测试保证:
|
||||
1. Dark -> Light -> Dark -> Light 往返后 9 个 swatch 按钮样式表仍带底色;
|
||||
2. Light 下实际渲染出的按钮中心像素 = swatch 色值(不只样式表字符串存在);
|
||||
3. 标题 24px 加粗(QFont)在往返后不变。
|
||||
|
||||
运行: python selftest_theme.py (依赖 PySide6-Fluent-Widgets)
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
from PySide6.QtGui import QColor
|
||||
from PySide6.QtWidgets import QApplication
|
||||
from qfluentwidgets import PushButton, StrongBodyLabel, Theme, setTheme
|
||||
|
||||
import app_fluent
|
||||
import patterns
|
||||
|
||||
|
||||
def check_style_sheet(win, app):
|
||||
swatches = [b for b in win.findChildren(PushButton) if b.text() in {"55", "AA", "FF"}]
|
||||
assert len(swatches) == 9, f"expect 9 swatch buttons, got {len(swatches)}"
|
||||
title = [l for l in win.findChildren(StrongBodyLabel) if l.text() == "DLPilot"]
|
||||
assert len(title) == 1, "title label not found"
|
||||
colored = sum(1 for b in swatches if "background-color: #" in b.styleSheet())
|
||||
f = title[0].font()
|
||||
print(f" swatch 样式表带底色: {colored}/9, 标题 24px 粗体: "
|
||||
f"{f.pixelSize() == 24 and f.bold()}")
|
||||
return colored == 9 and f.pixelSize() == 24 and f.bold()
|
||||
|
||||
|
||||
def check_rendered_pixel(win, app):
|
||||
"""Light 主题下逐个渲染 swatch,与目标色一致的像素须占明显多数(背景为主,
|
||||
中心处是文字字形,不能只采单点)。"""
|
||||
ok = True
|
||||
for channel, items in patterns.SOLID_ROWS:
|
||||
for label, color in items:
|
||||
button = next(b for b in win.findChildren(PushButton)
|
||||
if b.text() == label and f"background-color: {color}" in b.styleSheet())
|
||||
image = button.grab().toImage()
|
||||
target = QColor(color)
|
||||
total, matched = image.width() * image.height(), 0
|
||||
for y in range(image.height()):
|
||||
for x in range(image.width()):
|
||||
if image.pixelColor(x, y) == target:
|
||||
matched += 1
|
||||
ratio = matched / total
|
||||
same = ratio >= 0.2
|
||||
ok &= same
|
||||
if not same:
|
||||
print(f" 渲染不符: {channel}/{label} 期望 {color} 仅占 {ratio:.0%}")
|
||||
print(f" Light 下渲染像素比对: {'一致' if ok else '存在偏差'}")
|
||||
return ok
|
||||
|
||||
|
||||
def main():
|
||||
app = QApplication.instance() or QApplication(sys.argv)
|
||||
setTheme(Theme.AUTO)
|
||||
win = app_fluent.App(0)
|
||||
passed = True
|
||||
for step, theme in (("初始 Dark", Theme.DARK), ("切 Light", Theme.LIGHT),
|
||||
("切回 Dark", Theme.DARK), ("再切 Light", Theme.LIGHT)):
|
||||
setTheme(theme)
|
||||
app.processEvents()
|
||||
print(f"[{step}]")
|
||||
passed &= check_style_sheet(win, app)
|
||||
if theme == Theme.LIGHT:
|
||||
passed &= check_rendered_pixel(win, app)
|
||||
win.close()
|
||||
print("ALL PASS" if passed else "FAILED")
|
||||
return 0 if passed else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,8 @@
|
||||
# 本机虚拟环境(根 .gitignore 已覆盖 build/ dist/ *.spec __pycache__/)
|
||||
.venv/
|
||||
|
||||
# 构建日志(测试结果由 unittest 实时输出, 不留档)
|
||||
build-log*.txt
|
||||
|
||||
# 验证脚本生成的截图
|
||||
validation/*.png
|
||||
@@ -0,0 +1,53 @@
|
||||
# EDID Viewer — 开发需求与进度
|
||||
|
||||
## 基本环境
|
||||
- 主项目位置:`E:\Hulk-Coding\HW-Debug-Tools\EDID-viewer`;为兼容此前约定,已同步镜像到 `E:\Hulk-Coding\LT8619C\_Debug\_Tools\EDID-viewer`。
|
||||
- Windows 10/11 x64;Python 3.14;PySide6 6.11.2(Qt 官方 Python 绑定);PySide6-Fluent-Widgets 1.11.3。
|
||||
- 使用项目 `.venv`;依赖见 requirements.txt;GUI 入口为 `src/main.py`(版本号在 `src/main.py` 的 `APP_VERSION`)。
|
||||
- 独立工具,不依赖、不修改 LT8619C 固件或 DLPilot 工程。
|
||||
|
||||
## 工程结构与流水线(对齐 DLPilot 三区约定)
|
||||
- 三区目录:`src/` 人写代码(main / edid / windows_edid / theme / test_edid + 打包流水线);`assets/` 图标与生成脚本(可再生);`release/` 交付(`EDID-Viewer.exe` 入库 + README)。
|
||||
- 打包单文件 exe:`python src/build_exe.py`(spec 由脚本生成到 `src/build/`,不入库;原 viewer.spec 的 ICU 排除逻辑已内置其中)。`--debug` 附带带控制台变体。
|
||||
- 发布:`python src/package_release.py <版本>` 组装 `release/EDID-Viewer-v*-win64.zip`(zip 不入库,只上传 Gitea Release);上传用 `python src/publish_gitea.py <zip>`,token 走环境变量 `GITEA_TOKEN`。
|
||||
- 解析测试:`cd src && python -m unittest`(9 项,改 edid.py 后必跑)。
|
||||
|
||||
## 任务目标
|
||||
1. 枚举 Windows 活动显示设备并读取 EDID 原始块。
|
||||
2. 查看厂家代码、产品编号、名称、序列号、生产日期、分辨率和详细时序。
|
||||
3. 展示 CTA 扩展、HDMI、音频、HDR、色彩能力和校验结果。
|
||||
4. 支持离线 BIN/HEX 导入、BIN 和 JSON 报告导出。
|
||||
5. Light / Dark / 跟随系统主题,持久化用户选择并响应系统主题变化。
|
||||
6. 图标参考 DLPilot 黑底、橙色标签、白字,使用 EDID / Viewer 独立标识。
|
||||
- Fluent 主题包含 `dark1`(蓝色)和 `dark2`(青色),两者均为显式深色模式;选中态文字必须保持高对比度。
|
||||
- Fluent Widgets 版本已采用顶部操作区、下方信息卡片和分组页签;后续布局调整需保持信息层级清晰。
|
||||
|
||||
## Fluent Widgets 版本
|
||||
- 界面使用 PySide6-Fluent-Widgets 的 `CardWidget`、`ComboBox`、`PrimaryPushButton`、`PlainTextEdit` 和 `TreeWidget`;顶部操作区、下方信息卡片和分组页签。
|
||||
- Fluent 主题只负责表现层;EDID 解析、Windows WMI 读取、导入导出和线程边界不改变。
|
||||
- 主题切换必须三件套同步(与 DLPilot `app_fluent.py` 同一方案):`setTheme` 之外,QPalette + 应用级 QSS 统一 QMainWindow 背景、原生 QTabWidget/QStatusBar 表面色,DWM 属性 20/35/36 切换原生标题栏深浅。只调 `setTheme` 会导致 Light 模式下窗口背景、页签和标题栏仍是系统深色。
|
||||
- 窗口截图验证可用 `validation\capture-window.ps1`(按进程窗口矩形截屏,注意全屏窗口会遮挡)。
|
||||
|
||||
## 实现与边界
|
||||
- 只读 Windows WMI 显示驱动提供的 EDID;不写 EDID、不更改分辨率或显示拓扑。
|
||||
- Windows/驱动可能缓存或覆盖 EDID;不能声称数据是实时 DDC 总线抓取。
|
||||
- HDMI、DP、内屏均列出,连接类型来自 WmiMonitorConnectionParams,未知则如实标注。
|
||||
- 无法读取的设备、缺失扩展、未知数据块和无效校验必须明确展示,不猜测。
|
||||
- EDID 表示接收端声明能力,不能证明当前链路色深、HDR、HDCP 或真实带宽。
|
||||
- 解析器与 UI、Windows 读取分离;读取在后台线程完成。
|
||||
- 添加解析边界/错误数据测试。打包后验证实际可见窗口、缩放、刷新和导入导出流程。
|
||||
- 第一版不完整解码 DisplayID、HDMI Forum VRR/DSC;保留原始块供分析。
|
||||
|
||||
## 进度记录
|
||||
- **v0.1.0(2026-09-25,已发布)**:目录对齐 DLPilot 三区结构;onefile 打包
|
||||
(`src/build_exe.py` 生成 spec,剔除 PATH 上 Poppler/Conda 的版本化 ICU);Light
|
||||
主题三件套修复(setTheme + QPalette/应用级 QSS + DWM 标题栏);右上角"关于";
|
||||
标签 `EDID-Viewer-v0.1.0` 与 Release 附件已核对(66,483,477 字节)。
|
||||
- 验证明细见 `VALIDATION.md`;实机验收缺口:HDMI 热插拔、多屏、跨屏 DPI、
|
||||
最大化/恢复与导入导出完整交互流程。
|
||||
- 根目录 `agent.md` 为仓库整体的开发需求与进度管理文档。
|
||||
|
||||
## 后续建议
|
||||
- EDID 对比、字节差异与固件数组导出。
|
||||
- HDMI Forum VRR/ALLM/FRL/DSC、DisplayID 与高级色彩数据解析。
|
||||
- 与实际输出时序和桥接芯片寄存器联合诊断。
|
||||
@@ -0,0 +1,65 @@
|
||||
# EDID Viewer
|
||||
|
||||
Windows 10/11 显示器 EDID 查看器。使用 **PySide6 / PySide6-Fluent-Widgets**,只读,不修改显示设置。
|
||||
|
||||
> 只想使用工具:到 [Gitea Releases](https://gitea.hulk.wang/hulk/HW-Debug-Tools/releases)
|
||||
> 下载 `EDID-Viewer-vX.Y.Z-win64.zip`,解压双击 `EDID-Viewer.exe` 即可(Windows 10/11 x64,免安装、无需 Python)。
|
||||
|
||||
## 使用
|
||||
|
||||
- 双击 `release\EDID-Viewer.exe`(单文件,免安装)。
|
||||
- 或双击 `start.cmd` 使用本机 Python 环境运行源码。
|
||||
- 右上角「外观」选择 Light(浅色)、Dark(琥珀深色)、dark1(蓝色深色)、dark2(青色深色)或跟随系统;默认跟随系统,选择自动保存,系统模式响应 Windows 明暗变化。
|
||||
- 图标沿用 DLPilot 的黑底/橙色标签/白字语言,文字为 EDID / Viewer;窗口、任务栏和 EXE 使用同一图标。
|
||||
- 当前布局采用 Fluent Widgets:顶部设备/文件操作卡片、右上角「关于」,下方信息卡片和分组页签;Dark 使用琥珀强调色,dark1 使用蓝色强调色,dark2 使用青色强调色,主题随系统设置持久化。
|
||||
- 点击「刷新设备」,从下拉框选择设备。HDMI、DP 和内屏均显示连接类型。
|
||||
- 「设备与能力」显示身份和音频/HDR/色彩/HDMI 信息;「分辨率与时序」可展开 DTD 查看像素时钟、前后肩、同步宽度和极性。
|
||||
- 「原始 HEX」支持选中复制。「导出 BIN」保持读取到的字节不变;「导出报告」生成含原始数据的 UTF-8 JSON。
|
||||
- 支持 `.bin/.edid` 二进制和 `.hex/.txt` 纯十六进制。HEX 可以使用空格、逗号、`0x` 前缀,不接受带地址/ASCII 栏的 hexdump。
|
||||
|
||||
## 目录结构(对齐 DLPilot)
|
||||
|
||||
- `src/` — 人写代码:界面(main.py)、EDID 解析(edid.py)、Windows 读取(windows_edid.py)、主题(theme.py)、解析测试(test_edid.py)和打包流水线。
|
||||
- `assets/` — 图标与生成脚本(可再生)。
|
||||
- `release/` — 交付物:`EDID-Viewer.exe` 入库;发布 zip 只上传 Gitea Release,不入库。
|
||||
- `AGENTS.md` — 工程约定与任务边界(改代码前必读);`VALIDATION.md` — 验证记录。
|
||||
|
||||
## 环境与构建
|
||||
|
||||
本机:Python 3.14、PySide6 6.11.2、PySide6-Fluent-Widgets 1.11.3、PyInstaller 6.22.2。当前 `.venv` 通过 `--system-site-packages` 复用已安装依赖,不修改全局包。新电脑可以创建独立环境:
|
||||
|
||||
```powershell
|
||||
python -m venv .venv
|
||||
.\.venv\Scripts\python.exe -m pip install -r requirements.txt
|
||||
.\.venv\Scripts\python.exe src\main.py
|
||||
cd src && python -m unittest # 9 项解析测试
|
||||
python src\build_exe.py # 打包 → release\EDID-Viewer.exe
|
||||
python src\package_release.py 0.1.0 # 组装 release\EDID-Viewer-v0.1.0-win64.zip
|
||||
python src\publish_gitea.py ..\release\EDID-Viewer-v0.1.0-win64.zip --insecure
|
||||
```
|
||||
|
||||
打包为单文件 exe;spec 由 `build_exe.py` 生成到 `src/build/`(不入库),其中剔除 PATH 上其他工具(Poppler/Conda)的版本化 ICU DLL,避免 QtCore 加载失败(WinError 127)。构建前关闭正在运行的 EDID Viewer,以免文件被占用。图标源为 `assets/make_icon.py`,重新生成时需安装 Pillow(仅开发时需要)。主题配置保存在当前用户的 `QSettings: LT8619C-Tools/EDID-Viewer`。
|
||||
|
||||
## 能力范围
|
||||
|
||||
- EDID 1.x 基础身份、生产日期、名称/序列号、物理尺寸、Gamma、色深、色度坐标。
|
||||
- 已建立/标准时序、基础与 CTA 详细时序;常用 CTA VIC(未映射的 VIC 显示编号)。
|
||||
- 多个 CTA 扩展、音频 SAD、HDMI VSDB、CEC 地址、深色、TMDS、HF-VSDB 的 SCDC/TMDS。
|
||||
- HDR EOTF、色彩标准、YCbCr 4:2:0 声明。未知块原样保留。
|
||||
- 每块校验和、扩展计数、截断和数据块越界诊断。
|
||||
|
||||
## 限制
|
||||
|
||||
- 读取 `root/wmi:WmiMonitorDescriptorMethods` 中的活动设备,不保证列出禁用输出/驱动不提供 WMI 的设备。失败会显示原因,可改用离线文件。
|
||||
- 数据来自 Windows/显卡驱动,可能是缓存或覆盖内容,不是实时 DDC 抓取。读取扩展失败时保留已经取得的块并报告缺失。
|
||||
- EDID 能力不等于当前输出模式;不能据此确定 HDCP、线材质量、正在使用的 HDR/色深或 HDMI 版本。
|
||||
- DisplayID 和 HDMI Forum VRR/ALLM/FRL/DSC 尚未详细解码;仅包含 DisplayID 时序的屏幕可能没有可解码的分辨率。范围描述符扩展偏移仅提示,未应用。
|
||||
- 不承诺所有 CTA VIC/扩展标签均已覆盖。厂商首先显示标准 PNP 三字母代码,避免错误猜测品牌。
|
||||
|
||||
## 推荐后续挖掘
|
||||
|
||||
1. **桥接板时序匹配**:像素时钟、H/V 消隐、同步极性和首选模式,排查黑屏、偏色、画面偏移。
|
||||
2. **EDID 差异比较**:对照板卡固件、Windows 读取值、显示器原始值,定位缓存、截断或改写。
|
||||
3. **带宽与色彩**:TMDS/FRL、RGB/YCbCr、深色和 4:2:0,解释分辨率或刷新率受限。
|
||||
4. **HDR 与音频**:PQ/HLG、亮度元数据、PCM 位深/采样率/声道和压缩音频能力。
|
||||
5. **DisplayID / VRR / DSC**:适合高刷新率和高分辨率显示设备,作为下一阶段扩展。
|
||||
@@ -0,0 +1,50 @@
|
||||
# 验证记录 — 2026-09-23
|
||||
|
||||
- Python 3.14 / PySide6 6.11.2 / PyInstaller 6.22.2。
|
||||
- 9 个解析测试通过,包括身份字段、标准时序、1080p/1080i DTD、CTA 音频/4K/HDR/CEC、缺失扩展、坏校验、越界、未知扩展;其中包括 1000 份随机畸形数据的无崩溃检查。
|
||||
- BIN → 带 0x 前缀 HEX → BIN 一致性检查通过。
|
||||
- `pip check` 通过。
|
||||
- WMI 实际读取到内屏 SDC / ATNA60HU01-0;取得 256 字节,两个块校验通过;声明 384 字节,读取第三块失败。UI 正确展示读取错误和缺失警告。
|
||||
- 打包 EXE 实际启动通过,QtCore/QtGui/QtWidgets 绑定文件存在。截图检查确认设备信息、中文、校验、警告均可见。
|
||||
- 修复 PATH 中 Poppler ICU 被 PyInstaller 错误收集导致的 QtCore DLL 加载失败;`viewer.spec` 排除冲突 ICU,使用 Windows 系统 ICU。
|
||||
- 修复系统深色主题与浅色内容背景造成的白字不可见问题,使用完整浅色 Qt 调色板。
|
||||
- 当前没有可用于验证的外接 HDMI 设备;HDMI 热插拔、多屏、跨屏 DPI、最大化/恢复和 GUI 文件对话框完整流程尚未完成交互验收。检查期间窗口发生用户输入/位置变化,没有继续抢占窗口操作。
|
||||
- DisplayID、高级 HDMI Forum 字段未完整解析,详见 README。
|
||||
|
||||
`validation/` 保存本机读取样本和合成 HDMI 测试数据,仅作本地验收材料。
|
||||
|
||||
## 主题与图标更新
|
||||
|
||||
- 新 EXE 实际启动通过,窗口展示 EDID / Viewer 黑橙白图标。
|
||||
- 实际通过右上角切换 Light、Dark;截图检查文字、数据树、按钮、选择框的对比度正常。
|
||||
- 跟随系统在当前 Windows 深色设置下正确显示深色。已连接 Qt `colorSchemeChanged`;未修改用户 Windows 设置进行系统热切换测试。
|
||||
- Dark 选择写入 QSettings,关闭 EXE 后重新启动,选择和深色外观均保留。
|
||||
- 最大化后界面正常,随后还原;没有进行跨显示器 DPI 验证。
|
||||
- 9 项解析测试仍通过;三种主题的调色板检查通过。
|
||||
- qt-material 2.17 已在 PySide6 环境加载;Light/Dark/System 三种模式样式表生成检查通过。
|
||||
- Material 版窗口使用左侧设备/离线操作面板和右侧内容卡片,源码启动与解析测试通过;需完成本次打包后的可见 EXE 检查。
|
||||
- 本次打包 EXE 实际启动通过;可见界面已切换为 Material Amber 主题,侧栏、圆角内容卡片、页签、设备数据和警告均正常显示。
|
||||
- 实机操作验证 Light 与 Dark 切换,文字和数据树对比度正常;Material 版保留系统跟随选项。
|
||||
- 修复 Material 选中态对比度:设备/主题下拉框选中项改为深色文字配琥珀色背景;树表格、焦点行、页签和警告提示分别使用可读的深色/浅色组合。源码测试和打包 EXE 均已更新。
|
||||
- 针对截图反馈再次调整页签选中态:深色使用深灰底/琥珀字,浅色使用浅琥珀底/深琥珀字,并保留底部强调线;Light 打包窗口实测“分辨率与时序”页签可读。
|
||||
- 针对 HEX/JSON 截图反馈调整 `QPlainTextEdit`/`QTextEdit` 文本选中态:深色使用蓝灰底/浅字,浅色使用浅蓝灰底/深字,避免 qt-material 的亮黄色底/白字组合。源码样式检查和解析测试通过;本次重新打包后窗口启动验证因物理 Escape 中断,未继续进行 UI 操作。
|
||||
- 主题选择框和下拉列表已加宽至 148/至少 170 px,三种中文选项可完整显示;控件尺寸检查通过,EXE 已重新打包。
|
||||
|
||||
# 验证记录 — 2026-09-24
|
||||
|
||||
- 新增 `dark1`(`dark_blue.xml`,蓝色强调)和 `dark2`(`dark_cyan.xml`,青色强调)两个深色 Material 主题;原有 Light、Dark、跟随系统仍保留。
|
||||
- 9 项解析测试、`pip check` 和 Python 编译检查通过;qt-material 2.17 已确认包含两个新主题资源。
|
||||
- 最新 `dist\EDID-Viewer\EDID-Viewer.exe` 已重新构建并启动,进程响应正常;offscreen 窗口渲染确认两个主题的主题选择框、页签和内容面板均能显示。
|
||||
- 深色主题的下拉选中项、树表格焦点行、页签、警告和 HEX/JSON 文本选择态均使用按主题的高对比配色,避免亮背景配白字。
|
||||
- 当前预览使用无 EDID 样本的启动状态;Windows WMI 实际设备读取结果沿用上一条记录,未把本次 offscreen 渲染当作硬件验收。
|
||||
# Fluent Widgets 重写验证(2026-09-24)
|
||||
|
||||
- `PySide6-Fluent-Widgets 1.11.3` 已替换 qt-material;主界面使用 Fluent 卡片、控件和树视图,主题选择持久化并支持跟随系统。
|
||||
- 9 项 EDID 解析测试、Python 编译检查和离屏窗口启动通过;主题下拉框可切换 system/light/dark/dark1/dark2。
|
||||
- `build.ps1` 打包通过,`dist\\EDID-Viewer\\_internal\\qfluentwidgets` 资源已收集;离线 EDID 样本可渲染并启用 BIN/JSON 导出。
|
||||
|
||||
# 目录重构与 onefile 打包验证(2026-09-24)
|
||||
|
||||
- 目录对齐 DLPilot 三区结构:`src/`(代码 + 流水线)、`assets/`(图标)、`release/`(EDID-Viewer.exe + README);`agent.md` 更名 `AGENTS.md`;`build.ps1`/`viewer.spec` 由 `src/build_exe.py`(生成 spec,ICU 排除逻辑内置)取代。
|
||||
- `src/` 下 9 项解析测试通过;`src/build_exe.py` 单文件打包通过,`release\EDID-Viewer.exe` 启动验证窗口正常、图标与主题(三件套:QPalette + 应用级 QSS + DWM 标题栏)保持上一轮修复效果。
|
||||
- `src/package_release.py` 组装 zip(exe + README);`src/publish_gitea.py` 由 DLPilot 同名脚本适配(tag 前缀 `EDID-Viewer-v*`),本次未实际上传。
|
||||
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 9.2 KiB |
@@ -0,0 +1,13 @@
|
||||
"""Rebuild icon with Pillow (development only); matches the DLPilot brand."""
|
||||
from pathlib import Path
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
out = Path(__file__).resolve().parent
|
||||
image = Image.new('RGB', (512,512), 'black')
|
||||
draw = ImageDraw.Draw(image)
|
||||
draw.rounded_rectangle((38,64,474,250),radius=34,fill='#ff9900')
|
||||
font = 'C:/Windows/Fonts/arialbd.ttf'
|
||||
draw.text((256,157),'EDID',font=ImageFont.truetype(font,134),anchor='mm',fill='black')
|
||||
draw.text((256,368),'Viewer',font=ImageFont.truetype(font,116),anchor='mm',fill='white')
|
||||
image.save(out/'edid-viewer.png')
|
||||
image.save(out/'edid-viewer.ico',sizes=[(16,16),(24,24),(32,32),(48,48),(64,64),(128,128),(256,256)])
|
||||
@@ -0,0 +1,65 @@
|
||||
# EDID Viewer
|
||||
|
||||
Windows 10/11 显示器 EDID 查看器。使用 **PySide6 / PySide6-Fluent-Widgets**,只读,不修改显示设置。
|
||||
|
||||
> 只想使用工具:到 [Gitea Releases](https://gitea.hulk.wang/hulk/HW-Debug-Tools/releases)
|
||||
> 下载 `EDID-Viewer-vX.Y.Z-win64.zip`,解压双击 `EDID-Viewer.exe` 即可(Windows 10/11 x64,免安装、无需 Python)。
|
||||
|
||||
## 使用
|
||||
|
||||
- 双击 `release\EDID-Viewer.exe`(单文件,免安装)。
|
||||
- 或双击 `start.cmd` 使用本机 Python 环境运行源码。
|
||||
- 右上角「外观」选择 Light(浅色)、Dark(琥珀深色)、dark1(蓝色深色)、dark2(青色深色)或跟随系统;默认跟随系统,选择自动保存,系统模式响应 Windows 明暗变化。
|
||||
- 图标沿用 DLPilot 的黑底/橙色标签/白字语言,文字为 EDID / Viewer;窗口、任务栏和 EXE 使用同一图标。
|
||||
- 当前布局采用 Fluent Widgets:顶部设备/文件操作卡片、右上角「关于」,下方信息卡片和分组页签;Dark 使用琥珀强调色,dark1 使用蓝色强调色,dark2 使用青色强调色,主题随系统设置持久化。
|
||||
- 点击「刷新设备」,从下拉框选择设备。HDMI、DP 和内屏均显示连接类型。
|
||||
- 「设备与能力」显示身份和音频/HDR/色彩/HDMI 信息;「分辨率与时序」可展开 DTD 查看像素时钟、前后肩、同步宽度和极性。
|
||||
- 「原始 HEX」支持选中复制。「导出 BIN」保持读取到的字节不变;「导出报告」生成含原始数据的 UTF-8 JSON。
|
||||
- 支持 `.bin/.edid` 二进制和 `.hex/.txt` 纯十六进制。HEX 可以使用空格、逗号、`0x` 前缀,不接受带地址/ASCII 栏的 hexdump。
|
||||
|
||||
## 目录结构(对齐 DLPilot)
|
||||
|
||||
- `src/` — 人写代码:界面(main.py)、EDID 解析(edid.py)、Windows 读取(windows_edid.py)、主题(theme.py)、解析测试(test_edid.py)和打包流水线。
|
||||
- `assets/` — 图标与生成脚本(可再生)。
|
||||
- `release/` — 交付物:`EDID-Viewer.exe` 入库;发布 zip 只上传 Gitea Release,不入库。
|
||||
- `AGENTS.md` — 工程约定与任务边界(改代码前必读);`VALIDATION.md` — 验证记录。
|
||||
|
||||
## 环境与构建
|
||||
|
||||
本机:Python 3.14、PySide6 6.11.2、PySide6-Fluent-Widgets 1.11.3、PyInstaller 6.22.2。当前 `.venv` 通过 `--system-site-packages` 复用已安装依赖,不修改全局包。新电脑可以创建独立环境:
|
||||
|
||||
```powershell
|
||||
python -m venv .venv
|
||||
.\.venv\Scripts\python.exe -m pip install -r requirements.txt
|
||||
.\.venv\Scripts\python.exe src\main.py
|
||||
cd src && python -m unittest # 9 项解析测试
|
||||
python src\build_exe.py # 打包 → release\EDID-Viewer.exe
|
||||
python src\package_release.py 0.1.0 # 组装 release\EDID-Viewer-v0.1.0-win64.zip
|
||||
python src\publish_gitea.py ..\release\EDID-Viewer-v0.1.0-win64.zip --insecure
|
||||
```
|
||||
|
||||
打包为单文件 exe;spec 由 `build_exe.py` 生成到 `src/build/`(不入库),其中剔除 PATH 上其他工具(Poppler/Conda)的版本化 ICU DLL,避免 QtCore 加载失败(WinError 127)。构建前关闭正在运行的 EDID Viewer,以免文件被占用。图标源为 `assets/make_icon.py`,重新生成时需安装 Pillow(仅开发时需要)。主题配置保存在当前用户的 `QSettings: LT8619C-Tools/EDID-Viewer`。
|
||||
|
||||
## 能力范围
|
||||
|
||||
- EDID 1.x 基础身份、生产日期、名称/序列号、物理尺寸、Gamma、色深、色度坐标。
|
||||
- 已建立/标准时序、基础与 CTA 详细时序;常用 CTA VIC(未映射的 VIC 显示编号)。
|
||||
- 多个 CTA 扩展、音频 SAD、HDMI VSDB、CEC 地址、深色、TMDS、HF-VSDB 的 SCDC/TMDS。
|
||||
- HDR EOTF、色彩标准、YCbCr 4:2:0 声明。未知块原样保留。
|
||||
- 每块校验和、扩展计数、截断和数据块越界诊断。
|
||||
|
||||
## 限制
|
||||
|
||||
- 读取 `root/wmi:WmiMonitorDescriptorMethods` 中的活动设备,不保证列出禁用输出/驱动不提供 WMI 的设备。失败会显示原因,可改用离线文件。
|
||||
- 数据来自 Windows/显卡驱动,可能是缓存或覆盖内容,不是实时 DDC 抓取。读取扩展失败时保留已经取得的块并报告缺失。
|
||||
- EDID 能力不等于当前输出模式;不能据此确定 HDCP、线材质量、正在使用的 HDR/色深或 HDMI 版本。
|
||||
- DisplayID 和 HDMI Forum VRR/ALLM/FRL/DSC 尚未详细解码;仅包含 DisplayID 时序的屏幕可能没有可解码的分辨率。范围描述符扩展偏移仅提示,未应用。
|
||||
- 不承诺所有 CTA VIC/扩展标签均已覆盖。厂商首先显示标准 PNP 三字母代码,避免错误猜测品牌。
|
||||
|
||||
## 推荐后续挖掘
|
||||
|
||||
1. **桥接板时序匹配**:像素时钟、H/V 消隐、同步极性和首选模式,排查黑屏、偏色、画面偏移。
|
||||
2. **EDID 差异比较**:对照板卡固件、Windows 读取值、显示器原始值,定位缓存、截断或改写。
|
||||
3. **带宽与色彩**:TMDS/FRL、RGB/YCbCr、深色和 4:2:0,解释分辨率或刷新率受限。
|
||||
4. **HDR 与音频**:PQ/HLG、亮度元数据、PCM 位深/采样率/声道和压缩音频能力。
|
||||
5. **DisplayID / VRR / DSC**:适合高刷新率和高分辨率显示设备,作为下一阶段扩展。
|
||||
@@ -0,0 +1,4 @@
|
||||
PySide6==6.11.2
|
||||
PySide6-Fluent-Widgets==1.11.3
|
||||
pyinstaller==6.22.2
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
把 src/main.py 打包成单文件 exe(工具名: EDID-Viewer)
|
||||
================================================
|
||||
与 DLPilot/src/build_exe.py 同一套路: onefile + --noconsole, Python 解释器、
|
||||
PySide6 和 PySide6-Fluent-Widgets 全部打进一个 exe, 目标机器无需安装依赖。
|
||||
|
||||
用法:
|
||||
python build_exe.py 自动安装 PyInstaller(如缺)并打包
|
||||
python build_exe.py --debug 额外打一个带控制台的变体
|
||||
|
||||
产物: release/EDID-Viewer.exe
|
||||
spec 由本脚本生成到 src/build/(不入库), 调整打包逻辑直接改这里的模板。
|
||||
"""
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
# 本脚本位于 src/, 打包产物输出到工具根的 release/
|
||||
SRC = os.path.dirname(os.path.abspath(__file__))
|
||||
BASE = os.path.dirname(SRC)
|
||||
RELEASE = os.path.join(BASE, 'release')
|
||||
WORK = os.path.join(SRC, 'build')
|
||||
ICO = os.path.join(BASE, 'assets', 'edid-viewer.ico')
|
||||
|
||||
SPEC_TEMPLATE = """\
|
||||
# -*- coding: utf-8 -*-
|
||||
# 由 build_exe.py 生成, 不要手改; 调整打包逻辑请改 src/build_exe.py。
|
||||
from PyInstaller.utils.hooks import collect_all
|
||||
|
||||
qfluent_datas, qfluent_binaries, qfluent_hidden = collect_all('qfluentwidgets')
|
||||
a = Analysis(
|
||||
[r'{entry}'], pathex=[r'{src}'], binaries=qfluent_binaries,
|
||||
datas=qfluent_datas + {icon_datas}, hiddenimports=qfluent_hidden,
|
||||
noarchive=False)
|
||||
# Qt 6.11 使用 Windows 非版本化 ICU 导出; PATH 上 Poppler/Conda 的版本化
|
||||
# ICU(icuuc.dll/icudt78.dll)会被 PyInstaller 误收, 令 QtCore.pyd 启动报
|
||||
# WinError 127 —— 打包时剔除, 运行时用系统自带 ICU。
|
||||
a.binaries = [b for b in a.binaries if b[0].lower() not in ('icuuc.dll', 'icudt78.dll')]
|
||||
pyz = PYZ(a.pure)
|
||||
exe = EXE(pyz, a.scripts, a.binaries, a.datas, [], name='{name}',
|
||||
debug=False, strip=False, upx=False, console={console}{icon_clause})
|
||||
"""
|
||||
|
||||
|
||||
def ensure_pyinstaller():
|
||||
try:
|
||||
import PyInstaller # noqa: F401
|
||||
return
|
||||
except ImportError:
|
||||
pass
|
||||
print('PyInstaller 未安装, 正在安装...')
|
||||
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'pyinstaller'])
|
||||
|
||||
|
||||
def remove_stale(exe_path):
|
||||
"""删除旧 exe; 若被占用(上次验证的进程还在), 先结束同名进程再重试"""
|
||||
if not os.path.exists(exe_path):
|
||||
return
|
||||
try:
|
||||
os.remove(exe_path)
|
||||
return
|
||||
except PermissionError:
|
||||
pass
|
||||
import time
|
||||
print(f'{exe_path} 被占用, 结束残留进程后重试...')
|
||||
subprocess.run(['taskkill', '/F', '/IM', os.path.basename(exe_path)],
|
||||
capture_output=True)
|
||||
time.sleep(1.0)
|
||||
os.remove(exe_path)
|
||||
|
||||
|
||||
def build(name, console):
|
||||
remove_stale(os.path.join(RELEASE, name + '.exe'))
|
||||
if os.path.exists(ICO):
|
||||
icon_datas = f"[(r'{ICO}', 'assets')]"
|
||||
icon_clause = f", icon=r'{ICO}'"
|
||||
else:
|
||||
print('警告: 未找到 assets/edid-viewer.ico(先运行 assets/make_icon.py), 本次打包不带图标')
|
||||
icon_datas, icon_clause = '[]', ''
|
||||
spec = SPEC_TEMPLATE.format(entry=os.path.join(SRC, 'main.py'), src=SRC,
|
||||
icon_datas=icon_datas, name=name,
|
||||
console=console, icon_clause=icon_clause)
|
||||
os.makedirs(WORK, exist_ok=True)
|
||||
spec_path = os.path.join(WORK, name + '.spec')
|
||||
with open(spec_path, 'w', encoding='utf-8') as f:
|
||||
f.write(spec)
|
||||
cmd = [sys.executable, '-m', 'PyInstaller', '--noconfirm', '--clean',
|
||||
'--distpath', RELEASE, '--workpath', WORK, spec_path]
|
||||
print('\n>>', ' '.join(cmd))
|
||||
subprocess.check_call(cmd)
|
||||
out = os.path.join(RELEASE, name + '.exe')
|
||||
print(f'完成: {out} ({os.path.getsize(out) / 1024 / 1024:.1f} MB)')
|
||||
|
||||
|
||||
def main():
|
||||
build_console = '--debug' in sys.argv
|
||||
ensure_pyinstaller()
|
||||
# 常规版: 双击即用, 无黑框
|
||||
build('EDID-Viewer', 'False')
|
||||
if build_console:
|
||||
# 调试版: 带控制台, 异常栈可见
|
||||
build('EDID-Viewer-console', 'True')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,157 @@
|
||||
"""Bounds-checked EDID 1.x / CTA parser. Unknown fields retain their bytes."""
|
||||
import hashlib
|
||||
import re
|
||||
|
||||
VICS = {1:'640×480p 60 Hz',2:'720×480p 60 Hz 4:3',3:'720×480p 60 Hz 16:9',
|
||||
4:'1280×720p 60 Hz',5:'1920×1080i 60 Hz',16:'1920×1080p 60 Hz',
|
||||
17:'720×576p 50 Hz 4:3',18:'720×576p 50 Hz 16:9',19:'1280×720p 50 Hz',
|
||||
20:'1920×1080i 50 Hz',31:'1920×1080p 50 Hz',32:'1920×1080p 24 Hz',
|
||||
33:'1920×1080p 25 Hz',34:'1920×1080p 30 Hz',60:'1280×720p 24 Hz',
|
||||
61:'1280×720p 25 Hz',62:'1280×720p 30 Hz',63:'1920×1080p 120 Hz',64:'1920×1080p 100 Hz',
|
||||
93:'3840×2160p 24 Hz',94:'3840×2160p 25 Hz',95:'3840×2160p 30 Hz',
|
||||
96:'3840×2160p 50 Hz',97:'3840×2160p 60 Hz',98:'4096×2160p 24 Hz',
|
||||
99:'4096×2160p 25 Hz',100:'4096×2160p 30 Hz',101:'4096×2160p 50 Hz',102:'4096×2160p 60 Hz',
|
||||
117:'3840×2160p 100 Hz',118:'3840×2160p 120 Hz'}
|
||||
EST = ['720×400 70 Hz','720×400 88 Hz','640×480 60 Hz','640×480 67 Hz','640×480 72 Hz',
|
||||
'640×480 75 Hz','800×600 56 Hz','800×600 60 Hz','800×600 72 Hz','800×600 75 Hz',
|
||||
'832×624 75 Hz','1024×768i 87 Hz','1024×768 60 Hz','1024×768 70 Hz','1024×768 75 Hz',
|
||||
'1280×1024 75 Hz','1152×870 75 Hz']
|
||||
|
||||
def read_file(path):
|
||||
from pathlib import Path
|
||||
data = Path(path).read_bytes()
|
||||
if len(data) > 32768 * 4:
|
||||
raise ValueError('文件过大:最大 128 KiB')
|
||||
if Path(path).suffix.lower() in ('.hex', '.txt'):
|
||||
s = data.decode('utf-8-sig').strip()
|
||||
s = re.sub(r'0[xX]([0-9a-fA-F]{2})', r'\1', s)
|
||||
s = re.sub(r'[\s,{};]', '', s)
|
||||
if not re.fullmatch(r'(?:[0-9a-fA-F]{2})+', s):
|
||||
raise ValueError('HEX 文件仅接受十六进制字节,不接受偏移地址或 ASCII 栏')
|
||||
return bytes.fromhex(s)
|
||||
return data
|
||||
|
||||
def hex_dump(raw):
|
||||
return '\n'.join(f'{i:04X} ' + ' '.join(f'{x:02X}' for x in raw[i:i+16]) +
|
||||
' |' + ''.join(chr(x) if 32 <= x < 127 else '.' for x in raw[i:i+16]) + '|'
|
||||
for i in range(0, len(raw), 16))
|
||||
|
||||
def dtd(b, source):
|
||||
clock = int.from_bytes(b[:2], 'little') * 10000
|
||||
h = b[2] + ((b[4] & 240) << 4); hb = b[3] + ((b[4] & 15) << 8)
|
||||
v = b[5] + ((b[7] & 240) << 4); vb = b[6] + ((b[7] & 15) << 8)
|
||||
hf = b[8] + ((b[11] & 192) << 2); hs = b[9] + ((b[11] & 48) << 4)
|
||||
vf = (b[10] >> 4) + ((b[11] & 12) << 2); vs = (b[10] & 15) + ((b[11] & 3) << 4)
|
||||
interlace = bool(b[17] & 128)
|
||||
total_v = (v + vb) * 2 + 1 if interlace else v + vb
|
||||
rate = clock / ((h + hb) * total_v) if h + hb and total_v else 0
|
||||
sync = (b[17] >> 3) & 3
|
||||
polarity = ('H' + ('+' if b[17] & 2 else '-') + ' V' + ('+' if b[17] & 4 else '-')) if sync == 3 else '非数字分离同步'
|
||||
return {'来源':source, '分辨率':f'{h}×{v*2 if interlace else v}' + ('i' if interlace else 'p'),
|
||||
'刷新率':f'{rate*2 if interlace else rate:.3f} Hz' + ('(场率)' if interlace else ''),
|
||||
'像素时钟 MHz':clock / 1e6, '水平有效/前肩/同步/后肩':[h,hf,hs,hb-hf-hs],
|
||||
'垂直有效/前肩/同步/后肩(隔行按场)':[v,vf,vs,vb-vf-vs], '同步':polarity}
|
||||
|
||||
def parse(raw):
|
||||
if len(raw) < 128:
|
||||
raise ValueError(f'EDID 基础块不足 128 字节,实际 {len(raw)}')
|
||||
r = {'基本信息':{}, '时序':[], '能力':[], '数据块':[], '校验':[], '警告':[]}
|
||||
info, warnings = r['基本信息'], r['警告']
|
||||
if raw[:8] != bytes.fromhex('00 ff ff ff ff ff ff 00'):
|
||||
warnings.append('EDID 文件头无效;以下解析仅供诊断')
|
||||
if raw[18] != 1:
|
||||
warnings.append('非 EDID 1.x:未解析,仅保留原始数据')
|
||||
return r
|
||||
if len(raw) % 128: warnings.append('末尾存在不足 128 字节的数据')
|
||||
expected = (raw[126] + 1) * 128
|
||||
if expected != len(raw): warnings.append(f'声明 {expected} 字节,实际 {len(raw)} 字节')
|
||||
for n in range(len(raw)//128):
|
||||
block = raw[n*128:(n+1)*128]
|
||||
r['校验'].append(f'块 {n}: ' + ('通过' if sum(block)%256 == 0 else '失败'))
|
||||
pnp = int.from_bytes(raw[8:10], 'big')
|
||||
manufacturer = ''.join(chr(((pnp >> s) & 31) + 64) for s in (10,5,0))
|
||||
info.update({'厂家 PNP 代码':manufacturer, '产品编号':f'0x{int.from_bytes(raw[10:12], "little"):04X}',
|
||||
'数字序列号':int.from_bytes(raw[12:16], 'little'), 'EDID 版本':f'{raw[18]}.{raw[19]}',
|
||||
'生产日期':f'{raw[17]+1990} 年 / '+('型号年份' if raw[16]==255 else f'第 {raw[16]} 周' if raw[16] else '周未指定'),
|
||||
'尺寸':f'{raw[21]} × {raw[22]} cm' if raw[21] and raw[22] else '未给出完整物理尺寸(可能编码宽高比)',
|
||||
'Gamma':(raw[23]+100)/100 if raw[23]!=255 else '未定义',
|
||||
'扩展块数':raw[126], 'SHA-256':hashlib.sha256(raw).hexdigest()})
|
||||
if raw[20]&128:
|
||||
info['输入类型'] = '数字'
|
||||
if raw[19]>=4:
|
||||
info['接口声明'] = {0:'未定义',1:'DVI',2:'HDMI-A',3:'HDMI-B',4:'MDDI',5:'DisplayPort'}.get(raw[20]&15,'保留')
|
||||
info['色深 bpc'] = {0:'未定义',1:6,2:8,3:10,4:12,5:14,6:16}.get((raw[20]>>4)&7,'保留')
|
||||
else: info['输入类型'] = '模拟'
|
||||
for idx, mode in enumerate(EST):
|
||||
if raw[35+idx//8] & (128>>(idx%8)): r['时序'].append({'来源':'已建立时序','分辨率':mode})
|
||||
for i in range(38,54,2):
|
||||
a,b = raw[i:i+2]
|
||||
if (a,b) in ((1,1),(0,0)): continue
|
||||
h = (a+31)*8
|
||||
ratio = (1 if raw[19]<3 else 10/16, 3/4, 4/5, 9/16)[b>>6]
|
||||
r['时序'].append({'来源':'标准时序','分辨率':f'{h}×{round(h*ratio)}','刷新率':f'{(b&63)+60} Hz'})
|
||||
for offset in range(54,126,18):
|
||||
b=raw[offset:offset+18]
|
||||
if any(b[:2]):
|
||||
r['时序'].append(dtd(b, '基础 DTD'+('(首选)' if offset==54 and (raw[19]>=4 or raw[24]&2) else '')))
|
||||
elif b[:3]==b'\0\0\0':
|
||||
if b[3] in (252,255,254): info[{252:'显示器名称',255:'文本序列号',254:'描述文本'}[b[3]]] = b[5:18].decode('ascii','replace').strip('\x00\n ')
|
||||
elif b[3]==253:
|
||||
info['频率范围原始值'] = f'垂直 {b[5]}–{b[6]} Hz;水平 {b[7]}–{b[8]} kHz;最大像素时钟 {b[9]*10} MHz'
|
||||
if b[4]: warnings.append('范围描述符有扩展偏移,频率范围显示原始字段,暂未应用偏移')
|
||||
coords=[]
|
||||
low=[(raw[25]>>s)&3 for s in (6,4,2,0)]+[(raw[26]>>s)&3 for s in (6,4,2,0)]
|
||||
for i,name in enumerate(('Rx','Ry','Gx','Gy','Bx','By','Wx','Wy')): coords.append(f'{name}={(raw[27+i]*4+low[i])/1024:.4f}')
|
||||
r['能力'].append('色度坐标:'+', '.join(coords))
|
||||
for n in range(1,min(len(raw)//128,raw[126]+1)):
|
||||
b=raw[n*128:(n+1)*128]
|
||||
r['数据块'].append({'块':n,'类型':{2:'CTA-861',112:'DisplayID(暂未解码)'}.get(b[0],f'未知 0x{b[0]:02X}'),'原始':b.hex(' ')})
|
||||
if b[0]!=2: continue
|
||||
r['能力'].append(f'CTA 块 {n} / revision {b[1]}:'+', '.join(label for bit,label in ((64,'基本音频'),(32,'YCbCr 4:4:4'),(16,'YCbCr 4:2:2')) if b[3]&bit))
|
||||
end=b[2]
|
||||
if end==0: continue
|
||||
if not 4<=end<=127:
|
||||
warnings.append(f'CTA 块 {n} DTD 偏移无效:{end}'); continue
|
||||
p=4
|
||||
while p<end:
|
||||
tag,length=b[p]>>5,b[p]&31
|
||||
if not b[p]: break
|
||||
if p+1+length>end:
|
||||
warnings.append(f'CTA 块 {n} 数据块越界 @{p}'); break
|
||||
x=b[p+1:p+1+length]; p+=length+1
|
||||
entry={'块':n,'tag':tag,'原始':x.hex(' ')}; r['数据块'].append(entry)
|
||||
if tag==2:
|
||||
for svd in x:
|
||||
vic=svd&127 if 129<=svd<=192 else svd
|
||||
r['时序'].append({'来源':f'CTA VIC {vic}'+('(原生)' if 129<=svd<=192 else ''),'分辨率':VICS.get(vic,'尚未映射;查看 VIC 编号')})
|
||||
elif tag==1:
|
||||
if len(x)%3: warnings.append('音频数据块长度不是 3 的倍数')
|
||||
for j in range(0,len(x)-2,3):
|
||||
a,f,c=x[j:j+3]; fmt=(a>>3)&15
|
||||
rates='/'.join(str(v) for k,v in enumerate((32,44.1,48,88.2,96,176.4,192)) if f&(1<<k))
|
||||
bits='/'.join(str(v) for k,v in enumerate((16,20,24)) if c&(1<<k))
|
||||
r['能力'].append(f'音频:'+{1:'LPCM',2:'AC-3',7:'DTS',10:'E-AC-3',11:'DTS-HD',12:'MAT'}.get(fmt,f'格式代码 {fmt}')+f' / {(a&7)+1} 声道 / {rates} kHz'+(f' / {bits} bit' if fmt==1 else f' / 格式字段 0x{c:02X}'))
|
||||
elif tag==3 and len(x)>=3:
|
||||
oui=int.from_bytes(x[:3],'little'); entry['OUI']=f'{oui:06X}'
|
||||
if oui==0x000c03:
|
||||
r['能力'].append('HDMI VSDB')
|
||||
if len(x)>=5: r['能力'].append('CEC 物理地址:'+'.'.join(str(v) for v in (x[3]>>4,x[3]&15,x[4]>>4,x[4]&15)))
|
||||
if len(x)>=6: r['能力'].append('HDMI 深色:'+('/'.join(str(v) for k,v in ((4,10),(5,12),(6,16)) if x[5]&(1<<k)) or '未声明')+' bpc')
|
||||
if len(x)>=7 and x[6]: r['能力'].append(f'最大 TMDS 时钟:{x[6]*5} MHz')
|
||||
elif oui==0xc45dd8:
|
||||
r['能力'].append('HDMI Forum VSDB(VRR/FRL/DSC 字段暂未解码)')
|
||||
if len(x)>=5 and x[4]: r['能力'].append(f'最大 TMDS 字符速率:{x[4]*5} MHz')
|
||||
if len(x)>=6: r['能力'].append('SCDC:'+('支持' if x[5]&128 else '未声明'))
|
||||
elif tag==7 and x:
|
||||
entry['扩展 tag']=x[0]
|
||||
if x[0]==6 and len(x)>=3:
|
||||
r['能力'].append('HDR EOTF:'+', '.join(name for k,name in enumerate(('传统 SDR','传统 HDR','PQ / ST 2084','HLG')) if x[1]&(1<<k)))
|
||||
r['能力'].append(f'HDR 静态元数据类型位图:0x{x[2]:02X}')
|
||||
elif x[0]==14:
|
||||
r['能力'].append('仅 YCbCr 4:2:0 VIC:'+', '.join(f'{v} ({VICS.get(v,"未映射")})' for v in x[1:]))
|
||||
elif x[0]==15: r['能力'].append('YCbCr 4:2:0 能力映射:'+x[1:].hex(' ')+'(按本 CTA SVD 顺序)')
|
||||
elif x[0]==5 and len(x)>=3:
|
||||
r['能力'].append('色彩标准:'+', '.join(name for k,name in enumerate(('xvYCC601','xvYCC709','sYCC601','opYCC601','opRGB','BT.2020 cYCC','BT.2020 YCC','BT.2020 RGB')) if x[1]&(1<<k)))
|
||||
for o in range(end,110,18):
|
||||
if any(b[o:o+2]): r['时序'].append(dtd(b[o:o+18],f'CTA {n} DTD'))
|
||||
return r
|
||||
@@ -0,0 +1,391 @@
|
||||
"""Fluent EDID viewer for Windows display devices and offline files."""
|
||||
|
||||
import ctypes
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from PySide6.QtCore import QThread, Qt, QTimer, Signal
|
||||
from PySide6.QtGui import QFont, QFontDatabase, QIcon
|
||||
from PySide6.QtWidgets import (
|
||||
QApplication,
|
||||
QFileDialog,
|
||||
QHBoxLayout,
|
||||
QMainWindow,
|
||||
QMessageBox,
|
||||
QPlainTextEdit,
|
||||
QSizePolicy,
|
||||
QSplitter,
|
||||
QTabWidget,
|
||||
QTreeWidgetItem,
|
||||
QVBoxLayout,
|
||||
QWidget,
|
||||
)
|
||||
from qfluentwidgets import (
|
||||
BodyLabel,
|
||||
CaptionLabel,
|
||||
CardWidget,
|
||||
ComboBox,
|
||||
FluentIcon,
|
||||
PlainTextEdit,
|
||||
PrimaryPushButton,
|
||||
PushButton,
|
||||
StrongBodyLabel,
|
||||
SubtitleLabel,
|
||||
TreeWidget,
|
||||
)
|
||||
|
||||
from edid import hex_dump, parse, read_file
|
||||
from theme import ThemeManager
|
||||
from windows_edid import scan
|
||||
|
||||
APP_NAME = "EDID Viewer"
|
||||
APP_VERSION = "0.1.0"
|
||||
REPO_URL = "https://gitea.hulk.wang/hulk/HW-Debug-Tools"
|
||||
|
||||
|
||||
def icon_path():
|
||||
"""Packaged onefile: icon is extracted under sys._MEIPASS/assets; source: ../assets."""
|
||||
if hasattr(sys, "_MEIPASS"):
|
||||
return Path(sys._MEIPASS) / "assets" / "edid-viewer.ico"
|
||||
return Path(__file__).resolve().parent.parent / "assets" / "edid-viewer.ico"
|
||||
|
||||
|
||||
class Scanner(QThread):
|
||||
result = Signal(object)
|
||||
failure = Signal(str)
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
self.result.emit(scan())
|
||||
except Exception as exc:
|
||||
self.failure.emit(str(exc))
|
||||
|
||||
|
||||
class Window(QMainWindow):
|
||||
"""Main Fluent surface; parser and Windows access remain separate modules."""
|
||||
|
||||
def __init__(self, theme_manager=None):
|
||||
super().__init__()
|
||||
self.theme_manager = theme_manager or ThemeManager(QApplication.instance())
|
||||
self.setWindowTitle("EDID Viewer · HDMI 显示信息")
|
||||
self.resize(1240, 820)
|
||||
self.setMinimumSize(900, 620)
|
||||
self.raw = b""
|
||||
self.report = {}
|
||||
self.worker = None
|
||||
self._build_ui()
|
||||
self.theme_manager.set_window(self)
|
||||
self.bin_button.setEnabled(False)
|
||||
self.export_button.setEnabled(False)
|
||||
QTimer.singleShot(0, self.start_scan)
|
||||
|
||||
def _button(self, text, callback, primary=False, icon=None):
|
||||
button = PrimaryPushButton(self) if primary else PushButton(self)
|
||||
button.setText(text)
|
||||
if icon is not None:
|
||||
button.setIcon(icon)
|
||||
button.clicked.connect(callback)
|
||||
return button
|
||||
|
||||
def _card(self, title, subtitle=None, parent=None):
|
||||
card = CardWidget(parent or self)
|
||||
layout = QVBoxLayout(card)
|
||||
layout.setContentsMargins(16, 14, 16, 16)
|
||||
layout.setSpacing(9)
|
||||
layout.addWidget(StrongBodyLabel(title, card))
|
||||
if subtitle:
|
||||
caption = CaptionLabel(subtitle, card)
|
||||
caption.setWordWrap(True)
|
||||
layout.addWidget(caption)
|
||||
return card, layout
|
||||
|
||||
def _text(self, mono=False, parent=None):
|
||||
text = PlainTextEdit(parent or self)
|
||||
text.setReadOnly(True)
|
||||
text.setLineWrapMode(QPlainTextEdit.NoWrap)
|
||||
if mono:
|
||||
text.setFont(QFontDatabase.systemFont(QFontDatabase.FixedFont))
|
||||
return text
|
||||
|
||||
def _build_ui(self):
|
||||
root = QWidget(self)
|
||||
root.setObjectName("root")
|
||||
outer = QVBoxLayout(root)
|
||||
outer.setContentsMargins(22, 18, 22, 18)
|
||||
outer.setSpacing(14)
|
||||
|
||||
header = QHBoxLayout()
|
||||
title_box = QVBoxLayout()
|
||||
title_box.setSpacing(1)
|
||||
title_box.addWidget(SubtitleLabel("EDID Viewer", root))
|
||||
title_box.addWidget(BodyLabel("显示设备能力与原始数据", root))
|
||||
header.addLayout(title_box)
|
||||
header.addStretch(1)
|
||||
header.addWidget(BodyLabel("外观", root))
|
||||
self.theme_choice = ComboBox(root)
|
||||
self.theme_choice.setAccessibleName("外观主题")
|
||||
for label, value in (
|
||||
("跟随系统", "system"),
|
||||
("Light · 浅色", "light"),
|
||||
("Dark · 深色", "dark"),
|
||||
("dark1 · 蓝色", "dark1"),
|
||||
("dark2 · 青色", "dark2"),
|
||||
):
|
||||
self.theme_choice.addItem(label)
|
||||
self.theme_choice.setItemData(self.theme_choice.count() - 1, value)
|
||||
self.theme_choice.setCurrentIndex(self.theme_choice.findData(self.theme_manager.mode))
|
||||
self.theme_choice.currentIndexChanged.connect(
|
||||
lambda: self.theme_manager.set_mode(self.theme_choice.currentData())
|
||||
)
|
||||
header.addWidget(self.theme_choice)
|
||||
header.addWidget(self._button("关于", self.show_about))
|
||||
outer.addLayout(header)
|
||||
|
||||
note = CaptionLabel(
|
||||
"Windows 驱动提供的 EDID,可能包含缓存或覆盖;EDID 是接收端声明能力,不代表当前实际输出。",
|
||||
root,
|
||||
)
|
||||
note.setWordWrap(True)
|
||||
outer.addWidget(note)
|
||||
|
||||
split = QSplitter(Qt.Vertical, root)
|
||||
split.setChildrenCollapsible(False)
|
||||
split.setHandleWidth(8)
|
||||
split.addWidget(self._build_sidebar())
|
||||
split.addWidget(self._build_content())
|
||||
split.setStretchFactor(0, 0)
|
||||
split.setStretchFactor(1, 1)
|
||||
split.setSizes([150, 620])
|
||||
outer.addWidget(split, 1)
|
||||
self.setCentralWidget(root)
|
||||
|
||||
def _build_sidebar(self):
|
||||
host = QWidget(self)
|
||||
host.setMinimumHeight(132)
|
||||
host.setMaximumHeight(210)
|
||||
layout = QHBoxLayout(host)
|
||||
layout.setContentsMargins(2, 2, 2, 2)
|
||||
layout.setSpacing(12)
|
||||
|
||||
card, body = self._card("显示设备", "选择活动输出并读取驱动提供的原始 EDID。", host)
|
||||
card.setMinimumWidth(360)
|
||||
self.devices = ComboBox(card)
|
||||
self.devices.setMinimumHeight(38)
|
||||
self.devices.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
|
||||
device_row = QHBoxLayout()
|
||||
device_row.setSpacing(8)
|
||||
device_row.addWidget(self.devices, 1)
|
||||
self.refresh_button = self._button("刷新设备", self.start_scan, icon=FluentIcon.SYNC)
|
||||
self.refresh_button.setMinimumWidth(116)
|
||||
device_row.addWidget(self.refresh_button)
|
||||
body.addLayout(device_row)
|
||||
layout.addWidget(card)
|
||||
|
||||
card, body = self._card("离线文件", "适用于 .bin、.edid、.hex 和纯十六进制 .txt。", host)
|
||||
card.setMinimumWidth(430)
|
||||
self.open_button = self._button("打开 EDID", self.open_file, primary=True, icon=FluentIcon.FOLDER)
|
||||
self.bin_button = self._button("导出 BIN", self.save_bin, icon=FluentIcon.DOWNLOAD)
|
||||
self.export_button = self._button("导出 JSON 报告", self.save_report, icon=FluentIcon.SAVE)
|
||||
file_row = QHBoxLayout()
|
||||
file_row.setSpacing(8)
|
||||
for button in (self.open_button, self.bin_button, self.export_button):
|
||||
button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
|
||||
file_row.addWidget(button, 1)
|
||||
body.addLayout(file_row)
|
||||
layout.addWidget(card)
|
||||
|
||||
layout.setStretch(0, 1)
|
||||
layout.setStretch(1, 1)
|
||||
return host
|
||||
|
||||
def _build_content(self):
|
||||
card = CardWidget(self)
|
||||
layout = QVBoxLayout(card)
|
||||
layout.setContentsMargins(18, 16, 18, 18)
|
||||
layout.setSpacing(12)
|
||||
self.summary = BodyLabel("正在读取设备…", card)
|
||||
self.summary.setWordWrap(True)
|
||||
layout.addWidget(self.summary)
|
||||
|
||||
self.tabs = QTabWidget(card)
|
||||
self.tabs.setDocumentMode(True)
|
||||
self.tree = TreeWidget(card)
|
||||
self.tree.setHeaderLabels(["项目", "详细信息"])
|
||||
self.tree.setColumnWidth(0, 260)
|
||||
self.tree.setAlternatingRowColors(True)
|
||||
self.tabs.addTab(self.tree, "设备与能力")
|
||||
|
||||
self.timings = TreeWidget(card)
|
||||
self.timings.setHeaderLabels(["来源 / 字段", "分辨率 / 数值", "刷新率"])
|
||||
self.timings.setColumnWidth(0, 255)
|
||||
self.timings.setColumnWidth(1, 360)
|
||||
self.timings.setAlternatingRowColors(True)
|
||||
self.tabs.addTab(self.timings, "分辨率与时序")
|
||||
|
||||
self.hex = self._text(mono=True, parent=card)
|
||||
self.tabs.addTab(self.hex, "原始 HEX")
|
||||
self.details = self._text(mono=True, parent=card)
|
||||
self.tabs.addTab(self.details, "完整解析 JSON")
|
||||
layout.addWidget(self.tabs, 1)
|
||||
|
||||
self.devices.currentIndexChanged.connect(self.select_device)
|
||||
return card
|
||||
|
||||
def show_about(self):
|
||||
QMessageBox.about(
|
||||
self,
|
||||
f"关于 {APP_NAME}",
|
||||
f"{APP_NAME} v{APP_VERSION}\n\n"
|
||||
"Windows 显示器 EDID 查看器 · 只读,不修改显示设置\n"
|
||||
"PySide6-Fluent-Widgets UI\n\n"
|
||||
f"{REPO_URL}",
|
||||
)
|
||||
|
||||
def start_scan(self):
|
||||
if self.worker and self.worker.isRunning():
|
||||
return
|
||||
self.refresh_button.setEnabled(False)
|
||||
self.open_button.setEnabled(False)
|
||||
self.statusBar().showMessage("正在读取活动设备…")
|
||||
self.worker = Scanner(self)
|
||||
self.worker.result.connect(self.scanned)
|
||||
self.worker.failure.connect(self.scan_failed)
|
||||
self.worker.finished.connect(lambda: self.refresh_button.setEnabled(True))
|
||||
self.worker.finished.connect(lambda: self.open_button.setEnabled(True))
|
||||
self.worker.start()
|
||||
|
||||
def scan_failed(self, message):
|
||||
self.statusBar().showMessage("设备读取失败,可打开离线 EDID 文件")
|
||||
self.summary.setText("Windows EDID 读取失败:" + message)
|
||||
|
||||
def scanned(self, items):
|
||||
old = self.devices.currentData()
|
||||
old_id = old.get("instance") if old else None
|
||||
self.devices.blockSignals(True)
|
||||
self.devices.clear()
|
||||
selected = 0
|
||||
for index, item in enumerate(items):
|
||||
name = item["instance"]
|
||||
try:
|
||||
info = parse(item["raw"])["基本信息"]
|
||||
name = info.get("显示器名称", info.get("厂家 PNP 代码", name))
|
||||
except ValueError:
|
||||
pass
|
||||
self.devices.addItem(
|
||||
f'{item["连接"]} · {name} · {item["instance"]}',
|
||||
userData=item,
|
||||
)
|
||||
if item["instance"] == old_id:
|
||||
selected = index
|
||||
self.devices.setCurrentIndex(selected)
|
||||
self.devices.blockSignals(False)
|
||||
self.select_device()
|
||||
self.statusBar().showMessage(f"找到 {len(items)} 个活动设备;未启用的输出可能不会列出")
|
||||
|
||||
def select_device(self, *_):
|
||||
item = self.devices.currentData()
|
||||
if item:
|
||||
self.show_raw(item["raw"], item["instance"] + " / " + item["连接"], item["error"])
|
||||
else:
|
||||
self.show_raw(b"", "未找到活动显示器。可刷新或打开离线文件。")
|
||||
|
||||
def show_raw(self, raw, source, error=""):
|
||||
self.raw = raw
|
||||
self.report = {}
|
||||
self.tree.clear()
|
||||
self.timings.clear()
|
||||
self.details.clear()
|
||||
self.hex.setPlainText(hex_dump(raw))
|
||||
self.bin_button.setEnabled(bool(raw))
|
||||
self.export_button.setEnabled(False)
|
||||
try:
|
||||
report = parse(raw)
|
||||
except ValueError as exc:
|
||||
self.summary.setText(f"{source}\n{error or str(exc)}")
|
||||
return
|
||||
|
||||
self.report = {"来源": source, "读取错误": error, **report, "原始 HEX": raw.hex(" ")}
|
||||
self.export_button.setEnabled(True)
|
||||
messages = report["警告"] + [item for item in report["校验"] if "失败" in item]
|
||||
if error:
|
||||
messages.insert(0, error)
|
||||
status = "各块校验通过" if not messages else "⚠ " + ";".join(messages)
|
||||
self.summary.setText(f"{source}\n{len(raw)} 字节 · {status}")
|
||||
|
||||
for group in ("基本信息", "能力", "校验", "警告", "数据块"):
|
||||
parent = QTreeWidgetItem(self.tree, [group])
|
||||
value = report[group]
|
||||
rows = value.items() if isinstance(value, dict) else enumerate(value, 1)
|
||||
for key, item in rows:
|
||||
rendered = json.dumps(item, ensure_ascii=False) if isinstance(item, (dict, list)) else str(item)
|
||||
QTreeWidgetItem(parent, [str(key), rendered])
|
||||
parent.setExpanded(group != "数据块")
|
||||
|
||||
for timing in report["时序"]:
|
||||
parent = QTreeWidgetItem(self.timings, [timing["来源"], timing["分辨率"], timing.get("刷新率", "")])
|
||||
for key, value in timing.items():
|
||||
if key not in ("来源", "分辨率", "刷新率"):
|
||||
QTreeWidgetItem(parent, [key, str(value)])
|
||||
self.details.setPlainText(json.dumps(self.report, ensure_ascii=False, indent=2))
|
||||
|
||||
def open_path(self, path):
|
||||
try:
|
||||
raw = read_file(path)
|
||||
self.devices.blockSignals(True)
|
||||
self.devices.setCurrentIndex(-1)
|
||||
self.devices.blockSignals(False)
|
||||
self.show_raw(raw, "文件:" + str(path))
|
||||
except (OSError, ValueError, UnicodeError) as exc:
|
||||
QMessageBox.warning(self, "无法打开", str(exc))
|
||||
|
||||
def open_file(self):
|
||||
path, _ = QFileDialog.getOpenFileName(
|
||||
self,
|
||||
"打开 EDID",
|
||||
"",
|
||||
"EDID (*.bin *.edid *.hex *.txt);;全部文件 (*)",
|
||||
)
|
||||
if path:
|
||||
self.open_path(path)
|
||||
|
||||
def save_bin(self):
|
||||
path, _ = QFileDialog.getSaveFileName(self, "导出原始 EDID", "edid.bin", "BIN (*.bin)")
|
||||
if path:
|
||||
self.write(path, self.raw)
|
||||
|
||||
def save_report(self):
|
||||
path, _ = QFileDialog.getSaveFileName(self, "导出报告", "edid-report.json", "JSON (*.json)")
|
||||
if path:
|
||||
self.write(path, json.dumps(self.report, ensure_ascii=False, indent=2).encode("utf-8"))
|
||||
|
||||
def write(self, path, data):
|
||||
try:
|
||||
Path(path).write_bytes(data)
|
||||
self.statusBar().showMessage("已保存:" + path)
|
||||
except OSError as exc:
|
||||
QMessageBox.warning(self, "保存失败", str(exc))
|
||||
|
||||
def closeEvent(self, event):
|
||||
if self.worker and self.worker.isRunning():
|
||||
self.statusBar().showMessage("正在读取,请等待读取完成后关闭(最长约 45 秒)")
|
||||
event.ignore()
|
||||
else:
|
||||
event.accept()
|
||||
|
||||
|
||||
def main():
|
||||
if sys.platform == "win32":
|
||||
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("LT8619C.Tools.EDIDViewer")
|
||||
app = QApplication(sys.argv)
|
||||
app.setApplicationName(APP_NAME)
|
||||
app.setFont(QFont("Microsoft YaHei UI", 10))
|
||||
app.setWindowIcon(QIcon(str(icon_path())))
|
||||
theme_manager = ThemeManager(app)
|
||||
window = Window(theme_manager)
|
||||
window.show()
|
||||
return app.exec()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
组装 EDID-Viewer 发布包: exe + README → 一个 zip(解压即用)
|
||||
================================================
|
||||
把主 README 复制进 release/ 后, 与单文件 exe 一起压成 zip —— 两者内容一致。
|
||||
|
||||
zip 解压后根目录为 EDID-Viewer/:
|
||||
EDID-Viewer.exe 主程序(先运行 build_exe.py 打包)
|
||||
README.md 使用说明
|
||||
|
||||
用法:
|
||||
python package_release.py 版本号自动取最近 git tag(EDID-Viewer-v*)
|
||||
python package_release.py 0.1.0 手动指定版本号
|
||||
产物: release/EDID-Viewer-v<版本>-win64.zip(zip 不入库, 上传到 Gitea Release)
|
||||
"""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import zipfile
|
||||
|
||||
SRC = os.path.dirname(os.path.abspath(__file__))
|
||||
BASE = os.path.dirname(SRC)
|
||||
RELEASE = os.path.join(BASE, 'release')
|
||||
|
||||
|
||||
def detect_version():
|
||||
"""从最近的 EDID-Viewer-v* tag 推断版本号, 无 tag 则报错提示手动指定"""
|
||||
try:
|
||||
out = subprocess.check_output(
|
||||
['git', 'describe', '--tags', '--abbrev=0', '--match', 'EDID-Viewer-v*'],
|
||||
cwd=BASE, stderr=subprocess.DEVNULL)
|
||||
return out.decode().strip().removeprefix('EDID-Viewer-v')
|
||||
except Exception:
|
||||
sys.exit('未能从 git tag 推断版本号, 请手动指定: python package_release.py <版本号>')
|
||||
|
||||
|
||||
def main():
|
||||
version = (sys.argv[1] if len(sys.argv) > 1 else detect_version()).lstrip('v')
|
||||
exe = os.path.join(RELEASE, 'EDID-Viewer.exe')
|
||||
readme = os.path.join(BASE, 'README.md')
|
||||
if not os.path.exists(exe):
|
||||
sys.exit('缺少 release/EDID-Viewer.exe, 先运行: python build_exe.py')
|
||||
if not os.path.exists(readme):
|
||||
sys.exit(f'缺少 {readme}')
|
||||
|
||||
shutil.copy2(readme, os.path.join(RELEASE, 'README.md'))
|
||||
zip_name = f'EDID-Viewer-v{version}-win64.zip'
|
||||
zip_path = os.path.join(RELEASE, zip_name)
|
||||
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as z:
|
||||
z.write(exe, f'EDID-Viewer/{os.path.basename(exe)}')
|
||||
z.write(os.path.join(RELEASE, 'README.md'), 'EDID-Viewer/README.md')
|
||||
print(f'发布文件夹: {RELEASE} (exe + README)')
|
||||
print(f'发布包: {zip_path} ({os.path.getsize(zip_path) / 1024 / 1024:.1f} MB)')
|
||||
print('下一步上传: python publish_gitea.py', zip_name)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,154 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
创建/更新 Gitea Release 并上传发布 zip(纯标准库, 无需安装依赖)
|
||||
================================================================
|
||||
用法:
|
||||
python publish_gitea.py EDID-Viewer-v0.1.0-win64.zip
|
||||
python publish_gitea.py <zip> --notes-file release/notes-v0.1.0.md
|
||||
python publish_gitea.py <zip> --tag EDID-Viewer-v0.1.0 --replace
|
||||
|
||||
行为:
|
||||
- tag 与版本默认取 zip 文件名(EDID-Viewer-vX.Y.Z-win64.zip → EDID-Viewer-vX.Y.Z)
|
||||
- release 不存在则创建(tag 不存在时 Gitea 在默认分支头自动建 tag);
|
||||
已存在则复用, 仅上传/更新资产
|
||||
- release 上已有同名资产时: 默认跳过, --replace 删旧再传
|
||||
- API token: --token 参数或环境变量 GITEA_TOKEN(需该仓库写权限)
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import ssl
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
import uuid
|
||||
|
||||
DEFAULT_NOTES = """## EDID-Viewer {version}
|
||||
|
||||
Windows 显示器 EDID 查看器(LT8619C 调试工具集配套): 只读查看活动显示设备
|
||||
或离线文件的 EDID —— 厂家/序列号/分辨率时序、CTA/HDMI/音频/HDR 能力、
|
||||
校验诊断, 支持 BIN/HEX 导入与 BIN/JSON 报告导出。
|
||||
|
||||
### 安装
|
||||
下载 `EDID-Viewer-v{version}-win64.zip`, 解压后双击 `EDID-Viewer.exe`(Windows 10/11 x64, 免安装)。
|
||||
|
||||
### 包内容
|
||||
- `EDID-Viewer.exe` — 主程序
|
||||
- `README.md` — 完整使用说明
|
||||
"""
|
||||
|
||||
|
||||
def git_remote_info():
|
||||
"""从 origin 远程地址解析 API base 与 owner/repo(ssh 端口不影响 https API)"""
|
||||
url = subprocess.check_output(['git', 'remote', 'get-url', 'origin']).decode().strip()
|
||||
m = re.match(r'(?:ssh://git@|git@)([\w.-]+)(?::\d+)?[:/]([\w.-]+)/([\w.-]+?)(?:\.git)?$', url)
|
||||
if not m:
|
||||
sys.exit(f'无法从 origin 解析 Gitea 地址: {url}')
|
||||
host, owner, repo = m.groups()
|
||||
return f'https://{host}', owner, repo
|
||||
|
||||
|
||||
class Api:
|
||||
def __init__(self, base, owner, repo, token, insecure):
|
||||
self.api = f'{base}/api/v1/repos/{owner}/{repo}'
|
||||
self.headers = {'Authorization': f'token {token}'}
|
||||
self.ctx = ssl._create_unverified_context() if insecure else None
|
||||
|
||||
def request(self, method, path, data=None, headers=None, retries=4):
|
||||
"""发请求; 实例 TLS 间歇性抽风(SSL UNEXPECTED_EOF), 连接级错误自动重试"""
|
||||
last = None
|
||||
for attempt in range(retries):
|
||||
req = urllib.request.Request(self.api + path, data=data, method=method,
|
||||
headers={**self.headers, **(headers or {})})
|
||||
try:
|
||||
with urllib.request.urlopen(req, context=self.ctx) as resp:
|
||||
body = resp.read()
|
||||
return resp.status, json.loads(body) if body else None
|
||||
except urllib.error.HTTPError as e:
|
||||
return e.code, json.loads(e.read() or b'{}')
|
||||
except (urllib.error.URLError, ssl.SSLError, OSError) as e:
|
||||
last = e
|
||||
time.sleep(1.0 + attempt)
|
||||
raise RuntimeError(f'Gitea 请求连续 {retries} 次失败: {last}')
|
||||
|
||||
def get_json(self, path):
|
||||
status, data = self.request('GET', path)
|
||||
return data if status == 200 else None
|
||||
|
||||
def upload_asset(self, release_id, filepath, replace):
|
||||
name = os.path.basename(filepath)
|
||||
status, rel = self.request('GET', f'/releases/{release_id}')
|
||||
if status != 200:
|
||||
sys.exit(f'读取 release {release_id} 失败: {status} {rel}')
|
||||
# Gitea 版本差异: assets 可能是 {items:[...]} 或纯数组
|
||||
assets = rel.get('assets') or []
|
||||
if isinstance(assets, dict):
|
||||
assets = assets.get('items', [])
|
||||
for asset in assets:
|
||||
if asset['name'] == name:
|
||||
if not replace:
|
||||
print(f'资产 {name} 已存在, 跳过(覆盖请加 --replace)')
|
||||
return
|
||||
self.request('DELETE', f"/releases/{release_id}/assets/{asset['id']}")
|
||||
print(f'已删除旧资产 {name}')
|
||||
boundary = uuid.uuid4().hex
|
||||
payload = open(filepath, 'rb').read()
|
||||
body = (f'--{boundary}\r\n'
|
||||
f'Content-Disposition: form-data; name="attachment"; filename="{name}"\r\n'
|
||||
f'Content-Type: application/octet-stream\r\n\r\n').encode() + payload + \
|
||||
f'\r\n--{boundary}--\r\n'.encode()
|
||||
status, data = self.request(
|
||||
'POST', f'/releases/{release_id}/assets?name={name}', body,
|
||||
{'Content-Type': f'multipart/form-data; boundary={boundary}'})
|
||||
if status != 201:
|
||||
sys.exit(f'上传资产失败: {status} {data}')
|
||||
print(f'已上传资产: {name} ({len(payload) / 1024 / 1024:.1f} MB)')
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument('zipfile_path', help='发布 zip(release/ 下)')
|
||||
ap.add_argument('--tag', help='release 标签, 默认取 zip 文件名去掉 -win64.zip')
|
||||
ap.add_argument('--notes-file', help='release 说明 markdown 文件, 默认用内置模板')
|
||||
ap.add_argument('--token', default=os.environ.get('GITEA_TOKEN'), help='API token')
|
||||
ap.add_argument('--replace', action='store_true', help='覆盖已存在的同名资产')
|
||||
ap.add_argument('--insecure', action='store_true', help='跳过 TLS 证书校验(自签证书)')
|
||||
args = ap.parse_args()
|
||||
|
||||
if not os.path.exists(args.zipfile_path):
|
||||
sys.exit(f'找不到 {args.zipfile_path}')
|
||||
if not args.token:
|
||||
sys.exit('缺少 API token: 传 --token 或设环境变量 GITEA_TOKEN')
|
||||
|
||||
tag = args.tag or re.sub(r'-win64\.zip$', '', os.path.basename(args.zipfile_path))
|
||||
version = tag.removeprefix('EDID-Viewer-v')
|
||||
notes = open(args.notes_file, encoding='utf-8').read() if args.notes_file \
|
||||
else DEFAULT_NOTES.format(version=version)
|
||||
|
||||
base, owner, repo = git_remote_info()
|
||||
api = Api(base, owner, repo, args.token, args.insecure)
|
||||
print(f'目标: {base}/{owner}/{repo} tag={tag}')
|
||||
|
||||
rel = api.get_json(f'/releases/tags/{tag}')
|
||||
if rel:
|
||||
print(f'release 已存在(id={rel["id"]}), 复用')
|
||||
else:
|
||||
status, rel = api.request('POST', '/releases', json.dumps({
|
||||
'tag_name': tag,
|
||||
'name': f'EDID-Viewer v{version}',
|
||||
'body': notes,
|
||||
}).encode(), {'Content-Type': 'application/json'})
|
||||
if status != 201:
|
||||
sys.exit(f'创建 release 失败: {status} {rel}')
|
||||
print(f'release 已创建(id={rel["id"]})')
|
||||
api.upload_asset(rel['id'], args.zipfile_path, args.replace)
|
||||
print(f'完成: {rel.get("html_url", "") or f"{base}/{owner}/{repo}/releases/tag/{tag}"}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,50 @@
|
||||
import random
|
||||
import unittest
|
||||
from edid import parse,dtd
|
||||
|
||||
def checksum(b):
|
||||
b[127]=(-sum(b[:127]))&255
|
||||
return bytes(b)
|
||||
|
||||
def base(ext=0):
|
||||
b=bytearray(128); b[:8]=bytes.fromhex('00ffffffffffff00'); b[8:10]=bytes.fromhex('4c2d')
|
||||
b[18:20]=bytes((1,4)); b[20]=0xa2; b[38:54]=b'\x01\x01'*8; b[126]=ext
|
||||
b[54:72]=bytes.fromhex('023a801871382d40582c4500fd1e1100001e')
|
||||
b[72:90]=b'\0\0\0\xfc\0TEST PANEL\n '
|
||||
return bytearray(checksum(b))
|
||||
|
||||
class Tests(unittest.TestCase):
|
||||
def test_identity_and_dtd(self):
|
||||
r=parse(base()); self.assertEqual(r['基本信息']['显示器名称'],'TEST PANEL')
|
||||
self.assertEqual(r['基本信息']['厂家 PNP 代码'],'SAM')
|
||||
t=r['时序'][0]; self.assertEqual(t['分辨率'],'1920×1080p'); self.assertEqual(t['刷新率'],'60.000 Hz')
|
||||
self.assertEqual(t['同步'],'H+ V+'); self.assertEqual(t['水平有效/前肩/同步/后肩'],[1920,88,44,148])
|
||||
def test_standard(self):
|
||||
b=base(); b[38:40]=bytes((129,192)); r=parse(checksum(b))
|
||||
self.assertEqual(r['时序'][0]['分辨率'],'1280×720'); self.assertEqual(r['时序'][0]['刷新率'],'60 Hz')
|
||||
def test_cta(self):
|
||||
b=bytearray(128); payload=bytes.fromhex('429061 23090707 67030c0012343078 e3060c01')
|
||||
b[:4]=bytes((2,3,4+len(payload),0x70)); b[4:4+len(payload)]=payload
|
||||
r=parse(bytes(base(1))+checksum(b)); text=str(r)
|
||||
self.assertIn('1.2.3.4',text); self.assertIn('PQ / ST 2084',text); self.assertIn('3840×2160p 60 Hz',text)
|
||||
self.assertIn('600 MHz',text); self.assertIn('LPCM',text)
|
||||
def test_missing_extension(self):
|
||||
self.assertTrue(parse(base(2))['警告'])
|
||||
def test_bad_checksum_and_header(self):
|
||||
b=base(); b[0]=1; r=parse(b); self.assertTrue(r['警告']); self.assertIn('失败',r['校验'][0])
|
||||
def test_bounds(self):
|
||||
with self.assertRaises(ValueError): parse(b'\0'*127)
|
||||
b=bytearray(128); b[:5]=bytes((2,3,6,0,0x5f))
|
||||
self.assertIn('越界',str(parse(bytes(base(1))+checksum(b))['警告']))
|
||||
def test_unknown_extension(self):
|
||||
b=bytearray(128); b[0]=0x70
|
||||
self.assertIn('暂未解码',str(parse(bytes(base(1))+checksum(b))))
|
||||
def test_interlaced(self):
|
||||
b=bytes.fromhex('011d8018711c1620582c2500fd1e1100009e')
|
||||
t=dtd(b,'test'); self.assertEqual(t['分辨率'],'1920×1080i'); self.assertEqual(t['刷新率'],'60.000 Hz(场率)')
|
||||
def test_random_malformed(self):
|
||||
rng=random.Random(42)
|
||||
for _ in range(1000):
|
||||
b=bytearray(rng.randbytes(rng.randint(128,600))); b[18]=1; parse(b)
|
||||
|
||||
if __name__=='__main__': unittest.main()
|
||||
@@ -0,0 +1,129 @@
|
||||
"""Theme persistence and Fluent Widgets integration."""
|
||||
|
||||
import ctypes
|
||||
import os
|
||||
|
||||
from PySide6.QtCore import QObject, QSettings, Qt
|
||||
from PySide6.QtGui import QColor, QPalette
|
||||
from qfluentwidgets import Theme, setTheme, setThemeColor
|
||||
|
||||
# Fluent widgets restyle themselves on setTheme(); QMainWindow, the native
|
||||
# QTabWidget/QStatusBar and the Windows title bar keep the OS palette unless
|
||||
# the palette, an app stylesheet and the DWM title bar attributes follow suit
|
||||
# (same approach as DLPilot app_fluent.py).
|
||||
_SURFACES = {
|
||||
False: {"window": "#f4f6f8", "base": "#ffffff", "text": "#1f2328",
|
||||
"dim": "#57606a", "border": "#d8dee4", "selected_text": "#ffffff"},
|
||||
True: {"window": "#202020", "base": "#2b2b2b", "text": "#f5f5f5",
|
||||
"dim": "#9a9a9a", "border": "#3a3a3a", "selected_text": "#1f2328"},
|
||||
}
|
||||
|
||||
|
||||
class ThemeManager(QObject):
|
||||
"""Keep the appearance choice persistent and synchronized with Qt."""
|
||||
|
||||
MODES = {"system", "light", "dark", "dark1", "dark2"}
|
||||
_THEMES = {
|
||||
"system": Theme.AUTO,
|
||||
"light": Theme.LIGHT,
|
||||
"dark": Theme.DARK,
|
||||
"dark1": Theme.DARK,
|
||||
"dark2": Theme.DARK,
|
||||
}
|
||||
_ACCENTS = {
|
||||
"light": "#0f6cbd",
|
||||
"dark": "#f2c94c",
|
||||
"dark1": "#5aa9e6",
|
||||
"dark2": "#35c6c8",
|
||||
}
|
||||
|
||||
def __init__(self, app):
|
||||
super().__init__(app)
|
||||
self.app = app
|
||||
self.window = None
|
||||
self.settings = QSettings("LT8619C-Tools", "EDID-Viewer")
|
||||
mode = self.settings.value("appearance/theme", "system")
|
||||
self.mode = mode if mode in self.MODES else "system"
|
||||
self.apply()
|
||||
app.styleHints().colorSchemeChanged.connect(self.apply)
|
||||
|
||||
def set_window(self, window):
|
||||
"""Register the main window so the native title bar follows the theme."""
|
||||
self.window = window
|
||||
self._apply_titlebar()
|
||||
|
||||
def set_mode(self, mode):
|
||||
if mode not in self.MODES:
|
||||
raise ValueError(f"Unknown theme: {mode}")
|
||||
self.mode = mode
|
||||
self.settings.setValue("appearance/theme", mode)
|
||||
self.apply()
|
||||
|
||||
def is_dark(self):
|
||||
if self.mode in {"dark", "dark1", "dark2"}:
|
||||
return True
|
||||
return self.mode == "system" and self.app.styleHints().colorScheme() == Qt.ColorScheme.Dark
|
||||
|
||||
def apply(self, *_):
|
||||
is_dark = self.is_dark()
|
||||
setTheme(self._THEMES[self.mode])
|
||||
setThemeColor(self._ACCENTS.get(self.mode, self._ACCENTS["light"]))
|
||||
self._apply_palette(is_dark)
|
||||
self._apply_titlebar()
|
||||
|
||||
def _apply_palette(self, is_dark):
|
||||
"""Give native Qt surfaces the same colors as the Fluent widgets."""
|
||||
surface = _SURFACES[is_dark]
|
||||
accent = QColor(self._ACCENTS.get(self.mode, self._ACCENTS["light"]))
|
||||
palette = QPalette()
|
||||
for role, color in (
|
||||
(QPalette.Window, surface["window"]),
|
||||
(QPalette.Base, surface["base"]),
|
||||
(QPalette.AlternateBase, surface["base"]),
|
||||
(QPalette.Text, surface["text"]),
|
||||
(QPalette.WindowText, surface["text"]),
|
||||
(QPalette.Button, surface["base"]),
|
||||
(QPalette.ButtonText, surface["text"]),
|
||||
(QPalette.PlaceholderText, surface["dim"]),
|
||||
(QPalette.Highlight, accent),
|
||||
(QPalette.HighlightedText, surface["selected_text"]),
|
||||
(QPalette.ToolTipBase, surface["base"]),
|
||||
(QPalette.ToolTipText, surface["text"]),
|
||||
):
|
||||
palette.setColor(role, QColor(color))
|
||||
self.app.setPalette(palette)
|
||||
self.app.setStyleSheet(f"""
|
||||
QMainWindow, QWidget#root {{ background-color: {surface['window']}; color: {surface['text']}; }}
|
||||
QTabWidget::pane {{ background: {surface['base']}; border: 1px solid {surface['border']}; border-radius: 6px; }}
|
||||
QTabBar {{ qproperty-drawBase: 0; }}
|
||||
QTabBar::tab {{ background: transparent; color: {surface['dim']}; padding: 6px 16px;
|
||||
border: 1px solid transparent; border-top-left-radius: 6px;
|
||||
border-top-right-radius: 6px; }}
|
||||
QTabBar::tab:selected {{ background: {surface['base']}; color: {surface['text']};
|
||||
border: 1px solid {surface['border']}; }}
|
||||
QTabBar::tab:hover:!selected {{ background: {surface['base']}; }}
|
||||
QSplitter::handle {{ background: {surface['window']}; }}
|
||||
QStatusBar {{ background: {surface['window']}; color: {surface['dim']};
|
||||
border-top: 1px solid {surface['border']}; }}
|
||||
QToolTip {{ background-color: {surface['base']}; color: {surface['text']};
|
||||
border: 1px solid {surface['border']}; }}
|
||||
""")
|
||||
|
||||
def _apply_titlebar(self):
|
||||
"""Ask DWM for a title bar in the current surface color (Win10/11)."""
|
||||
if self.window is None or os.name != "nt" or not hasattr(ctypes, "windll"):
|
||||
return
|
||||
try:
|
||||
hwnd = int(self.window.winId())
|
||||
dwm = ctypes.windll.dwmapi
|
||||
dark = ctypes.c_int(1 if self.is_dark() else 0)
|
||||
dwm.DwmSetWindowAttribute(hwnd, 20, ctypes.byref(dark), ctypes.sizeof(dark))
|
||||
surface = _SURFACES[self.is_dark()]
|
||||
dwm.DwmSetWindowAttribute(hwnd, 35, ctypes.byref(self._colorref(QColor(surface["window"]))), 4)
|
||||
dwm.DwmSetWindowAttribute(hwnd, 36, ctypes.byref(self._colorref(QColor(surface["text"]))), 4)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def _colorref(color):
|
||||
return ctypes.c_int(color.red() | (color.green() << 8) | (color.blue() << 16))
|
||||
@@ -0,0 +1,44 @@
|
||||
"""Read active monitors through Windows WMI; never change display settings."""
|
||||
import json
|
||||
import subprocess
|
||||
|
||||
SCRIPT = r'''
|
||||
$ErrorActionPreference = 'Stop'
|
||||
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)
|
||||
$connections = @{}
|
||||
try { Get-CimInstance -Namespace root/wmi -ClassName WmiMonitorConnectionParams | ForEach-Object { $connections[$_.InstanceName] = [long]$_.VideoOutputTechnology } } catch {}
|
||||
$result = @(Get-CimInstance -Namespace root/wmi -ClassName WmiMonitorDescriptorMethods | Where-Object Active | ForEach-Object {
|
||||
$m = $_
|
||||
$bytes = [System.Collections.Generic.List[byte]]::new()
|
||||
$failure = ''
|
||||
try {
|
||||
$base = Invoke-CimMethod -InputObject $m -MethodName WmiGetMonitorRawEEdidV1Block -Arguments @{BlockId=[byte]0}
|
||||
if (-not $base.ReturnValue -or $base.BlockContent.Count -ne 128) { throw 'Base EDID read failed' }
|
||||
$bytes.AddRange([byte[]]$base.BlockContent)
|
||||
for ($i=1; $i -le [int]$base.BlockContent[126]; $i++) {
|
||||
$ext = Invoke-CimMethod -InputObject $m -MethodName WmiGetMonitorRawEEdidV1Block -Arguments @{BlockId=[byte]$i}
|
||||
if (-not $ext.ReturnValue -or $ext.BlockContent.Count -ne 128) { throw "Extension $i read failed" }
|
||||
$bytes.AddRange([byte[]]$ext.BlockContent)
|
||||
}
|
||||
} catch { $failure = $_.Exception.Message }
|
||||
[pscustomobject]@{instance=$m.InstanceName; connection=$connections[$m.InstanceName]; hex=([BitConverter]::ToString($bytes.ToArray())).Replace('-',''); error=$failure}
|
||||
})
|
||||
ConvertTo-Json -InputObject $result -Depth 4 -Compress
|
||||
'''
|
||||
|
||||
CONNECTIONS = {0:'VGA',4:'DVI',5:'HDMI',6:'LVDS 内屏',10:'DisplayPort',11:'eDP 内屏',15:'Miracast',16:'间接有线显示',2147483648:'内部显示'}
|
||||
|
||||
def scan():
|
||||
import base64
|
||||
command = base64.b64encode(SCRIPT.encode('utf-16le')).decode('ascii')
|
||||
proc = subprocess.run(['powershell.exe','-NoProfile','-NonInteractive','-EncodedCommand',command],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=45,
|
||||
creationflags=subprocess.CREATE_NO_WINDOW)
|
||||
if proc.returncode:
|
||||
raise RuntimeError(proc.stderr.decode('utf-8','replace').strip())
|
||||
data = json.loads(proc.stdout.decode('utf-8-sig'))
|
||||
for item in data:
|
||||
item['raw'] = bytes.fromhex(item.pop('hex'))
|
||||
item['连接'] = CONNECTIONS.get(item['connection'],f'未知 ({item["connection"]})')
|
||||
return data
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
cd /d "%~dp0"
|
||||
start "" ".venv\Scripts\pythonw.exe" "src\main.py"
|
||||
@@ -0,0 +1,48 @@
|
||||
"""Headless check for the About button and dialog: saves header and dialog PNGs."""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from PySide6.QtCore import QTimer
|
||||
from PySide6.QtGui import QFont
|
||||
from PySide6.QtWidgets import QApplication, QMessageBox
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "src"))
|
||||
import main as m
|
||||
|
||||
OUT = Path(__file__).resolve().parent
|
||||
|
||||
|
||||
def snap_dialog():
|
||||
boxes = [w for w in QApplication.topLevelWidgets() if isinstance(w, QMessageBox)]
|
||||
if not boxes:
|
||||
QTimer.singleShot(200, snap_dialog)
|
||||
return
|
||||
boxes[0].grab().save(str(OUT / "about-dialog.png"))
|
||||
boxes[0].close()
|
||||
|
||||
|
||||
def open_about(window):
|
||||
QTimer.singleShot(600, lambda: snap_dialog())
|
||||
window.show_about()
|
||||
|
||||
|
||||
def main():
|
||||
app = QApplication(sys.argv)
|
||||
app.setApplicationName(m.APP_NAME)
|
||||
app.setFont(QFont("Microsoft YaHei UI", 10))
|
||||
theme_manager = m.ThemeManager(app)
|
||||
window = m.Window(theme_manager)
|
||||
window.show()
|
||||
|
||||
def grab_header():
|
||||
window.grab().save(str(OUT / "about-header.png"))
|
||||
open_about(window)
|
||||
|
||||
QTimer.singleShot(1500, grab_header)
|
||||
QTimer.singleShot(6000, app.quit)
|
||||
sys.exit(app.exec())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,30 @@
|
||||
param(
|
||||
[string]$ProcessName = "python",
|
||||
[string]$OutPng = "$env:TEMP\edid-window.png"
|
||||
)
|
||||
Add-Type @"
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
public class Win32Cap {
|
||||
[DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr h, out RECT r);
|
||||
[DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr h);
|
||||
public struct RECT { public int Left, Top, Right, Bottom; }
|
||||
}
|
||||
"@
|
||||
Add-Type -AssemblyName System.Drawing
|
||||
$proc = Get-Process -Name $ProcessName -ErrorAction Stop |
|
||||
Where-Object { $_.MainWindowHandle -ne 0 -and $_.MainWindowTitle -like 'EDID*' } |
|
||||
Select-Object -First 1
|
||||
if (-not $proc) { throw "no EDID window found for process '$ProcessName'" }
|
||||
$hwnd = $proc.MainWindowHandle
|
||||
[Win32Cap]::SetForegroundWindow($hwnd) | Out-Null
|
||||
Start-Sleep -Milliseconds 800
|
||||
$r = New-Object Win32Cap+RECT
|
||||
[Win32Cap]::GetWindowRect($hwnd, [ref]$r) | Out-Null
|
||||
$w = $r.Right - $r.Left; $h2 = $r.Bottom - $r.Top
|
||||
$bmp = New-Object System.Drawing.Bitmap($w, $h2)
|
||||
$g = [System.Drawing.Graphics]::FromImage($bmp)
|
||||
$g.CopyFromScreen($r.Left, $r.Top, 0, 0, (New-Object System.Drawing.Size($w, $h2)))
|
||||
$bmp.Save($OutPng, [System.Drawing.Imaging.ImageFormat]::Png)
|
||||
$g.Dispose(); $bmp.Dispose()
|
||||
Write-Output "saved $OutPng ($w x $h2)"
|
||||
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"instance": "DISPLAY\\SDC420B\\4&1387f127&0&UID8388688_0",
|
||||
"connection": 2147483648,
|
||||
"error": "常规故障 ",
|
||||
"连接": "内部显示",
|
||||
"基本信息": {
|
||||
"厂家 PNP 代码": "SDC",
|
||||
"产品编号": "0x420B",
|
||||
"数字序列号": 0,
|
||||
"EDID 版本": "1.4",
|
||||
"生产日期": "2024 年 / 周未指定",
|
||||
"尺寸": "34 × 22 cm",
|
||||
"Gamma": 2.2,
|
||||
"扩展块数": 2,
|
||||
"SHA-256": "16f168eda782b8d49c3ef5cdf46cb894c353c6ef2570629707b72a0cdefb9584",
|
||||
"输入类型": "数字",
|
||||
"接口声明": "DisplayPort",
|
||||
"色深 bpc": 10,
|
||||
"频率范围原始值": "垂直 48–240 Hz;水平 177–177 kHz;最大像素时钟 1170 MHz",
|
||||
"描述文本": "SDC",
|
||||
"显示器名称": "ATNA60HU01-0"
|
||||
},
|
||||
"时序": [],
|
||||
"能力": [
|
||||
"色度坐标:Rx=0.6807, Ry=0.3184, Gx=0.2197, Gy=0.7246, Bx=0.1426, By=0.0391, Wx=0.3135, Wy=0.3291"
|
||||
],
|
||||
"数据块": [
|
||||
{
|
||||
"块": 1,
|
||||
"类型": "DisplayID(暂未解码)",
|
||||
"原始": "70 20 79 02 00 20 00 0c ba 41 59 0b 42 00 00 00 00 00 18 00 21 00 1d 74 0d 69 08 00 0a 40 06 00 e5 7a 51 85 a3 b9 4a 02 0a 02 45 54 d0 5f 4c 64 00 45 23 78 26 00 09 06 00 00 00 00 00 50 00 00 22 00 28 80 c5 11 85 ff 09 87 00 07 00 1f 00 3f 06 c7 00 7f 00 07 00 80 c5 11 05 ff 09 87 00 07 00 1f 00 3f 06 df 15 97 15 07 00 81 00 0b e3 05 80 00 e6 06 05 01 8f 6a 02 00 00 00 00 00 f1 90"
|
||||
}
|
||||
],
|
||||
"校验": [
|
||||
"块 0: 通过",
|
||||
"块 1: 通过"
|
||||
],
|
||||
"警告": [
|
||||
"声明 384 字节,实际 256 字节",
|
||||
"范围描述符有扩展偏移,频率范围显示原始字段,暂未应用偏移"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x4C, 0x2D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x3A, 0x80, 0x18, 0x71, 0x38, 0x2D, 0x40, 0x58, 0x2C, 0x45, 0x00, 0xFD, 0x1E, 0x11, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x54, 0x45, 0x53, 0x54, 0x20, 0x50, 0x41, 0x4E, 0x45, 0x4C, 0x0A, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC2, 0x02, 0x03, 0x17, 0x70, 0x42, 0x90, 0x61, 0x23, 0x09, 0x07, 0x07, 0x67, 0x03, 0x0C, 0x00, 0x12, 0x34, 0x30, 0x78, 0xE3, 0x06, 0x0C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAD
|
||||
@@ -1,155 +0,0 @@
|
||||
# AGENTS.md — DLPilot 工程档案(供 AI/Agent 使用)
|
||||
|
||||
> **本文档面向 AI/Agent**,是人类文档 [README.md](README.md) 的姊妹篇,两者不重叠:
|
||||
> README 回答"这是什么、怎么用";本文回答"代码怎么组织、怎么构建发布、改动时哪些约束不能破坏"。
|
||||
> 任何 Agent 在修改本目录代码前应先读完本文。
|
||||
|
||||
## 1. 项目定位
|
||||
|
||||
仓库 `LT8619C_Debug_Tools` 是 LT8619C(HDMI→RGB888)→ DLPC3421 投影转接板的**调试上位机工具集**,
|
||||
上游主仓库(固件)为 `hulk/LT8619C_DLPC3421_HDMI`(同 Gitea 实例 `gitea.hulk.wang`),
|
||||
本仓库本机路径 `E:\Hulk-Coding\LT8619C_DLPC3421_HDMI`。
|
||||
DLPilot 工作在两端:HDMI **源端**(PC 显卡侧,EDID/分辨率/图案)与**光机控制端**
|
||||
(RS485 → 板载 GD32E230 网关 → DLPC3421)。寄存器语义判读基线(0x606E 位交换 /
|
||||
0x606D 整组顺序)与光机协议规程都在上游仓库 `doc/architecture/` 与 `protocols.md`,不在本仓库。
|
||||
|
||||
## 2. 目录契约(重要)
|
||||
|
||||
```
|
||||
DLPilot/
|
||||
├── src/ 源代码区 —— 只有这里可以手改(logos/ 改图标源后重跑 make_ico.py)
|
||||
├── assets/ 生成资产区 —— gen_*.py 的产物(PNG 图案),可随时再生成,改动需提交
|
||||
├── release/ 产物区 —— 机器生成,禁止手改:DLPilot.exe、pattern_slots.json、
|
||||
│ bw/solid 图案(package_release.py 从 assets/ 平铺复制来,均入库)、
|
||||
│ *.zip(gitignore,只上传 Release)。release/ 本身=完整可直接运行的
|
||||
│ 发布文件夹(exe+附属平铺),内容与 zip 一致
|
||||
├── README.md 人类文档
|
||||
└── AGENTS.md 本文
|
||||
```
|
||||
|
||||
划分原则:**"人写的"在 src/,"生成的"按去向分 assets/(随包分发)与 release/(直接交付)**。
|
||||
新文件必须落对区域;不要在 src/ 外新建源码,不要手改 assets/ 下的 PNG(改生成脚本再跑)。
|
||||
|
||||
### 文件角色速查
|
||||
|
||||
| 文件 | 角色 |
|
||||
|---|---|
|
||||
| `src/hdmi_gui.py` | 入口: argparse 命令行分发(--dump/--edid-fields/--test-pattern/--dlpc-cmd/--seconds), GUI 委托 app_gui |
|
||||
| `src/app_gui.py` | CustomTkinter 主界面: 双栏仪表盘(左 HDMI 源端五卡/右 光机四卡), 光强/定时快捷滑条 |
|
||||
| `src/display_win.py` | Win32 显示器枚举/分辨率切换/智能拓扑(纯 ctypes) |
|
||||
| `src/edid_parse.py` | EDID 1.4/CEA-861 解析(纯标准库, 上游 lt8619c_edid.c 以此为参考解码器) |
|
||||
| `src/patterns.py` | 测试图案全屏投屏窗口(tkinter, ESC 退出, 测试卡区域 1:1 居中) |
|
||||
| `src/config.py` | 运行目录定位(BASE_DIR)与 pattern_slots.json 读写(slots/area/serial 三键) |
|
||||
| `src/dlpc_rs485.py` | 光机 RS485 协议模块: 帧构造/增量解析/译码表/预设命令/串口线程(DLPC485) |
|
||||
| `src/selftest_rs485.py` | 光机协议自检(对照上游实测帧向量, 无硬件回归, 改协议代码后必跑) |
|
||||
| `src/build_exe.py` | PyInstaller 打包 → `release/DLPilot.exe`(onefile/noconsole, 内嵌图标+pyserial+customtkinter) |
|
||||
| `src/package_release.py` | 复制图案到 release/(平铺) → `release/DLPilot-v<ver>-win64.zip`(校验栏位引用完整性; release/ 与 zip 内容一致) |
|
||||
| `src/publish_gitea.py` | 建/复用 Gitea Release 并上传 zip(tag 默认取 zip 文件名) |
|
||||
| `src/hdmi_source.ps1/.bat` | 独立 PowerShell 命令行工具(自包含,与 GUI 无代码共享) |
|
||||
| `src/gen_bw_patterns.py` | 生成 `assets/bw_*.png` ×5(640x360 黑白,需 Pillow) |
|
||||
| `src/gen_solid_colors.py` | 生成 `assets/solid_*.png` ×10(800x600 纯色,需 Pillow) |
|
||||
| `src/la_wave_analyzer*.py` | 逻辑分析仪 CSV 波形判读(2/3 通道,40MHz 像素时钟假设) |
|
||||
| `src/logos/make_ico.py` | svg/png → ico(写在其自身目录) |
|
||||
| `release/pattern_slots.json` | 预置栏位:西门子星/波带片/综合测试卡,area=640x360;`serial` 键记忆光机串口 |
|
||||
| `UI参考布局.svg/.png` | 界面布局设计稿(app_gui.py 双栏布局的规格来源, 随分支入库) |
|
||||
|
||||
## 3. 代码不变量(改 hdmi_gui.py 必须维持)
|
||||
|
||||
1. **依赖分层**:CLI/显示/EDID/协议/配置模块(display_win/edid_parse/patterns/config/
|
||||
dlpc_rs485)纯标准库;customtkinter 是 GUI(app_gui)的**硬依赖**(装了才能开界面,
|
||||
CLI 不受影响)。可选依赖仍走"try-import + HAS_* 标志 + 缺失降级"模式:Pillow、
|
||||
pyserial——缺失时对应功能禁用/提示安装,其余功能必须照常工作。
|
||||
2. **模块边界**:hdmi_gui.py 只是入口, 不放实现; GUI 不直接碰 ctypes/winreg
|
||||
(显示器走 display_win, EDID 走 edid_parse); pyserial 只准在 dlpc_rs485.py 里 import
|
||||
(hdmi_gui/app_gui 经 `dlpc_rs485.HAS_SERIAL` 与 `DLPC485` 类间接使用)。
|
||||
3. **BASE_DIR 语义**(定义在 config.py):frozen(PyInstaller onefile)时
|
||||
`BASE_DIR=exe 所在目录`(`sys.executable`),源码运行时 `=config.py 所在目录`
|
||||
(即 src/)。所有用户数据(pattern_slots.json、自定义图片)都写/读自 BASE_DIR
|
||||
**平铺**存放,不建子目录。
|
||||
4. **自定义栏位 `file` 字段是裸文件名**:加载时 `os.path.join(BASE_DIR, file)` 解析,
|
||||
因此 pattern_slots.json 引用的图片必须与 exe 同目录 —— package_release.py 正是按此平铺打包。
|
||||
5. **exe 自包含**:图标经 `--add-data` 内嵌(运行时从 `_MEIPASS` 读);内置五种图案
|
||||
(红/绿/蓝/棋盘格/网格线)由程序绘制,运行时**不依赖** assets/;solid/bw PNG 只服务自定义栏位。
|
||||
6. **DPI 感知**:进程启动即 `SetProcessDpiAwareness(2)`,图案窗口按物理像素定位,勿移除。
|
||||
7. **智能显示拓扑(勿改回无条件扩展)**:启动时枚举"接入但不在桌面"的显示器,仅当其
|
||||
EDID 厂商字节为转接板签名 `61 93`(压缩码 "XLS",上游 lt8619c_edid.c)时才
|
||||
`SetDisplayConfig(SDC_TOPOLOGY_EXTEND|SDC_APPLY)` 拉回桌面,静默容错。动机:板卡
|
||||
热插拔后 Windows 可能停留在"仅电脑屏幕"导致枚举不到板卡。用户主动选择的拓扑
|
||||
(家里的"仅第二屏幕"等,未激活的是笔记本内屏,厂商非 XLS)一律不动。
|
||||
8. **分辨率切换是临时的**:走 `CHANGEDISPLAYSETTINGS`(不写注册表),"恢复"用会话开始时快照。
|
||||
9. **EDID 来源是注册表**(`HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\...\Device Parameters\EDID`),
|
||||
不是 WMI/DDC;exe 的 noconsole 版无 stdout,`--dump/--edid-fields` 只在源码/控制台版可用。
|
||||
10. **光机串口线程回调不直接碰 GUI**:DLPC485 的 on_event/on_status 在后台线程触发,
|
||||
必须经 `queue.Queue` + `root.after(80, …)` 轮询投递回主线程(现行 `_poll_dlpc` 模式,
|
||||
与 I2C-Inject 的 Injector 同源);退出路径(关窗与 `--seconds` 自动关)都会走到
|
||||
`App.destroy()`,在那里 `dlpc.close()` 收线程。
|
||||
11. **pattern_slots.json 格式**:`{'area', 'slots', 'serial'}` 三键共存;load 兼容旧版
|
||||
纯数组(无 area)与无 serial 键两种历史格式,save 永远写全三键。`serial` 子键为
|
||||
`{port, baud, bytesize(8/7/6/5), parity(N/E/O), stopbits(1/2)}`,旧配置缺子键按
|
||||
默认 8-N-1 补齐。
|
||||
12. **GUI = app_gui.py 双栏仪表盘**(规格:`DLPilot/UI参考布局.svg`):左列 HDMI 源端
|
||||
五卡(显示器/模式/EDID 信息/测试图案/hex),右列光机四卡(串口/数据/命令/滑条),
|
||||
顶栏 Dark/Light/System 切换(ttk.Treeview 颜色随动)。打包必须 `--collect-all
|
||||
customtkinter`(build_exe.py 已内置,勿删)——CTk 主题/字体数据缺失会让 exe 启动即崩。
|
||||
|
||||
## 4. 领域语义(测试值都有含义,勿"顺手改")
|
||||
|
||||
- 纯色值 55/AA/FF:55(01010101) 与 AA(10101010) 互为字节镜像对(检出位序颠倒/位交换),
|
||||
FF(11111111) 全高基准;R/G/B 三行对应 RGB888 三字节组(R=D[23:16]/G=D[15:8]/B=D[7:0])。
|
||||
- 800x600@60:LT8619C **demo 板** shadow EDID 首选时序(solid 系列分辨率与之一致)。
|
||||
- 640x360:测试卡区域默认值(16:9 半分辨率,点对点检查用);full=铺满所选屏。
|
||||
**同时是转接板光机 DLPC3421 的 nHD 面板原生分辨率**(该板 shadow EDID 只声明 640x360@60),
|
||||
投 640x360 图案 + RS485 开光机 = 整链路 1:1 验证。
|
||||
- bw 系列图案各自目的见 `src/gen_bw_patterns.py` 顶部清单注释。
|
||||
- 光机 RS485 命令集(M730/M731/M732/M201/M202/M737/M999/M888/M7/M8/M1)语义、
|
||||
帧格式 `D5 01 LEN <ASCII> CRC`(累加和校验)、错误码与**就绪门禁**
|
||||
(DLPC 未就绪时 M730/M731/M732 被拒回 0xFF)以上游 `protocols.md` 为唯一权威,
|
||||
本仓不维护协议文档副本;注意 **M7S0 是"开启"TEC 自动控温**(方向反直觉)、
|
||||
M737 在定时投光中延迟应答(CLI 等待上限 35s)。
|
||||
|
||||
## 5. 构建 / 发布流水线(全部在 src/ 下执行)
|
||||
|
||||
```powershell
|
||||
python gen_bw_patterns.py ; python gen_solid_colors.py # 仅当改了图案生成逻辑
|
||||
python build_exe.py # → ../release/DLPilot.exe(缺 PyInstaller 会自动 pip install)
|
||||
python build_exe.py --debug # 附加带控制台的 DLPilot-console.exe(调试 --dump 用)
|
||||
python package_release.py <版本> # → ../release/DLPilot-v<版本>-win64.zip
|
||||
python publish_gitea.py DLPilot-v<版本>-win64.zip --replace --insecure # 上传(需 GITEA_TOKEN)
|
||||
```
|
||||
|
||||
发布约定:
|
||||
- tag/release 命名 `DLPilot-vX.Y.Z`,zip 命名 `DLPilot-vX.Y.Z-win64.zip`(publish_gitea.py
|
||||
依赖此命名从文件名推 tag);
|
||||
- **exe、pattern_slots.json 与 release/ 下平铺的图案 png 改动跟随源码/资产生成提交入库;
|
||||
zip 永不入库**(.gitignore 已挡);
|
||||
- publish_gitea.py 幂等:release 已存在则复用,同名资产默认跳过,`--replace` 删旧重传;
|
||||
- token 读环境变量 `GITEA_TOKEN`:本机已用 setx 持久化为用户级变量(新开的会话/终端自动
|
||||
继承,值不入库;在 setx 之前启动的进程读不到,需重开终端),急用时也可临时传 `--token`;
|
||||
- Gitea 实例 `gitea.hulk.wang`,API 走 https(443),git 走 ssh(1234)——从 origin 远程自动解析;
|
||||
python urllib 连该实例会在部分请求上报 `SSL: UNEXPECTED_EOF`,**实际发布需加 `--insecure`**;
|
||||
- 本实例 Gitea 的 API 兼容性怪癖:`GET /releases/tags/{tag}` 返回的 `assets` 是纯数组,
|
||||
而 `GET /releases/{id}` 是 `{items:[...]}` —— publish_gitea.py 已按两种形状兼容,勿"简化"回去。
|
||||
|
||||
## 6. 已知坑(历史踩过,勿重蹈)
|
||||
|
||||
- onefile 运行时 `__file__` 指向临时解压目录 `_MEIPASS`,定位 exe 必须用 `sys.executable`(§3.3);
|
||||
- 重新打包前旧 exe 可能被残留进程占用 → build_exe.py 会 taskkill 同名进程,手改打包脚本时保留;
|
||||
- 打包后本机图标缓存不刷新:`ie4uinit -show`,不是产物问题;
|
||||
- 改图标流程:改 svg → `make_ico.py` 生成 ico → 重新打包(ico 同时是文件图标与运行时窗口图标);
|
||||
- GUI 与 hdmi_source.ps1 各自独立实现显示器枚举,行为可能微差(GUI 与 `-List` 序号一致,
|
||||
但与"设置"面板序号无保证);多屏操作前先确认序号;
|
||||
- `pattern_slots.json` 兼容两种历史格式,写出只写新格式(详见 §3.11);
|
||||
- CustomTkinter 6.x:`CTkComboBox` 不支持 `textvariable`(用 `.set()/.get()`);`CTkTextbox`
|
||||
的 `tag_config` 在部分版本不可用,app_gui 已 try/except 兜底为单色;同一容器内
|
||||
grid/pack 不可混用(卡片用 grid 挂进列,卡片内部一律 pack——`_card` 返回 (卡片, 内容));
|
||||
|
||||
## 7. 验证清单(改完代码后)
|
||||
|
||||
1. `python -m py_compile src/*.py` —— 全模块可编译;
|
||||
2. `python selftest_rs485.py` —— 光机协议回归(改 dlpc_rs485.py 后必跑,向量来自上游 protocols.md);
|
||||
3. `python hdmi_gui.py --seconds 5` —— GUI 冒烟(自动开关);
|
||||
4. `python hdmi_gui.py --test-pattern Checker --area 800x600 --seconds 3` —— 投图链路;
|
||||
5. `python hdmi_gui.py --dump` —— EDID 解算不抛异常;
|
||||
6. `python hdmi_gui.py --dlpc-cmd M999`(不带 --port)—— 应明确报错而非崩溃(无硬件时的优雅降级);
|
||||
7. `python build_exe.py` → 双击 release/DLPilot.exe 确认图标/双栏布局/投图/光机区渲染;
|
||||
8. `python package_release.py <版本>` —— 不报"引用图片缺失"即栏位完整性 OK。
|
||||
@@ -1,17 +0,0 @@
|
||||
{
|
||||
"area": "640x360",
|
||||
"slots": [
|
||||
{
|
||||
"name": "西门子星",
|
||||
"file": "bw_star.png"
|
||||
},
|
||||
{
|
||||
"name": "BW_ZONE",
|
||||
"file": "bw_zoneplate.png"
|
||||
},
|
||||
{
|
||||
"name": "BW_TEST",
|
||||
"file": "bw_testcard.png"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
# I2C-Inject — LT8619C 寄存器择机注入工具
|
||||
|
||||
> **⏸ 状态:暂停开发(2026-09-25)。** 工具与固件保留在仓库中不作删除,当前没有继续开发的计划。
|
||||
> demo 板寄存器语义实测当时即由本工具完成;0x606E 其余位交换经确认(2026-09-25)现状正常、
|
||||
> 符合预期,无需单独实测。恢复开发前请勿视为完整可用。
|
||||
|
||||
> 更新:2026-09-03。由两部分组成:**RP2040 注入器固件**(`mcu-rp2040/`,刷入
|
||||
> BPI-Pico-RP2040,MicroPython)+ **PC 端 GUI**(`i2c_inject_gui.py` / 打包版
|
||||
> `I2C-Inject.exe`)。可在 LT8619C demo 板的 I2C 总线上安全地在线读写寄存器。
|
||||
|
||||
@@ -12,7 +12,7 @@ PORT = sys.argv[1] if len(sys.argv) > 1 else 'COM9'
|
||||
FULL = len(sys.argv) > 2 and sys.argv[2].lower() == 'full'
|
||||
|
||||
BANK, REG = '60', '6E'
|
||||
STEPS = [ # (写值, 含义, 写入后 HDMI-Tool 应投的图, LA 预期变化 vs 基线)
|
||||
STEPS = [ # (写值, 含义, 写入后 DLPilot 应投的图, LA 预期变化 vs 基线)
|
||||
('00', '关闭交换(基准)', 'solid_0000AA / solid_000055',
|
||||
'D0:AA=13%/55=84%, D1:AA=72%/55=0.9% (基线)'),
|
||||
('80', 'B通道镜像', 'solid_0000AA',
|
||||
|
||||
@@ -1,53 +1,79 @@
|
||||
# LT8619C_Debug_Tools
|
||||
# HW-Debug-Tools
|
||||
|
||||
LT8619C(HDMI→RGB888)→ DLPC3421 投影转接板调试配套上位机工具集。
|
||||
硬件调试上位机工具集,起家于 LT8619C(HDMI→RGB888)→ DLPC3421 投影转接板调试配套,
|
||||
现收纳全部调试工具;原名 `LT8619C_Debug_Tools`,2026-09-28 更名(Gitea 旧地址自动重定向)。
|
||||
上游主仓库(固件):[LT8619C_DLPC3421_HDMI](https://gitea.hulk.wang/hulk/LT8619C_DLPC3421_HDMI)。
|
||||
|
||||
## 工具一览
|
||||
|
||||
| 工具 | 用途 | 获取 |
|
||||
|---|---|---|
|
||||
| [DLPilot](DLPilot/) | HDMI 源端(EDID 查看/逐字节解析、分辨率切换、纯色与测试图案全屏投屏)+ 光机控制(RS485→GD32 网关→DLPC3421:开关光机/设光强/查温度电流) | 到 [Releases](https://gitea.hulk.wang/hulk/LT8619C_Debug_Tools/releases) 下 `DLPilot-vX.Y.Z-win64.zip`,解压即用;详见 [DLPilot/README.md](DLPilot/README.md) |
|
||||
| [I2C-Inject](I2C-Inject/) | LT8619C 寄存器在线读写:RP2040 注入器在 demo 板 I2C 总线上择机注入(避让主控轮询,写后自动读回校验) | 需配合 RP2040 固件 `rp2040_inject.py`;详见 [I2C-Inject/README.md](I2C-Inject/README.md) |
|
||||
| 图标 | 工具 | 用途 | 获取 |
|
||||
|---|---|---|---|
|
||||
| <img src="DLPilot/src/logos/logo_dlpilot.png" width="64" alt="DLPilot 图标"/> | [DLPilot](DLPilot/) | HDMI 源端(EDID 查看/逐字节解析、分辨率切换、纯色与测试图案全屏投屏)+ 光机控制(RS485→GD32 网关→DLPC3421:开关光机/设光强/查温度电流) | 到 [Releases](https://gitea.hulk.wang/hulk/HW-Debug-Tools/releases) 下 `DLPilot-vX.Y.Z-win64.zip`,解压即用;详见 [DLPilot/README.md](DLPilot/README.md) |
|
||||
| <img src="EDID-viewer/assets/edid-viewer.png" width="64" alt="EDID-Viewer 图标"/> | [EDID-viewer](EDID-viewer/) | Windows 显示器 EDID 只读查看器:活动设备或离线文件的厂家/序列号/分辨率时序、CTA/HDMI/音频/HDR 能力、校验诊断;BIN/HEX 导入,BIN/JSON 报告导出 | 到 [Releases](https://gitea.hulk.wang/hulk/HW-Debug-Tools/releases) 下 `EDID-Viewer-vX.Y.Z-win64.zip`,解压即用;详见 [EDID-viewer/README.md](EDID-viewer/README.md) |
|
||||
| <img src="SerialMate/assets/serial-mate.png" width="64" alt="SerialMate 图标"/> | [SerialMate](SerialMate/) | RS485/串口调试助手:收发 + 协议包解析(帧构成令牌序列/包头/板ID/LEN口径/CRC 全可定制,默认兼容 DLPilot 光机协议)、板型档案一键切换协议参数与命令预设、payload 字符串/HEX 显示、4 通道曲线(弹窗独立、时间窗滑笔回看、悬停读值、暂停渲染)、发送框输入 payload 自动包装组帧(`/` 分隔多条)、HEX 直发与周期发送 | 到 [Releases](https://gitea.hulk.wang/hulk/HW-Debug-Tools/releases) 下 `SerialMate-vX.Y.Z-win64.zip`,解压即用;详见 [SerialMate/README.md](SerialMate/README.md) |
|
||||
| <img src="I2C-Inject/logos/logo_i2c_orange.png" width="64" alt="I2C-Inject 图标"/> | [I2C-Inject](I2C-Inject/) | ⏸ **暂停开发**:LT8619C 寄存器在线读写(RP2040 注入器在 demo 板 I2C 总线上择机注入,避让主控轮询,写后自动读回校验)。代码与固件保留备查 | 暂不提供发布;状态与原理详见 [I2C-Inject/README.md](I2C-Inject/README.md) |
|
||||
| <img src="gd32e230f8_firmware_merge_tool/FlashTool/src/logos/logo_flash.png" width="64" alt="GD32 固件工具图标"/> | [gd32e230f8_firmware_merge_tool](gd32e230f8_firmware_merge_tool/) | 🔗 **子模块**(独立仓库独立管理):GD32E230 固件工具——APP/BL 合成补齐(`_UPDATE.bin`/`_BL.bin`)+ DAPLink Flash GUI 烧录(自带 OpenOCD 工具链) | 本仓目录即快捷入口;版本更新与发布在其[原仓库](https://gitea.hulk.wang/hulk/gd32e230f8_firmware_merge_tool)(Releases 下 zip 解压即用);详见 [README](gd32e230f8_firmware_merge_tool/README.md) |
|
||||
|
||||
## 环境要求
|
||||
|
||||
- 发布版 zip 开箱即用(Windows 10/11 x64,无需安装 Python)
|
||||
- 源码运行:Python ≥3.10;DLPilot 命令行/EDID 纯标准库,GUI 需
|
||||
`py -m pip install customtkinter`(自定义图片 JPG/BMP 可选 Pillow、光机控制可选 pyserial);
|
||||
`py -m pip install PySide6-Fluent-Widgets`(自定义图片 JPG/BMP 可选 Pillow、光机控制可选 pyserial);
|
||||
EDID-viewer GUI 需 `py -m pip install -r EDID-viewer/requirements.txt`(PySide6 + PySide6-Fluent-Widgets);
|
||||
SerialMate GUI 需 `py -m pip install PySide6 PySide6-Fluent-Widgets pyserial`;
|
||||
I2C-Inject 需 `py -m pip install pyserial`
|
||||
- 重新打包:`DLPilot/src/build_exe.py`(自动安装 PyInstaller);I2C-Inject 目录内 `python build_exe.py`
|
||||
- 重新打包:`DLPilot/src/build_exe.py`、`EDID-viewer/src/build_exe.py` 与
|
||||
`SerialMate/src/build_exe.py`(均自动安装 PyInstaller);I2C-Inject 目录内 `python build_exe.py`
|
||||
|
||||
## 目录结构
|
||||
|
||||
每个工具内统一三区:**src/ 源代码(人写)** → **assets/ 生成资产(可再生成)** →
|
||||
**release/ 打包与发布产物(机器生成)**;README.md 面向使用者,AGENTS.md 面向 AI/Agent(工程约定与构建规程)。
|
||||
**release/ 打包与发布产物(机器生成)**;README.md 面向使用者,AGENTS.md 记录工程约束与开发进度,
|
||||
仓库整体的开发需求与进度管理见根目录 `agent.md`。
|
||||
|
||||
```
|
||||
LT8619C_Debug_Tools/
|
||||
HW-Debug-Tools/
|
||||
├── DLPilot/
|
||||
│ ├── src/ # 源码 + 打包/发布脚本 + 图标源
|
||||
│ ├── assets/ # 生成的测试图案 PNG(gen_*.py 产物)
|
||||
│ ├── release/ # 打包 exe + 运行配置(入库);发布 zip(不入库)
|
||||
│ ├── README.md # 使用说明
|
||||
│ └── AGENTS.md # AI/Agent 工程档案
|
||||
│ └── AGENTS.md # 工程档案
|
||||
├── EDID-viewer/
|
||||
│ ├── src/ # 界面/解析/WMI 读取 + 打包/发布脚本
|
||||
│ ├── assets/ # 图标与生成脚本
|
||||
│ ├── release/ # EDID-Viewer.exe + README(入库);发布 zip(不入库)
|
||||
│ ├── README.md # 使用说明
|
||||
│ └── AGENTS.md # 工程档案
|
||||
├── SerialMate/
|
||||
│ ├── src/ # 协议/串口线程/曲线控件/GUI + 自检 + 打包/发布脚本
|
||||
│ ├── release/ # SerialMate.exe + README(入库);发布 zip(不入库)
|
||||
│ ├── README.md # 使用说明
|
||||
│ └── AGENTS.md # 工程档案
|
||||
├── I2C-Inject/ # PC 端 GUI + RP2040 固件 + 打包 exe + 图标 + README
|
||||
├── gd32e230f8_firmware_merge_tool/ # 🔗 git 子模块 → GD32E230 固件工具(独立仓库,见下方备注)
|
||||
├── LICENSE
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## 发布流程(DLPilot)
|
||||
## 发布流程(DLPilot / EDID-Viewer / SerialMate 同一套流水线)
|
||||
|
||||
```powershell
|
||||
cd DLPilot/src
|
||||
python build_exe.py # 打包 → ../release/DLPilot.exe
|
||||
python package_release.py <版本> # → ../release/DLPilot-v<版本>-win64.zip
|
||||
python publish_gitea.py DLPilot-v<版本>-win64.zip --insecure # 上传 Gitea Release(需 GITEA_TOKEN)
|
||||
cd DLPilot/src # 或 EDID-viewer/src、SerialMate/src
|
||||
python build_exe.py # 打包 → ../release/<工具>.exe
|
||||
python package_release.py <版本> # → ../release/<工具>-v<版本>-win64.zip
|
||||
python publish_gitea.py <工具>-v<版本>-win64.zip --insecure # 上传 Gitea Release(需 GITEA_TOKEN)
|
||||
```
|
||||
|
||||
每个工具独立打标签发布(`DLPilot-v*` / `EDID-Viewer-v*` / `SerialMate-v*`),Release 列表按时间倒序混排于同一页面。
|
||||
|
||||
## 备注
|
||||
|
||||
- 源码与打包产物(exe、pattern_slots.json)均入库;发布 zip 不入库,只上传 Gitea Release
|
||||
- `gd32e230f8_firmware_merge_tool/` 是 git 子模块([独立仓库](https://gitea.hulk.wang/hulk/gd32e230f8_firmware_merge_tool),
|
||||
代码与发布均在其仓内管理,本仓只锁定指针):
|
||||
新克隆后需 `git submodule update --init` 拉取内容;
|
||||
跟进其最新版用 `git submodule update --remote gd32e230f8_firmware_merge_tool`,随本仓提交新指针
|
||||
- 两件工具的寄存器语义(0x606E 位交换 / 0x606D 整组顺序)均经 demo 板逻辑分析仪
|
||||
双色交叉实测,过程数据与规程存于上游主仓库 `doc/architecture/`
|
||||
- 更新:2026-09-11
|
||||
- 更新:2026-09-30
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
# AGENTS.md — SerialMate 工程档案(开发约束与进度)
|
||||
|
||||
> 人类文档 [README.md](README.md) 回答"这是什么、怎么用";本文记录"代码怎么组织、
|
||||
> 怎么构建发布、改动时哪些约束不能破坏",兼作本工具的进度记录。
|
||||
> 修改本目录代码前先读完本文。仓库整体的开发需求与进度管理见根目录 `agent.md`。
|
||||
|
||||
## 1. 项目定位
|
||||
|
||||
仓库 `HW-Debug-Tools` 是 LT8619C→DLPC3421 投影转接板的调试上位机工具集。
|
||||
SerialMate 是其中的**通用串口/RS485 调试助手**:收发 + 协议解析 + 曲线。
|
||||
默认帧格式与 DLPilot 光机 RS485 协议完全一致(`D5 01 LEN <payload> CRC`),
|
||||
可直接调试板载 GD32E230 网关;帧格式(包头/板ID/CRC 算法与覆盖范围)可定制,
|
||||
适配任意"包头+板ID+LEN(=payload长度)+payload+CRC"五段式协议。
|
||||
协议语义权威同 DLPilot:上游固件仓 `protocols.md`,本仓不维护副本。
|
||||
|
||||
## 2. 目录契约
|
||||
|
||||
```
|
||||
SerialMate/
|
||||
├── src/ 源代码区 —— 只有这里可以手改
|
||||
├── release/ 产物区 —— SerialMate.exe + README.md(入库),
|
||||
│ *-win64.zip(gitignore,只上传 Release)
|
||||
├── assets/ 图标等生成资产(暂无;build_exe.py 已预留 assets/serial-mate.ico)
|
||||
├── README.md 人类文档
|
||||
└── AGENTS.md 本文
|
||||
```
|
||||
|
||||
### 文件角色速查
|
||||
|
||||
| 文件 | 角色 |
|
||||
|---|---|
|
||||
| `src/main.py` | Fluent GUI 入口(含 `--seconds N` 冒烟参数),argparse 仅此一处 |
|
||||
| `src/protocol.py` | 协议模块(纯标准库):FrameLayout 帧构成令牌、ProtoConfig 组帧/校验、FrameParser 增量解析、CRC 算法表、extract_value 数值提取 |
|
||||
| `src/link.py` | 串口工作线程 SerialLink(pyserial 只准在这里 import),支持 `loop://` 虚拟回环 |
|
||||
| `src/plot.py` | 滚动曲线控件(纯 QPainter,刻意不引 matplotlib/pyqtgraph) |
|
||||
| `src/config.py` | BASE_DIR 定位与 serial_mate.json / board_profiles.json 读写(缺键补默认,读容错) |
|
||||
| `src/theme.py` | 主题三件套同步(Fluent setTheme + QPalette/QSS + DWM 标题栏),与 EDID-Viewer 同源 |
|
||||
| `src/selftest.py` | 协议自检(无依赖、无硬件,改 protocol.py 后必跑) |
|
||||
| `src/selftest_loop.py` | 链路自检(loop:// 回环验证 组帧→发送→接收→解析→提取,缺 pyserial 跳过) |
|
||||
| `src/selftest_gui.py` | GUI 功能自检(offscreen 驱动事件处理函数:预览/回显/提取/配置往返,改 main.py 后建议重跑) |
|
||||
| `src/build_exe.py` | PyInstaller onefile 打包 → `release/SerialMate.exe` |
|
||||
| `src/package_release.py` | exe+README → `release/SerialMate-v<版本>-win64.zip` |
|
||||
| `src/publish_gitea.py` | 建/复用 Gitea Release 并上传 zip(`GITEA_TOKEN`,需 `--insecure`) |
|
||||
|
||||
## 3. 代码不变量(改代码必须维持)
|
||||
|
||||
1. **依赖分层**:protocol.py / config.py 纯标准库;pyserial 只准在 link.py
|
||||
import(main.py 经 `SerialLink` 间接使用);plot.py 只依赖 PySide6;
|
||||
GUI 硬依赖 PySide6-Fluent-Widgets + pyserial(串口工具缺 pyserial 即无意义,
|
||||
与 DLPilot 的"缺失降级"策略不同,只保留 try-import 提示)。
|
||||
1a. **卡片布局约定**:`_card(side=True)` 把短副标题放标题右侧省一行(串口/
|
||||
协议/发送卡);右列是纵向 QSplitter(接收/发送高度用户可拖拽,拉伸余量
|
||||
默认给接收、发送卡保持自然高度防空腔);发送卡末尾 `lay.addStretch(1)`
|
||||
保证内容贴顶(卡片被拖高后富余高度收在卡底,勿删——否则拉伸被各行均分,
|
||||
标题上方出现空隙);发送卡行序:板型管理行(下拉+新建+删除+配置+重载) /
|
||||
预设行(下拉+填入+直接发送) / 模式行(下拉+存为板型+存入预设) / 输入行 /
|
||||
周期行;帧日志 payload 高亮走 `_append_rx_frame`(html.escape 后拼 span
|
||||
背景,toPlainText 内容不变,selftest 的日志断言因此不受影响);预设下拉
|
||||
显示"名称 · 命令",存入命令走 `_add_command_named`(弹窗核 `_add_command`
|
||||
包装,测试用核函数),预设直发走 `_send_preset_direct`(经输入框复用
|
||||
组帧/历史链路)。
|
||||
1b. **窗口最小高度**:首帧布局后 `_apply_minimum_size` 按内容实际最小高度
|
||||
抬高窗口下限(高度拉过矮时布局约束无法满足,曲线卡绘图区会被压塌并与
|
||||
通道行互相叠压——用户实测);勿删, 调整曲线卡行数/高度后该值自动跟随。
|
||||
2. **回调线程边界**:SerialLink 的 on_status/on_frame/on_raw/on_tx 全在后台线程
|
||||
触发,一律 `events.put(...)` 投递,主线程 30ms QTimer 轮询 `_drain_events`
|
||||
分发(与 DLPilot `_poll_dlpc` 同模式),禁止回调里直接碰 GUI。
|
||||
3. **半双工节奏**:link 工作线程每个循环周期最多出队写一帧(20ms 间隔),
|
||||
RS485 总线多帧连发留应答间隙,勿改成批量 drain 一次写。
|
||||
4. **帧构成语义**:帧由 `FrameLayout` 令牌序列定义(`HDR ID LEN PAYLOAD CRC`
|
||||
令牌 + 十六进制字面量,收发共用布局、仅包头值分方向);约束:LEN/PAYLOAD/CRC
|
||||
恰好各一次、CRC 必须最后、LEN 前至少一个 HDR 或字面量(同步定界)、ID 最多一次。
|
||||
LEN 口径(`LEN_SEMS`):payload 长度 / 到帧尾(payload+CRC) / 整帧;
|
||||
CRC 算法/覆盖范围见 protocol.CRC_ALGOS/CRC_SCOPES,覆盖按**帧内位置**定义
|
||||
(with_header=第1字节起 / no_header=跳过第1字节 / payload_only=仅载荷),
|
||||
任意布局通用;2 字节 CRC 线上字节序 MODBUS 低前、其余高前,按算法约定单序
|
||||
校验(改动需同步 selftest 向量)。
|
||||
5. **解析重同步策略**:前缀令牌逐位对齐(HDR/字面量须匹配、ID 通配),LEN 值经
|
||||
口径换算为 payload 长度,负值视为伪帧头逐出;CRC 失配丢 1 字节重同步——
|
||||
通用工具不预设合法 LEN 区间(与 DLPilot 的 LEN 范围预判不同)。
|
||||
6. **ID 位不校验只透出**:`Frame.code` 原样上抛(布局无 ID 时为 None,GUI 日志
|
||||
与 selftest 均需兼容 None),TYPE_NAMES 仅用于显示译码(DLPilot 语义)。
|
||||
7. **BASE_DIR 语义**(config.py):frozen 时 =exe 所在目录,源码运行时 =src/;
|
||||
设置平铺存 `serial_mate.json`,不建子目录。`tx.periodic` 不随配置
|
||||
自动启动(防误连发),其余配置启动恢复。
|
||||
8. **曲线数据流**:每帧对每个启用通道调 `extract_value`(失败静默跳过),
|
||||
`PlotWidget.add` 内部 deque(maxlen=3000) 滚动丢弃;数值格式统一
|
||||
`fmt_val`(4 位有效数字)。
|
||||
9. **主题**:theme.py 三件套同步(见 EDID-Viewer 教训:只 setTheme 会黑块);
|
||||
plot 曲线颜色固定 4 色,文字/网格色取自 QPalette 自动跟随明暗。
|
||||
9a. **曲线时间窗**:PlotWidget 持有 `_span`(窗宽秒, None=跟随全部) 与
|
||||
`_offset`(右端距最新秒数, 0=实时);横轴域换算在 `visible_domain`(纯计算,
|
||||
selftest 有断言)。**窗口不向数据收敛**(用户实测反馈):选 5min 而数据只有
|
||||
23s 时显示完整 5min 轴、曲线贴右端随采集填满(示波器式),右下角标注
|
||||
"已采集 Xs / 窗口 Ns";滞后超出全部历史 = 空窗保宽。弹窗内 时间窗下拉+
|
||||
滑条 只改这两个状态;滑条 0..1000 线性映射 (1000-v)/1000×maxpan,实时
|
||||
跟随=拉到最右(1000);poll 定时器 `_sync_time_slider` 回写位置(用户拖动中
|
||||
跳过);嵌回卡片时强制重置为跟随全部(卡内无滑条, 防困在滞后窗里)。纵轴
|
||||
数值刻度画在每条横向参考线上。
|
||||
悬停读值:mouseTracking 开启, mouseMove 只记录 `_hover_pos` 并请求重绘;
|
||||
读值内容由 paintEvent **每帧**经 `_hover_lines_at(_hover_pos)` 重算(光标
|
||||
时间 T 经 `_plot_geometry` 换算, `_nearest` 二分取 ±10px 容差内最近采样),
|
||||
画在顶部居中反色小框(`_hover_box`)——鼠标停住不动时数值也随实时数据持续
|
||||
刷新(勿改回 mouseMove 里一次性算好/或 QToolTip, 那样不动鼠标就不更新——
|
||||
用户实测反馈)。`_nearest`/`_hover_lines_at` 有单测。绘图区内边距统一用
|
||||
`M_LEFT/TOP/RIGHT/BOTTOM` 类常量(绘制与鼠标换算共用, 勿在 paint 里另写)。
|
||||
9b. **暂停(两级语义)**:主界面"暂停"= `_paused`, add() 丢弃暂停期间的数据;
|
||||
弹窗"暂停渲染"= `_frozen`, 数据照常入库但跳过重绘——冻结是**绝对状态**:
|
||||
PlotWidget 覆写 `update()` 直接吞掉一切重绘请求(任何代码路径都无法在
|
||||
冻结期打破), 只有 `set_frozen(False)` 恢复并一次性渲染积累;冻结时画面
|
||||
中央显示"已冻结渲染(采集继续)"角标让状态可见。两者互不干扰, 均有
|
||||
selftest 断言。
|
||||
9c. **弹窗曲线交互**:自动Y(勾选按钮, 与主界面 chk_auto_y 双向同步, 关闭时
|
||||
以 `auto_yrange()` 初始化手动量程);图上左键拖动 = 平移手动 Y 量程
|
||||
(`on_yrange_changed` 回调同步主界面 Ymin/Ymax 输入框, 阻断信号防回环);
|
||||
滚轮 = 缩放时间窗 2~900s(滞后按比例缩放, 经 `on_span_changed` 回调让
|
||||
`_sync_time_slider` 把时间窗下拉同步为匹配档位/自定义(-1));"实时"按钮
|
||||
= offset 归零跳回最新。自动 Y 量程抽取为 `auto_yrange()`(纯计算, 有单测)。
|
||||
11a. **曲线弹出窗口**:绘图区在曲线卡留有固定槽位布局 `_plot_slot`,弹出 =
|
||||
`setParent(None)` 后装入顶层窗口(通道/暂停/Y 轴控件留在主界面控制同一
|
||||
PlotWidget 实例);关掉弹出窗口(eventFilter 捕 Close)或主窗 closeEvent
|
||||
都会走 `_dock_plot()` 嵌回 —— `_dock_plot` 必须先摘 `self._plot_win` 引用
|
||||
再 `win.close()`(防 Close 递归),且 `setParent(None)` 后必须补 `show()`
|
||||
(重挂布局不会自动恢复可见)。
|
||||
10. **多实例**:有意不加单实例锁(双口双开的合法场景),串口冲突靠
|
||||
pyserial 报错提示("串口被占用"文案在 link.py,勿删)。
|
||||
11. **板型档案**:`board_profiles.json`(BASE_DIR 平铺,用户本机数据不入库,
|
||||
首次运行自动生成默认"DLPilot光机")。档案 = name + proto(7 个帧协议字段,
|
||||
**不含 parse** —— 解析开关是查看偏好) + commands[[名,命令]..];切换板型
|
||||
应用协议参数并装载命令表,"存入"命令以命令文本为名去重;启动恢复选中
|
||||
板型时**只装载命令表不重复应用协议参数**(协议以上次会话 store 为准);
|
||||
GUI 增删后经 config.save_profiles 落盘,"配置/重载"支持手改 JSON。
|
||||
|
||||
## 4. 构建与发布(全部在 src/ 下执行)
|
||||
|
||||
```powershell
|
||||
python -m compileall -q . # 全模块可编译
|
||||
python selftest.py # 协议回归(47 项, 改 protocol.py 后必跑)
|
||||
python selftest_loop.py # 链路回环(需 pyserial, 改 link.py 后必跑)
|
||||
python selftest_gui.py # GUI 功能回归(offscreen, 改 main.py 后建议重跑)
|
||||
python main.py --seconds 5 # GUI 冒烟(源码); offscreen: set QT_QPA_PLATFORM=offscreen
|
||||
python build_exe.py # → ../release/SerialMate.exe(缺 PyInstaller 自动装)
|
||||
python package_release.py <版本> # → ../release/SerialMate-v<版本>-win64.zip
|
||||
python publish_gitea.py ../release/SerialMate-v<版本>-win64.zip --replace --insecure
|
||||
```
|
||||
|
||||
发布约定与 Gitea 实例怪癖(TLS 抽风加 `--insecure`、assets 两种形状兼容、
|
||||
token 读 `GITEA_TOKEN` 用户级环境变量)同 DLPilot,详见 `DLPilot/AGENTS.md` §5;
|
||||
tag/release 命名 `SerialMate-vX.Y.Z`,zip 命名
|
||||
`SerialMate-vX.Y.Z-win64.zip`(publish_gitea.py 从文件名推 tag)。
|
||||
|
||||
## 5. 已知坑(本工具踩过/继承的)
|
||||
|
||||
- `qfluentwidgets.CaptionLabel` 无 `setDim` 方法(本机版本),灰字用
|
||||
`CaptionLabel` 本身即可;`ComboBox` 不要用 `currentData`(qfluentwidgets
|
||||
自绘下拉 userData 支持不稳),一律 currentIndex + 平行元组映射。
|
||||
- **qfluentwidgets 控件默认水平 Expanding**:紧凑行不设 stretch 项时空白会被
|
||||
CheckBox/Label 等瓜分出大空隙 —— 一律走 `Window._row()`(行尾默认补
|
||||
stretch;Qt 规则:有 stretch 因子时额外空间只按因子分配),需要自管拉伸的
|
||||
行传 `trailing=False`。
|
||||
- **qfluentwidgets SpinBox/DoubleSpinBox 设固定宽后内部行编辑器会塌缩**
|
||||
(minimumSizeHint 142/193 只是参考,强设小于它的宽度时行编辑器只剩几像素,
|
||||
数值被裁成残字——整数 0 在 96px 时渲染成 "]"):整数 SpinBox ≥110px、
|
||||
DoubleSpinBox ≥130px 才能完整显示数值;曲线卡偏移/序号/倍率/Y 量程框的
|
||||
宽度有 selftest 断言把守, 调布局时勿低于阈值。
|
||||
- 组帧/解析回路自测时必须让 `tx_hdr == rx_hdr`(收发方向包头本就允许不同,
|
||||
D5 组的帧 B5 解析器看不见——selftest 的 fuzz/回路用例已按此约定)。
|
||||
- offscreen 冒烟报 `QFontDatabase: Cannot find font directory` 属 Qt offscreen
|
||||
平台噪音,桌面运行无此问题,勿当 bug 修。
|
||||
- onefile 运行时定位 exe 用 `sys.executable`(`__file__` 在 `_MEIPASS`),
|
||||
config.py 已按此实现。
|
||||
|
||||
## 6. 验证清单(改完代码后)
|
||||
|
||||
1. `python -m compileall -q .` —— 全模块可编译;
|
||||
2. `python selftest.py` —— 协议回归(改 protocol.py 后必跑);
|
||||
3. `python selftest_loop.py` —— 链路回环(改 link.py 后必跑);
|
||||
4. `python main.py --seconds 5` —— GUI 冒烟自动开关;
|
||||
5. `python build_exe.py` → 双击 release/SerialMate.exe 确认界面渲染;
|
||||
6. (有硬件时)USB-RS485 接光机发 M1/M201/M731 验证真机收发与曲线。
|
||||
|
||||
## 7. 进度记录
|
||||
|
||||
### v0.1.0(2026-09-27,首版)
|
||||
|
||||
已完成:
|
||||
- 协议模块:**帧构成令牌序列可定制**(`HDR ID LEN PAYLOAD CRC` 令牌 + 十六进制
|
||||
字面量同步字节,收发共用布局,支持字段换序/无板ID/多字节同步头;LEN 口径三种:
|
||||
payload 长度 / 到帧尾 / 整帧)、5 种 CRC 算法 × 3 种覆盖范围(按帧内位置定义,
|
||||
任意布局通用)、增量解析(前缀逐位对齐 + CRC 失败逐字节重同步)、
|
||||
二进制/文本/正则三种曲线数值提取;自测 64 项全 PASS(含 DLPilot 实测帧向量、
|
||||
CRC 标准校验值 check("123456789")、布局换序/字面量/LEN 口径向量与布局模糊往返)。
|
||||
- 串口链路:参数热切换、发送队列(半双工友好 + 未连接丢弃)、解析/透传双模式
|
||||
热切、`loop://` 虚拟回环自检 13 项全 PASS(组帧→发送→接收→解析→曲线提取)。
|
||||
- GUI(PySide6-Fluent-Widgets):串口/协议/曲线/接收/发送五卡,帧构成与 LEN 口径
|
||||
可视化编辑(非法输入即时提示),payload 字符串/HEX 切换(帧日志的 payload
|
||||
段垫半透明底色高亮——主题无关 rgba, 明暗切换不残留, 经 appendHtml 实现)、
|
||||
原始帧 hex、时间戳、日志保存;发送:自动包装(`/` 分隔多条)、HEX 直发、
|
||||
周期发送、组帧实时预览、历史回溯(↑↓)、回车发送;主题跟随系统。
|
||||
- 曲线(plot.py + 弹窗,2026-09-27 实机反馈多轮迭代):4 通道三种提取方式 +
|
||||
倍率,自动/手动 Y 量程;绘图区可**弹出独立窗口**(嵌回自动重置视图);
|
||||
纵轴每条参考线标数值刻度;时间窗(跟随/10s~15min, 示波器式不向数据收敛,
|
||||
右下角"已采集/窗口"标注)+ 横向滑条回看历史;悬停读值框固定顶部、鼠标
|
||||
不动也随数据持续刷新;**暂停渲染**(冻结显示继续收数, 与主界面"暂停"
|
||||
两级语义, 冻结有中央角标);自动Y 开关、图上拖动自定义 Y 轴(同步主界面
|
||||
输入框)、滚轮缩放时间窗(2~900s)、实时按钮;窗口最小高度按内容自适应
|
||||
(防高度拉小时通道行叠压绘图区)。
|
||||
- 板型档案:发送卡"板型"下拉一键切换协议参数 + 命令预设;**新建板型**(协议
|
||||
沿用当前、命令预设空白,防遗留其他板子的命令)/存为板型(同名覆盖)/
|
||||
**删除板型**(确认弹窗,至少保留一个,删除后切第一个板型且协议参数不动)/
|
||||
存入预设命令(弹窗自定义显示名称)/配置=内嵌表格编辑器(**CommandTable**:
|
||||
第 0 列 ≡ 手柄按住上下拖动整行排序——内部 QDrag,move_row 整行搬移;
|
||||
网格线/隔行底色按 palette 明暗自适配,空行清晰可见;+加行 −删行;空命令与
|
||||
重复命令保存时忽略/去重,写回 board_profiles.json)/重载;预设下拉
|
||||
"名称 · 命令"同显。
|
||||
- 发布流水线:build_exe/package_release/publish_gitea 与全仓一致;exe 已重建
|
||||
入库,zip/Release 未发布(待用户验收)。
|
||||
|
||||
待办 / 计划:
|
||||
- 【无图标】assets/serial-mate.ico 未生成(build_exe.py 已预留路径,
|
||||
参照 DLPilot logos/make_ico.py 流程补)。
|
||||
- 【真机已过】用户已实机联调(COM15 真机收发/曲线提取/多板型档案实际使用,
|
||||
2026-09-27 多轮界面反馈即来自真机数据);温度曲线量纲(倍率取值)待用户
|
||||
按传感器手册确认。
|
||||
- 【计划】发送区多条 payload 的"批处理脚本"化(延时/循环/条件等待应答)。
|
||||
- 【计划】曲线数据导出 CSV;接收日志按日期自动分文件。
|
||||
- 【考虑】CRC 解析侧双字节序兼容开关(当前按算法约定单序)。
|
||||
@@ -0,0 +1,130 @@
|
||||
# SerialMate — RS485/串口调试助手
|
||||
|
||||
> LT8619C 调试工具集配套工具:串口收发 + 协议包解析 + 曲线绘制。
|
||||
> 帧格式(包头/板ID/LEN/CRC)全可定制,默认与 [DLPilot](../DLPilot) 光机
|
||||
> RS485 协议一致,可用来直接调试板载 GD32E230 网关或任意同构协议设备。
|
||||
|
||||
## 功能
|
||||
|
||||
- **串口收发**:端口自动枚举、波特率 1200~921600、数据位/校验/停止位可选,
|
||||
参数热切换;半双工 RS485 友好(每周期最多写一帧,留应答间隙)。
|
||||
- **协议解析**(可关,关=原始透传):
|
||||
增量字节流定界 + CRC 校验,失败逐字节重同步,噪声自动丢弃;
|
||||
接收帧 ID 位按 DLPilot 语义译码显示(0xF0=成功、0xFD=参数越界…)。
|
||||
- **帧构成定制**(协议卡,发送/接收共用同一布局,仅包头值分方向):
|
||||
帧构成用**令牌序列**定义,默认 `HDR ID LEN PAYLOAD CRC`(即 DLPilot 五段式):
|
||||
|
||||
| 令牌 | 含义 |
|
||||
|---|---|
|
||||
| `HDR` | 包头(值取 TX包头 / RX包头 字段) |
|
||||
| `ID` | 板ID(RX 侧多为响应 TYPE 码,不校验仅透出显示) |
|
||||
| `LEN` | 长度字节,口径可选:**payload 长度(默认)** / 到帧尾(payload+CRC) / 整帧 |
|
||||
| `PAYLOAD` | 协议载荷(发送框内容,别名 DATA) |
|
||||
| `CRC` | 校验(算法/覆盖范围见下表,必须在末尾) |
|
||||
| 十六进制字面量 | 固定字节,如 `AA 55` 双字节同步头 |
|
||||
|
||||
示例:`AA 55 LEN PAYLOAD CRC`(AA55 同步头、无板ID)·
|
||||
`HDR LEN PAYLOAD ID CRC`(板ID 在载荷后)· `HDR LEN ID PAYLOAD CRC`(板ID 在长度后)。
|
||||
约束:LEN/PAYLOAD/CRC 恰好各一次,LEN 前至少一个 HDR 或字面量作同步头。
|
||||
|
||||
| 项 | 说明 | 默认 |
|
||||
|---|---|---|
|
||||
| TX 包头 | HDR 令牌在命令帧的值 | `D5` |
|
||||
| RX 包头 | HDR 令牌在响应帧的值 | `B5` |
|
||||
| 板ID | ID 令牌的值(TX 用;RX 侧仅透出) | `01` |
|
||||
| LEN 口径 | payload 长度 / 到帧尾(payload+CRC) / 整帧 | payload 长度 |
|
||||
| CRC 算法 | SUM8 累加和 / CRC8 / CRC16 MODBUS / CRC16 XMODEM / CRC16 CCITT-FALSE | SUM8 |
|
||||
| CRC 覆盖 | 含包头(整帧) / 不含包头(跳过第1字节) / 仅 payload | 不含包头 |
|
||||
- **接收显示**:payload 一键切换 **字符串 / HEX**;可选附原始帧 hex;
|
||||
时间戳;日志保存为 txt。
|
||||
- **曲线**:4 通道,每帧有效数据按通道提取一个数值,支持三种提取方式
|
||||
(二进制定长 u8~f32 大小端 / 文本第 N 个数字 / 自定义正则)+ 倍率,
|
||||
y 轴自动或手动量程,暂停/清空;绘图区可**弹成独立窗口**("弹出"按钮,
|
||||
关掉窗口即嵌回),通道配置与暂停等控件留在主界面照常控制。弹出窗口内:
|
||||
纵轴每条参考线标注数值刻度;**时间窗**可选宽度(跟随/10s/30s/1min/5min/
|
||||
15min),配合横向滑条回看历史总体趋势或缩小窗口细看局部走势,拉到最右
|
||||
恢复实时跟随(冻结查看请配合"暂停");窗口宽度不向数据收敛——数据不足时
|
||||
显示完整的所选时间轴、曲线贴右端随采集逐渐填满(示波器式),右下角标注
|
||||
"已采集 Xs / 窗口 Ns";**鼠标悬停**在曲线上,绘图区顶部的小读数框持续显示
|
||||
光标处时间点 T 与各通道在该时刻的 Y 轴数值(±10px 容差取最近采样);
|
||||
弹出窗口工具栏:**暂停渲染**(只冻结画面方便查看,采集继续入库,点"继续
|
||||
渲染"后把积累的数据一次性画出来;画面中央会显示"已冻结渲染"角标;注意
|
||||
与主界面"暂停"的区别:那个会丢弃暂停期间的数据)、**自动Y**(开/关自动
|
||||
纵轴,关闭后可在图上按住左键上下拖动自定义 Y 轴范围)、**实时**(取消
|
||||
滞后跳回最新)、**滚轮**在图上缩放时间窗(2s~15min)。
|
||||
实例:回包 payload `01 AE 75 6D`(前 2 字节固定、第 3~4 字节是 16 位大端
|
||||
采样值 0x7444~0x7696)→ 勾选通道1,方式=二进制,偏移=2,格式=u16 大端,
|
||||
倍率按传感器量纲填(如 0.01);最新值显示在通道行尾并进入曲线。
|
||||
注意偏移是 payload 内的字节序号(0=第 1 字节),选错位宽/偏移会把多个字段
|
||||
拼成一个数(如 u32@偏移0 会把整包读成 28,210,029);数值显示为千分位普通
|
||||
小数,≥10 亿才用科学计数。
|
||||
- **板型档案**:不同板子的"协议参数 + 命令预设表"存为命名档案,保存在 exe
|
||||
同目录的 `board_profiles.json`。发送卡选中板型即一键套用其协议参数
|
||||
(包头/板ID/帧构成/LEN口径/CRC)并切换命令预设;**新建板型**按当前协议参数
|
||||
建档、命令预设从空白开始;**存为板型**把当前配置存成档案(同名覆盖);
|
||||
**删除板型**带确认(至少保留一个);"存入预设"把当前输入的命令加入当前
|
||||
板型(可自定义显示名称);**配置**打开表格编辑器(名称/命令两列,+加行
|
||||
−删行,保存写回档案);预设下拉以"名称 · 命令"同显。
|
||||
- **发送**:
|
||||
- **自动包装**:输入协议载荷(如 `M731S0T1000`)自动组帧加包头/板ID/LEN/CRC;
|
||||
多条用 `/` 分隔依次发送(如 `M1/M731S0T1000`);
|
||||
- **HEX 直发**:输入完整帧 hex 原样发出;
|
||||
- 周期发送(100ms~60s)、输入框实时组帧预览、预设命令一键填入、
|
||||
命令历史 ↑↓ 回溯、回车即发送。
|
||||
|
||||
## 运行
|
||||
|
||||
- 直接运行 `release/SerialMate.exe`(免安装,Windows 10/11 x64);
|
||||
- 或源码运行:`py -3 -m pip install PySide6 PySide6-Fluent-Widgets pyserial`,
|
||||
然后 `cd src && python main.py`。
|
||||
|
||||
## 界面速览
|
||||
|
||||
```
|
||||
┌ SerialMate ─────────────────────────────────────────────────┐
|
||||
│ 串口卡 协议卡 │ 接收卡(payload 字符串/HEX) │
|
||||
│ COMx 115200 8N1 D5/B5/01 │ ← 12:00:00 B=0xF0 成功 LEN=2 ok │
|
||||
│ 曲线卡(4通道) │ ┌───────── 滚动曲线 ─────────┐ │
|
||||
│ ☑ DMD温度 文本数字 第1个 ×0.1 │ └────────────────────────────┘ │
|
||||
│ │ 发送卡: [M1/M731S0T1000] 发送 │
|
||||
└────────────────────────────────┴──────────────────────────────────┘
|
||||
```
|
||||
|
||||
## 典型用法:调光机 RS485
|
||||
|
||||
1. 串口卡选 USB-RS485 适配器,115200 8N1,连接;
|
||||
2. 发送框输入 `M1` 回车——自动包装为 `D5 01 02 4D 31 81` 发出,
|
||||
接收区回 `ok`(协议卡默认即 DLPilot 协议);
|
||||
3. 查温度:发 `M201`,回包 `okTL:246` 译码显示"成功",曲线卡勾选通道
|
||||
设为"文本数字·第1个·×0.1",周期发送勾上,即可看温度曲线;
|
||||
4. 换任何自定义协议:改协议卡的**帧构成**(字段顺序/有无板ID/字面量同步头)、
|
||||
包头/板ID/LEN 口径/CRC 即可,收发解析同步生效;调好后点"存为板型",
|
||||
以后一键切换。
|
||||
|
||||
## 目录
|
||||
|
||||
```
|
||||
SerialMate/
|
||||
├── src/ 源代码(protocol 协议 / link 串口线程 / main GUI / selftest 自检)
|
||||
├── assets/ serial-mate.ico 图标(assets/make_icon.py 生成)
|
||||
├── release/ SerialMate.exe + README(发布文件夹,zip 只上传 Release)
|
||||
└── README.md 本文
|
||||
```
|
||||
|
||||
运行时用户数据与 exe 同目录平铺:`serial_mate.json`(串口/协议/通道记忆)、
|
||||
`board_profiles.json`(板型档案,首次运行自动生成默认"DLPilot光机")。
|
||||
|
||||
## 开发 / 发布
|
||||
|
||||
```powershell
|
||||
cd src
|
||||
python selftest.py # 协议回归(无依赖, 改 protocol.py 后必跑)
|
||||
python selftest_loop.py # 链路回环自检(loop:// 虚拟口, 需 pyserial)
|
||||
python main.py # 源码运行
|
||||
python build_exe.py # → ../release/SerialMate.exe
|
||||
python package_release.py <版本> # → release/SerialMate-v<版本>-win64.zip
|
||||
python publish_gitea.py ../release/SerialMate-v<版本>-win64.zip --replace --insecure
|
||||
```
|
||||
|
||||
工程约束与进度见 [AGENTS.md](AGENTS.md);协议语义唯一权威是上游固件仓
|
||||
`protocols.md`(本仓 DLPilot 目录有引用说明)。
|
||||
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
SerialMate 图标栅格化(家族风格, 与 DLPilot/EDID-Viewer/FlashTool 同版式):
|
||||
黑底 512, 绿色圆角矩形, 第一行 Serial(框内黑字), 第二行 Mate(白字)
|
||||
================================================================
|
||||
设计参数: 黑底 512, 绿色圆角矩形 x38 y64 w436 h186 rx34 (#00C878, 与
|
||||
gd32e230f8_firmware_merge_tool 的 FlashTool 同色系), Arial Bold。
|
||||
Serial 6 字母按框宽自适应字号(上限 146px, 留边距),
|
||||
Mate 146px 白字(基线对齐同 DLPilot 的 Pilot)。
|
||||
|
||||
用法: python make_icon.py # 生成 serial-mate.png / serial-mate.ico
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
BASE = os.path.dirname(os.path.abspath(__file__))
|
||||
FONT = r'C:\Windows\Fonts\arialbd.ttf' # Arial Bold, Windows 标配
|
||||
|
||||
|
||||
def fit_font(draw, text, max_w, start):
|
||||
"""从 start 字号往下找能装入 max_w 宽的字号(步进 2)"""
|
||||
size = start
|
||||
while size > 8:
|
||||
f = ImageFont.truetype(FONT, size)
|
||||
box = draw.textbbox((0, 0), text, font=f)
|
||||
if box[2] - box[0] <= max_w:
|
||||
return f
|
||||
size -= 2
|
||||
return ImageFont.truetype(FONT, 8)
|
||||
|
||||
|
||||
def render(size=512):
|
||||
s = size / 512.0
|
||||
img = Image.new('RGB', (size, size), (0, 0, 0))
|
||||
d = ImageDraw.Draw(img)
|
||||
d.rounded_rectangle([38 * s, 64 * s, (38 + 436) * s, (64 + 186) * s],
|
||||
radius=34 * s, fill=(0, 200, 120))
|
||||
if not os.path.exists(FONT):
|
||||
raise SystemExit(f'未找到字体 {FONT}, 无法栅格化')
|
||||
# Serial: 黑字居中于橙色框, 按框宽自适应(留 2×18px 边距)
|
||||
f1 = fit_font(d, 'Serial', 400 * s, round(146 * s))
|
||||
d.text((size / 2, 64 * s + 186 * s / 2), 'Serial', font=f1,
|
||||
fill=(0, 0, 0), anchor='mm')
|
||||
# Mate: 白字, 与家族一致 146px(无下伸字母, 中心 = 基线421 - cap/2 ~= 368)
|
||||
f2 = ImageFont.truetype(FONT, max(8, round(146 * s)))
|
||||
d.text((size / 2, 368 * s), 'Mate', font=f2, fill=(255, 255, 255),
|
||||
anchor='mm')
|
||||
return img
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
img = render(512)
|
||||
png = os.path.join(BASE, 'serial-mate.png')
|
||||
ico = os.path.join(BASE, 'serial-mate.ico')
|
||||
img.save(png)
|
||||
img.save(ico, sizes=[(16, 16), (24, 24), (32, 32), (48, 48),
|
||||
(64, 64), (128, 128), (256, 256)])
|
||||
print(f'写出 {png}')
|
||||
print(f'写出 {ico}')
|
||||
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 16 KiB |
@@ -0,0 +1,130 @@
|
||||
# SerialMate — RS485/串口调试助手
|
||||
|
||||
> LT8619C 调试工具集配套工具:串口收发 + 协议包解析 + 曲线绘制。
|
||||
> 帧格式(包头/板ID/LEN/CRC)全可定制,默认与 [DLPilot](../DLPilot) 光机
|
||||
> RS485 协议一致,可用来直接调试板载 GD32E230 网关或任意同构协议设备。
|
||||
|
||||
## 功能
|
||||
|
||||
- **串口收发**:端口自动枚举、波特率 1200~921600、数据位/校验/停止位可选,
|
||||
参数热切换;半双工 RS485 友好(每周期最多写一帧,留应答间隙)。
|
||||
- **协议解析**(可关,关=原始透传):
|
||||
增量字节流定界 + CRC 校验,失败逐字节重同步,噪声自动丢弃;
|
||||
接收帧 ID 位按 DLPilot 语义译码显示(0xF0=成功、0xFD=参数越界…)。
|
||||
- **帧构成定制**(协议卡,发送/接收共用同一布局,仅包头值分方向):
|
||||
帧构成用**令牌序列**定义,默认 `HDR ID LEN PAYLOAD CRC`(即 DLPilot 五段式):
|
||||
|
||||
| 令牌 | 含义 |
|
||||
|---|---|
|
||||
| `HDR` | 包头(值取 TX包头 / RX包头 字段) |
|
||||
| `ID` | 板ID(RX 侧多为响应 TYPE 码,不校验仅透出显示) |
|
||||
| `LEN` | 长度字节,口径可选:**payload 长度(默认)** / 到帧尾(payload+CRC) / 整帧 |
|
||||
| `PAYLOAD` | 协议载荷(发送框内容,别名 DATA) |
|
||||
| `CRC` | 校验(算法/覆盖范围见下表,必须在末尾) |
|
||||
| 十六进制字面量 | 固定字节,如 `AA 55` 双字节同步头 |
|
||||
|
||||
示例:`AA 55 LEN PAYLOAD CRC`(AA55 同步头、无板ID)·
|
||||
`HDR LEN PAYLOAD ID CRC`(板ID 在载荷后)· `HDR LEN ID PAYLOAD CRC`(板ID 在长度后)。
|
||||
约束:LEN/PAYLOAD/CRC 恰好各一次,LEN 前至少一个 HDR 或字面量作同步头。
|
||||
|
||||
| 项 | 说明 | 默认 |
|
||||
|---|---|---|
|
||||
| TX 包头 | HDR 令牌在命令帧的值 | `D5` |
|
||||
| RX 包头 | HDR 令牌在响应帧的值 | `B5` |
|
||||
| 板ID | ID 令牌的值(TX 用;RX 侧仅透出) | `01` |
|
||||
| LEN 口径 | payload 长度 / 到帧尾(payload+CRC) / 整帧 | payload 长度 |
|
||||
| CRC 算法 | SUM8 累加和 / CRC8 / CRC16 MODBUS / CRC16 XMODEM / CRC16 CCITT-FALSE | SUM8 |
|
||||
| CRC 覆盖 | 含包头(整帧) / 不含包头(跳过第1字节) / 仅 payload | 不含包头 |
|
||||
- **接收显示**:payload 一键切换 **字符串 / HEX**;可选附原始帧 hex;
|
||||
时间戳;日志保存为 txt。
|
||||
- **曲线**:4 通道,每帧有效数据按通道提取一个数值,支持三种提取方式
|
||||
(二进制定长 u8~f32 大小端 / 文本第 N 个数字 / 自定义正则)+ 倍率,
|
||||
y 轴自动或手动量程,暂停/清空;绘图区可**弹成独立窗口**("弹出"按钮,
|
||||
关掉窗口即嵌回),通道配置与暂停等控件留在主界面照常控制。弹出窗口内:
|
||||
纵轴每条参考线标注数值刻度;**时间窗**可选宽度(跟随/10s/30s/1min/5min/
|
||||
15min),配合横向滑条回看历史总体趋势或缩小窗口细看局部走势,拉到最右
|
||||
恢复实时跟随(冻结查看请配合"暂停");窗口宽度不向数据收敛——数据不足时
|
||||
显示完整的所选时间轴、曲线贴右端随采集逐渐填满(示波器式),右下角标注
|
||||
"已采集 Xs / 窗口 Ns";**鼠标悬停**在曲线上,绘图区顶部的小读数框持续显示
|
||||
光标处时间点 T 与各通道在该时刻的 Y 轴数值(±10px 容差取最近采样);
|
||||
弹出窗口工具栏:**暂停渲染**(只冻结画面方便查看,采集继续入库,点"继续
|
||||
渲染"后把积累的数据一次性画出来;画面中央会显示"已冻结渲染"角标;注意
|
||||
与主界面"暂停"的区别:那个会丢弃暂停期间的数据)、**自动Y**(开/关自动
|
||||
纵轴,关闭后可在图上按住左键上下拖动自定义 Y 轴范围)、**实时**(取消
|
||||
滞后跳回最新)、**滚轮**在图上缩放时间窗(2s~15min)。
|
||||
实例:回包 payload `01 AE 75 6D`(前 2 字节固定、第 3~4 字节是 16 位大端
|
||||
采样值 0x7444~0x7696)→ 勾选通道1,方式=二进制,偏移=2,格式=u16 大端,
|
||||
倍率按传感器量纲填(如 0.01);最新值显示在通道行尾并进入曲线。
|
||||
注意偏移是 payload 内的字节序号(0=第 1 字节),选错位宽/偏移会把多个字段
|
||||
拼成一个数(如 u32@偏移0 会把整包读成 28,210,029);数值显示为千分位普通
|
||||
小数,≥10 亿才用科学计数。
|
||||
- **板型档案**:不同板子的"协议参数 + 命令预设表"存为命名档案,保存在 exe
|
||||
同目录的 `board_profiles.json`。发送卡选中板型即一键套用其协议参数
|
||||
(包头/板ID/帧构成/LEN口径/CRC)并切换命令预设;**新建板型**按当前协议参数
|
||||
建档、命令预设从空白开始;**存为板型**把当前配置存成档案(同名覆盖);
|
||||
**删除板型**带确认(至少保留一个);"存入预设"把当前输入的命令加入当前
|
||||
板型(可自定义显示名称);**配置**打开表格编辑器(名称/命令两列,+加行
|
||||
−删行,保存写回档案);预设下拉以"名称 · 命令"同显。
|
||||
- **发送**:
|
||||
- **自动包装**:输入协议载荷(如 `M731S0T1000`)自动组帧加包头/板ID/LEN/CRC;
|
||||
多条用 `/` 分隔依次发送(如 `M1/M731S0T1000`);
|
||||
- **HEX 直发**:输入完整帧 hex 原样发出;
|
||||
- 周期发送(100ms~60s)、输入框实时组帧预览、预设命令一键填入、
|
||||
命令历史 ↑↓ 回溯、回车即发送。
|
||||
|
||||
## 运行
|
||||
|
||||
- 直接运行 `release/SerialMate.exe`(免安装,Windows 10/11 x64);
|
||||
- 或源码运行:`py -3 -m pip install PySide6 PySide6-Fluent-Widgets pyserial`,
|
||||
然后 `cd src && python main.py`。
|
||||
|
||||
## 界面速览
|
||||
|
||||
```
|
||||
┌ SerialMate ─────────────────────────────────────────────────┐
|
||||
│ 串口卡 协议卡 │ 接收卡(payload 字符串/HEX) │
|
||||
│ COMx 115200 8N1 D5/B5/01 │ ← 12:00:00 B=0xF0 成功 LEN=2 ok │
|
||||
│ 曲线卡(4通道) │ ┌───────── 滚动曲线 ─────────┐ │
|
||||
│ ☑ DMD温度 文本数字 第1个 ×0.1 │ └────────────────────────────┘ │
|
||||
│ │ 发送卡: [M1/M731S0T1000] 发送 │
|
||||
└────────────────────────────────┴──────────────────────────────────┘
|
||||
```
|
||||
|
||||
## 典型用法:调光机 RS485
|
||||
|
||||
1. 串口卡选 USB-RS485 适配器,115200 8N1,连接;
|
||||
2. 发送框输入 `M1` 回车——自动包装为 `D5 01 02 4D 31 81` 发出,
|
||||
接收区回 `ok`(协议卡默认即 DLPilot 协议);
|
||||
3. 查温度:发 `M201`,回包 `okTL:246` 译码显示"成功",曲线卡勾选通道
|
||||
设为"文本数字·第1个·×0.1",周期发送勾上,即可看温度曲线;
|
||||
4. 换任何自定义协议:改协议卡的**帧构成**(字段顺序/有无板ID/字面量同步头)、
|
||||
包头/板ID/LEN 口径/CRC 即可,收发解析同步生效;调好后点"存为板型",
|
||||
以后一键切换。
|
||||
|
||||
## 目录
|
||||
|
||||
```
|
||||
SerialMate/
|
||||
├── src/ 源代码(protocol 协议 / link 串口线程 / main GUI / selftest 自检)
|
||||
├── assets/ serial-mate.ico 图标(assets/make_icon.py 生成)
|
||||
├── release/ SerialMate.exe + README(发布文件夹,zip 只上传 Release)
|
||||
└── README.md 本文
|
||||
```
|
||||
|
||||
运行时用户数据与 exe 同目录平铺:`serial_mate.json`(串口/协议/通道记忆)、
|
||||
`board_profiles.json`(板型档案,首次运行自动生成默认"DLPilot光机")。
|
||||
|
||||
## 开发 / 发布
|
||||
|
||||
```powershell
|
||||
cd src
|
||||
python selftest.py # 协议回归(无依赖, 改 protocol.py 后必跑)
|
||||
python selftest_loop.py # 链路回环自检(loop:// 虚拟口, 需 pyserial)
|
||||
python main.py # 源码运行
|
||||
python build_exe.py # → ../release/SerialMate.exe
|
||||
python package_release.py <版本> # → release/SerialMate-v<版本>-win64.zip
|
||||
python publish_gitea.py ../release/SerialMate-v<版本>-win64.zip --replace --insecure
|
||||
```
|
||||
|
||||
工程约束与进度见 [AGENTS.md](AGENTS.md);协议语义唯一权威是上游固件仓
|
||||
`protocols.md`(本仓 DLPilot 目录有引用说明)。
|
||||
@@ -0,0 +1,108 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
把 src/main.py 打包成单文件 exe(工具名: SerialMate)
|
||||
================================================
|
||||
与 EDID-Viewer/src/build_exe.py 同一套路: onefile + --noconsole, Python 解释器、
|
||||
PySide6 和 PySide6-Fluent-Widgets 全部打进一个 exe, 目标机器无需安装依赖。
|
||||
|
||||
用法:
|
||||
python build_exe.py 自动安装 PyInstaller(如缺)并打包
|
||||
python build_exe.py --debug 额外打一个带控制台的变体
|
||||
|
||||
产物: release/SerialMate.exe
|
||||
spec 由本脚本生成到 src/build/(不入库), 调整打包逻辑直接改这里的模板。
|
||||
"""
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
# 本脚本位于 src/, 打包产物输出到工具根的 release/
|
||||
SRC = os.path.dirname(os.path.abspath(__file__))
|
||||
BASE = os.path.dirname(SRC)
|
||||
RELEASE = os.path.join(BASE, 'release')
|
||||
WORK = os.path.join(SRC, 'build')
|
||||
ICO = os.path.join(BASE, 'assets', 'serial-mate.ico')
|
||||
|
||||
SPEC_TEMPLATE = """\
|
||||
# -*- coding: utf-8 -*-
|
||||
# 由 build_exe.py 生成, 不要手改; 调整打包逻辑请改 src/build_exe.py。
|
||||
from PyInstaller.utils.hooks import collect_all
|
||||
|
||||
qfluent_datas, qfluent_binaries, qfluent_hidden = collect_all('qfluentwidgets')
|
||||
a = Analysis(
|
||||
[r'{entry}'], pathex=[r'{src}'], binaries=qfluent_binaries,
|
||||
datas=qfluent_datas + {icon_datas}, hiddenimports=qfluent_hidden,
|
||||
noarchive=False)
|
||||
# Qt 6.11 使用 Windows 非版本化 ICU 导出; PATH 上 Poppler/Conda 的版本化
|
||||
# ICU(icuuc.dll/icudt78.dll)会被 PyInstaller 误收, 令 QtCore.pyd 启动报
|
||||
# WinError 127 —— 打包时剔除, 运行时用系统自带 ICU。
|
||||
a.binaries = [b for b in a.binaries if b[0].lower() not in ('icuuc.dll', 'icudt78.dll')]
|
||||
pyz = PYZ(a.pure)
|
||||
exe = EXE(pyz, a.scripts, a.binaries, a.datas, [], name='{name}',
|
||||
debug=False, strip=False, upx=False, console={console}{icon_clause})
|
||||
"""
|
||||
|
||||
|
||||
def ensure_pyinstaller():
|
||||
try:
|
||||
import PyInstaller # noqa: F401
|
||||
return
|
||||
except ImportError:
|
||||
pass
|
||||
print('PyInstaller 未安装, 正在安装...')
|
||||
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'pyinstaller'])
|
||||
|
||||
|
||||
def remove_stale(exe_path):
|
||||
"""删除旧 exe; 若被占用(上次验证的进程还在), 先结束同名进程再重试"""
|
||||
if not os.path.exists(exe_path):
|
||||
return
|
||||
try:
|
||||
os.remove(exe_path)
|
||||
return
|
||||
except PermissionError:
|
||||
pass
|
||||
import time
|
||||
print(f'{exe_path} 被占用, 结束残留进程后重试...')
|
||||
subprocess.run(['taskkill', '/F', '/IM', os.path.basename(exe_path)],
|
||||
capture_output=True)
|
||||
time.sleep(1.0)
|
||||
os.remove(exe_path)
|
||||
|
||||
|
||||
def build(name, console):
|
||||
remove_stale(os.path.join(RELEASE, name + '.exe'))
|
||||
if os.path.exists(ICO):
|
||||
icon_datas = f"[(r'{ICO}', 'assets')]"
|
||||
icon_clause = f", icon=r'{ICO}'"
|
||||
else:
|
||||
print('警告: 未找到 assets/serial-mate.ico, 本次打包不带图标')
|
||||
icon_datas, icon_clause = '[]', ''
|
||||
spec = SPEC_TEMPLATE.format(entry=os.path.join(SRC, 'main.py'), src=SRC,
|
||||
icon_datas=icon_datas, name=name,
|
||||
console=console, icon_clause=icon_clause)
|
||||
os.makedirs(WORK, exist_ok=True)
|
||||
spec_path = os.path.join(WORK, name + '.spec')
|
||||
with open(spec_path, 'w', encoding='utf-8') as f:
|
||||
f.write(spec)
|
||||
cmd = [sys.executable, '-m', 'PyInstaller', '--noconfirm', '--clean',
|
||||
'--distpath', RELEASE, '--workpath', WORK, spec_path]
|
||||
print('\n>>', ' '.join(cmd))
|
||||
subprocess.check_call(cmd)
|
||||
out = os.path.join(RELEASE, name + '.exe')
|
||||
print(f'完成: {out} ({os.path.getsize(out) / 1024 / 1024:.1f} MB)')
|
||||
|
||||
|
||||
def main():
|
||||
build_console = '--debug' in sys.argv
|
||||
ensure_pyinstaller()
|
||||
# 常规版: 双击即用, 无黑框
|
||||
build('SerialMate', 'False')
|
||||
if build_console:
|
||||
# 调试版: 带控制台, 异常栈可见
|
||||
build('SerialMate-console', 'True')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,147 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
运行目录定位与设置持久化(BASE_DIR 语义与 DLPilot config.py 一致)
|
||||
==================================================================
|
||||
frozen(PyInstaller onefile)时 BASE_DIR=exe 所在目录(sys.executable),
|
||||
源码运行时=config.py 所在目录(即 src/)。设置写/读自 BASE_DIR 平铺的
|
||||
serial_mate.json, 不建子目录。
|
||||
|
||||
读容错: 文件缺失/损坏/缺键一律回落默认值, 并保证返回的 dict 键全齐,
|
||||
GUI 无需判空。
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
if getattr(sys, 'frozen', False):
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(sys.executable))
|
||||
else:
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
CONFIG_FILE = os.path.join(BASE_DIR, 'serial_mate.json')
|
||||
LEGACY_CONFIG = os.path.join(BASE_DIR, 'serial_assistant.json') # 更名前的配置
|
||||
PROFILES_FILE = os.path.join(BASE_DIR, 'board_profiles.json')
|
||||
|
||||
|
||||
def _migrate_legacy_config():
|
||||
"""SerialAssistant -> SerialMate 更名迁移: 旧配置搬为新名(一次性, 已存在则跳过)"""
|
||||
if os.path.exists(CONFIG_FILE) or not os.path.exists(LEGACY_CONFIG):
|
||||
return
|
||||
try:
|
||||
shutil.copy2(LEGACY_CONFIG, CONFIG_FILE)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
DEFAULTS = {
|
||||
'serial': {'port': '', 'baud': 115200, 'bytesize': 8, 'parity': 'N', 'stopbits': 1},
|
||||
'proto': {'tx_hdr': 'D5', 'rx_hdr': 'B5', 'board': '01',
|
||||
'crc_algo': 'SUM8', 'crc_scope': 'no_header', 'parse': True,
|
||||
'layout': 'HDR ID LEN PAYLOAD CRC', 'len_sem': 'payload'},
|
||||
'tx': {'mode': 'wrap', 'periodic': False, 'interval_ms': 1000, 'profile': ''},
|
||||
'rx': {'display': 'text', 'show_raw': True},
|
||||
'channels': [
|
||||
{'enabled': False, 'name': '通道1', 'mode': 'num', 'offset': 0,
|
||||
'fmt': 'u16be', 'index': 1, 'pattern': '(?<=:)\\d+', 'scale': 1.0},
|
||||
{'enabled': False, 'name': '通道2', 'mode': 'bin', 'offset': 0,
|
||||
'fmt': 's16be', 'index': 1, 'pattern': '(?<=:)\\d+', 'scale': 1.0},
|
||||
{'enabled': False, 'name': '通道3', 'mode': 'bin', 'offset': 0,
|
||||
'fmt': 'u16be', 'index': 1, 'pattern': '(?<=:)\\d+', 'scale': 1.0},
|
||||
{'enabled': False, 'name': '通道4', 'mode': 'bin', 'offset': 0,
|
||||
'fmt': 'u16be', 'index': 1, 'pattern': '(?<=:)\\d+', 'scale': 1.0},
|
||||
],
|
||||
}
|
||||
|
||||
# 板型档案的帧协议字段(不含 parse —— 解析开关是查看偏好, 不随板型走)
|
||||
_PROFILE_PROTO_KEYS = ('tx_hdr', 'rx_hdr', 'board', 'layout', 'len_sem',
|
||||
'crc_algo', 'crc_scope')
|
||||
|
||||
# 首个板型的命令预设(DLPilot 光机命令集, 全表见上游 protocols.md)
|
||||
DEFAULT_COMMANDS = (
|
||||
('握手', 'M1'), ('查版本', 'M999'),
|
||||
('开光机', 'M730S0'), ('关光机', 'M730S1'),
|
||||
('设光强', 'M731S100'), ('查电流', 'M732'),
|
||||
('查DMD温度', 'M201'), ('查LAMP温度', 'M202'),
|
||||
('TEC自动控温开', 'M7S0'), ('TEC自动控温关', 'M7S1'),
|
||||
('凝露点33.0°C', 'M8S330'), ('软件重启', 'M888'),
|
||||
)
|
||||
|
||||
|
||||
def default_profiles():
|
||||
"""首个板型档案: DLPilot 光机(协议字段取默认值)"""
|
||||
return [{'name': 'DLPilot光机',
|
||||
'proto': {k: DEFAULTS['proto'][k] for k in _PROFILE_PROTO_KEYS},
|
||||
'commands': [list(c) for c in DEFAULT_COMMANDS]}]
|
||||
|
||||
|
||||
def _merge(base, over):
|
||||
"""递归覆盖: over 缺键用 base 补齐, over 多余键保留(向前兼容旧配置)"""
|
||||
out = dict(base)
|
||||
for k, v in over.items():
|
||||
if k in base and isinstance(base[k], dict) and isinstance(v, dict):
|
||||
out[k] = _merge(base[k], v)
|
||||
else:
|
||||
out[k] = v
|
||||
return out
|
||||
|
||||
|
||||
def load():
|
||||
_migrate_legacy_config()
|
||||
"""读设置; 任何异常回落默认(键全齐), 不抛出"""
|
||||
try:
|
||||
with open(CONFIG_FILE, encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
if not isinstance(data, dict):
|
||||
raise ValueError('配置根不是对象')
|
||||
except Exception:
|
||||
return json.loads(json.dumps(DEFAULTS)) # 深拷贝默认值
|
||||
return _merge(DEFAULTS, data)
|
||||
|
||||
|
||||
def save(cfg):
|
||||
"""写设置; 失败静默(只读目录等场景不阻塞退出)"""
|
||||
try:
|
||||
with open(CONFIG_FILE, 'w', encoding='utf-8') as f:
|
||||
json.dump(cfg, f, ensure_ascii=False, indent=1)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def load_profiles():
|
||||
"""读板型档案(board_profiles.json); 缺失/损坏回落默认并落盘。
|
||||
档案结构: {'profiles': [{'name', 'proto'{7字段}, 'commands'[[名,命令]..]}..]}"""
|
||||
try:
|
||||
with open(PROFILES_FILE, encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
profiles = data.get('profiles') if isinstance(data, dict) else data
|
||||
if isinstance(profiles, list) and profiles:
|
||||
out = []
|
||||
for p in profiles:
|
||||
if not isinstance(p, dict) or not p.get('name'):
|
||||
continue
|
||||
out.append({'name': str(p['name']),
|
||||
'proto': {k: p.get('proto', {}).get(k,
|
||||
DEFAULTS['proto'][k])
|
||||
for k in _PROFILE_PROTO_KEYS},
|
||||
'commands': [[str(n), str(c)]
|
||||
for n, c in p.get('commands', [])
|
||||
if isinstance(n, str) and isinstance(c, str)]})
|
||||
if out:
|
||||
return out
|
||||
except Exception:
|
||||
pass
|
||||
profiles = default_profiles()
|
||||
save_profiles(profiles)
|
||||
return profiles
|
||||
|
||||
|
||||
def save_profiles(profiles):
|
||||
"""写板型档案; 失败静默并返回 False"""
|
||||
try:
|
||||
with open(PROFILES_FILE, 'w', encoding='utf-8') as f:
|
||||
json.dump({'profiles': profiles}, f, ensure_ascii=False, indent=1)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
@@ -0,0 +1,215 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
串口链路线程: 端口/波特率热切换 + 发送队列 + 接收分发
|
||||
======================================================
|
||||
与 DLPilot 的 DLPC485 同一套路(D I2C-Inject Injector 同源), 差异点:
|
||||
- 帧格式参数(ProtoConfig)可运行中热替换, 解析器配置随之切换并清残余半帧;
|
||||
- 支持协议解析(Frame 回调)与透传(原始 bytes 回调)两种接收模式, 运行中切换;
|
||||
- 发送一律传完整帧 bytes(组帧由 GUI 侧按 ProtoConfig 完成, 本模块不关心格式)。
|
||||
|
||||
回调全在后台线程触发, GUI 侧必须自行投递回主线程(见 main.py 的轮询队列)。
|
||||
pyserial 为本模块独占依赖(缺失只影响串口功能)。
|
||||
"""
|
||||
|
||||
import collections
|
||||
import queue
|
||||
import re
|
||||
import threading
|
||||
import time
|
||||
|
||||
try:
|
||||
import serial
|
||||
import serial.tools.list_ports
|
||||
HAS_SERIAL = True
|
||||
except ImportError:
|
||||
HAS_SERIAL = False
|
||||
|
||||
DEFAULT_BAUD = 115200
|
||||
DEFAULTS = dict(bytesize=8, parity='N', stopbits=1)
|
||||
|
||||
|
||||
class SerialLink:
|
||||
"""串口工作线程。回调(后台线程触发):
|
||||
on_status(str) 连接状态变化(已连接/断开/失败/设备拔出)
|
||||
on_frame(fr) 解析模式: 完整 Frame(protocol.Frame)
|
||||
on_raw(data) 透传模式: 原始接收 bytes
|
||||
on_tx(label, data) 发送回显: label=payload 字符串(自动包装)/None(HEX直发)
|
||||
"""
|
||||
|
||||
def __init__(self, cfg, on_status):
|
||||
self.on_status = on_status
|
||||
self.on_frame = None
|
||||
self.on_raw = None
|
||||
self.on_tx = None
|
||||
self.q = queue.Queue()
|
||||
self._cfg = cfg
|
||||
self._parse = True
|
||||
self._target = None # 意图 (port, baud, bytesize, parity, stopbits)
|
||||
self._open_key = None # 当前已打开串口的参数元组
|
||||
self.ser = None
|
||||
self.parser = None # 惰性建: 协议模块无 pyserial 依赖, 此处才用到
|
||||
self._lock = threading.Lock()
|
||||
threading.Thread(target=self._run, daemon=True).start()
|
||||
|
||||
# --- 配置与模式(线程安全) ---
|
||||
|
||||
def set_config(self, cfg):
|
||||
"""热替换帧格式; 解析器半帧缓冲随之清空, 避免新旧格式混接"""
|
||||
with self._lock:
|
||||
self._cfg = cfg
|
||||
if self.parser is not None:
|
||||
self.parser.cfg = cfg
|
||||
self.parser.clear()
|
||||
|
||||
def set_parse(self, enabled):
|
||||
"""切换 解析协议帧 / 原始透传; 切换时清解析缓冲"""
|
||||
with self._lock:
|
||||
self._parse = bool(enabled)
|
||||
if self.parser is not None:
|
||||
self.parser.clear()
|
||||
|
||||
# --- 串口管理 ---
|
||||
|
||||
@staticmethod
|
||||
def list_ports_info():
|
||||
"""枚举串口, 返回 [(设备名, 显示标签), ...]。
|
||||
|
||||
标签 = "COMx 设备描述"(描述里的 "(COMx)" 尾巴去掉), CH344 这类多路
|
||||
适配器每一路描述不同(serial-A/B/C/D), 依此区分; 多口描述完全相同时
|
||||
追加物理位置/序列号消歧。
|
||||
"""
|
||||
if not HAS_SERIAL:
|
||||
return []
|
||||
items = []
|
||||
for p in serial.tools.list_ports.comports():
|
||||
desc = re.sub(r'\s*\((COM\d+)\)\s*$', '', (p.description or '').strip(),
|
||||
flags=re.I)
|
||||
if desc.upper() == p.device.upper():
|
||||
desc = ''
|
||||
label = f'{p.device} {desc}'.rstrip()
|
||||
tail = p.location or p.serial_number or ''
|
||||
items.append((p.device, label, tail))
|
||||
counts = collections.Counter(label for _d, label, _t in items)
|
||||
out = []
|
||||
for dev, label, tail in items:
|
||||
if counts[label] > 1 and tail:
|
||||
label = f'{label} [{tail}]'
|
||||
out.append((dev, label))
|
||||
return out
|
||||
|
||||
def open(self, port, baud=DEFAULT_BAUD, **kw):
|
||||
if not HAS_SERIAL:
|
||||
self.on_status('未安装 pyserial: py -m pip install pyserial')
|
||||
return
|
||||
params = {**DEFAULTS, **kw}
|
||||
with self._lock:
|
||||
self._target = (port, int(baud), int(params['bytesize']),
|
||||
str(params['parity']).upper(), int(params['stopbits']))
|
||||
|
||||
def close(self):
|
||||
with self._lock:
|
||||
self._target = None
|
||||
|
||||
def is_connected(self):
|
||||
with self._lock:
|
||||
return self.ser is not None
|
||||
|
||||
# --- 发送(队列化, 后台线程写串口) ---
|
||||
|
||||
def send_frame(self, frame, label=''):
|
||||
"""发送一个完整帧 bytes; label 用于回显(自动包装时为 payload 文本)。
|
||||
未连接时直接丢弃并提示(防积压到重连后一起发出, DLPilot 同策略)"""
|
||||
with self._lock:
|
||||
ser = self.ser
|
||||
if ser is None:
|
||||
self.on_status('未连接串口, 命令被丢弃')
|
||||
return False
|
||||
self.q.put((label, bytes(frame)))
|
||||
return True
|
||||
|
||||
# --- 工作线程 ---
|
||||
|
||||
def _run(self):
|
||||
bytesizes = {8: serial.EIGHTBITS, 7: serial.SEVENBITS,
|
||||
6: serial.SIXBITS, 5: serial.FIVEBITS}
|
||||
parities = {'N': serial.PARITY_NONE, 'E': serial.PARITY_EVEN,
|
||||
'O': serial.PARITY_ODD}
|
||||
stopbits = {1: serial.STOPBITS_ONE, 2: serial.STOPBITS_TWO}
|
||||
while True:
|
||||
with self._lock:
|
||||
target = self._target
|
||||
cur = self._open_key
|
||||
if target != cur:
|
||||
if self.ser is not None:
|
||||
try:
|
||||
self.ser.close()
|
||||
except Exception:
|
||||
pass
|
||||
self.ser = None
|
||||
self._open_key = None
|
||||
self.on_status('已断开')
|
||||
if target:
|
||||
port, baud, dbsize, parity, sbits = target
|
||||
try:
|
||||
maker = (serial.serial_for_url if '://' in port
|
||||
else serial.Serial) # '://' 支持 loop:// 等虚拟端口(自检用)
|
||||
self.ser = maker(
|
||||
port, baud, bytesize=bytesizes.get(dbsize, serial.EIGHTBITS),
|
||||
parity=parities.get(parity, serial.PARITY_NONE),
|
||||
stopbits=stopbits.get(sbits, serial.STOPBITS_ONE),
|
||||
timeout=0.15,
|
||||
write_timeout=1.0) # 写超时: 转换器停滞时 write 会
|
||||
# 永久阻塞并卡死线程, 必须设上限
|
||||
with self._lock:
|
||||
self._open_key = target
|
||||
self.parser = None # 换口重建解析器(下次接收时惰性建)
|
||||
self.on_status(f'已连接 {port} @ {baud} {dbsize}{parity}{sbits}')
|
||||
except Exception as e:
|
||||
self.ser = None
|
||||
with self._lock:
|
||||
self._target = None
|
||||
et = str(e)
|
||||
if 'PermissionError' in repr(e) or '拒绝访问' in et \
|
||||
or 'Access is denied' in et:
|
||||
et += '(串口被占用: 检查串口助手/另一个本工具实例)'
|
||||
self.on_status(f'连接失败: {et}')
|
||||
if self.ser is not None:
|
||||
try:
|
||||
item = None
|
||||
try:
|
||||
item = self.q.get_nowait()
|
||||
except queue.Empty:
|
||||
pass
|
||||
if item is not None:
|
||||
label, frame = item
|
||||
self.ser.write(frame)
|
||||
if self.on_tx is not None:
|
||||
self.on_tx(label, frame)
|
||||
data = self.ser.read(4096)
|
||||
if data:
|
||||
self._dispatch_rx(data)
|
||||
except OSError:
|
||||
try:
|
||||
self.ser.close()
|
||||
except Exception:
|
||||
pass
|
||||
self.ser = None
|
||||
self._open_key = None # 必须同步清除, 否则同参数重连被当作已打开而跳过
|
||||
with self._lock:
|
||||
self._target = None
|
||||
self.on_status('串口丢失(设备拔出?), 请重新连接')
|
||||
time.sleep(0.02)
|
||||
|
||||
def _dispatch_rx(self, data):
|
||||
with self._lock:
|
||||
parse = self._parse
|
||||
if parse and self.parser is None: # 惰性建, 带当前 ProtoConfig
|
||||
from protocol import FrameParser
|
||||
self.parser = FrameParser(self._cfg)
|
||||
if parse:
|
||||
for fr in self.parser.feed(data):
|
||||
if self.on_frame is not None:
|
||||
self.on_frame(fr)
|
||||
elif self.on_raw is not None:
|
||||
self.on_raw(data)
|
||||