Files
STM32F4-Base/simulator/tests/regen_ref_png.py
T
wandering1 e4981aa2f6 refactor(docs): point entry-file references at their new homes
AGENTS.md stopped being the store of record for build steps, Python env,
hardware pins, doc conventions, log cost and task ownership. Those facts
already live in docs, skills and role files; the entry file now only
points at them. This commit moves every reference that used to name the
entry file to the authoritative landing point, so a reader who follows a
link arrives at the fact instead of at a sentence that no longer exists.

What changed is links and prose, not behaviour. Code, scripts and tests
only have comment and docstring lines touched; the only non-comment edit
in the whole changeset is one note string inside the generated pin table
JSON, and its generator was changed in the same step so the two stay
byte-identical.

New landing points created before the references were retargeted:
- The console single-writer log design doc, section 7.1, is now the single
  authority for log cost: about 90 B flash and 216 B stack per DBG_ line,
  and the rule that deep call chains must predefine DBG_LINE_BUF_MAX.
  It also carries the full list of the twelve translation units that have
  tightened it, plus the grep command that decides the truth if the list
  and the code ever disagree.
- The document writing standard, section 2, now holds the BOM list.
- keil-build skill gains an exit code table: 0 success, 1 build failure,
  2 BuildEnvError, 3 usage, 4 build lock held. This corrects a belief
  that was never actually written down anywhere: exit 2 does not simply
  mean environment error, argparse also exits 2 and the wrapper script
  was remapped so the two no longer collide.

Regenerated and checked byte for byte:
- The end-to-end architecture SVG in docs/images from its generator.
- tools/netlist_semantics/pinout_kb.json from gen_kb.py.
Both are idempotent; running the generators again produces no diff.

Deliberately not touched, because machines read them:
- scripts/check_bom_drift.py joins every line containing BOM and asserts
  four paths are present, so the entry file BOM line must stay one line.
- scripts/gen_task_table.py reads the TASK_TABLE anchors directly.
- scripts/rename_maps and scripts/archive keep their historical wording;
  they describe what happened, not what is true now.

Verified: doc links report the same six pre-existing findings as the base
commit and no new ones, generated-fresh passes, bom drift is clean across
101 files, and AGENTS.md itself is unchanged in this commit.
2026-11-16 19:38:27 +08:00

72 lines
2.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
regen_ref_png.py — 由黄金参考 .bin 批量重生成目检用 PNG(simulator/tests/ref/*.png)。
背景:ref/*.png 是本地目检调试产物(.gitignore 忽略;入库的基准是同名 .bin),
**不会**随 .bin 参考自动更新。
刷过 `check_content_pages.py --update` 或改了字体/视觉后,必须重跑本脚本,否则 PNG
仍是旧渲染(缺字/错位,看似"乱码")。
用法(仓库根目录;PIL 依赖用 .venv,重建见 new-machine-setup skill):
.venv\\Scripts\\python.exe simulator/tests/regen_ref_png.py
.venv\\Scripts\\python.exe simulator/tests/regen_ref_png.py --scale 4
.venv\\Scripts\\python.exe simulator/tests/regen_ref_png.py --no-invert # 白字黑底(设备原样)
默认 `--scale 6 --invert`(深字白底,便于目检)。
退出码:0 全部成功;1 无 .bin 参考 / 有文件转换失败。
"""
import argparse
import importlib.util
import sys
from pathlib import Path
HERE = Path(__file__).resolve().parent # simulator/tests/
REF_DIR = HERE / "ref"
I1_TO_PNG = HERE.parent / "i1_to_png.py" # simulator/i1_to_png.py
def _load_i1_to_png():
"""从 simulator/i1_to_png.py 载入转换模块(目录不同,不能直接 import)。"""
spec = importlib.util.spec_from_file_location("i1_to_png", I1_TO_PNG)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod
def main():
ap = argparse.ArgumentParser(description="由 ref/*.bin 批量重生成目检 PNG")
ap.add_argument("--scale", type=int, default=6, help="放大倍数(默认 6)")
ap.add_argument("--invert", dest="invert", action="store_true", default=True,
help="前景/背景互换:深字白底(默认开,便于目检)")
ap.add_argument("--no-invert", dest="invert", action="store_false",
help="关闭互换:白字黑底(与设备显示一致)")
args = ap.parse_args()
if not I1_TO_PNG.exists():
print("FAIL: 找不到 %s" % I1_TO_PNG)
return 1
bins = sorted(REF_DIR.glob("*.bin"))
if not bins:
print("FAIL: %s 下没有 .bin 参考(先运行 check_content_pages.py --update)" % REF_DIR)
return 1
i1_to_png = _load_i1_to_png()
ok = 0
for b in bins:
try:
out = i1_to_png.i1_to_png(str(b), scale=args.scale, invert=args.invert)
print(" %-24s -> %s" % (b.name, Path(out).name))
ok += 1
except Exception as e: # 单文件失败不中断其余
print(" %-24s FAIL: %s" % (b.name, e))
print("%s: %d/%d 张 PNG 已生成(scale=%d invert=%s)"
% ("PASS" if ok == len(bins) else "FAIL", ok, len(bins), args.scale, args.invert))
return 0 if ok == len(bins) else 1
if __name__ == "__main__":
sys.exit(main())