50 lines
2.3 KiB
Python
50 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""生成修改后的 led3number.c: 替换移位拼接段为新布局逻辑"""
|
|
import re
|
|
|
|
SRC = "/root/.openclaw/media/inbound/led3number---69efe51a-567a-4354-a1b8-6c796c184183.txt"
|
|
OUT = "/root/.openclaw/workspace/led3number_new.c"
|
|
text = open(SRC, encoding="utf-8", errors="replace").read().replace("\r\n", "\n")
|
|
|
|
# 定位原移位段: 第二个 for(i=0;i<16;i++) 循环 (move_reg1 = code12_ram[5][i] 开头)
|
|
pat = re.compile(r"for\(i=0;i<16;i\+\+\)\s*\{\s*move_reg1 = code12_ram\[5\]\[i\];")
|
|
m = pat.search(text)
|
|
assert m, "移位段起始未找到"
|
|
start = m.start()
|
|
end = text.find("memcpy(&CodeRAM[32- Screen.Uart.Receive_ID_Number*4][0]")
|
|
assert end != -1, "memcpy 未找到"
|
|
# TODO 注释行在 memcpy 之前
|
|
todo_end = text.rfind("// TODO", start, end)
|
|
assert todo_end != -1
|
|
# 找到 TODO 行结尾
|
|
nl = text.find("\n", todo_end)
|
|
seg_end = nl + 1
|
|
|
|
new_seg = """\t// ========== 新布局: 32列 = 1空 | [2空 + 7数字 + 1空]x3 | 1空 ==========\n\
|
|
\t// 数字本体(区域内列2-8, 7列) → 全局列 3-9 / 13-19 / 23-29\n\
|
|
\t// 左边界1列 + 每数字左2右1空 + 右边界1列, 数字间空隙3列\n\
|
|
\tfor(i=0;i<16;i++)\n\
|
|
\t{\n\
|
|
\t\tuint8_t s2 = code12_ram[2][i]; // 数字1 高字节(区域内列0-7)\n\
|
|
\t\tuint8_t s3 = code12_ram[3][i]; // 数字1 低字节(区域内列8-15)\n\
|
|
\t\tuint8_t s4 = code12_ram[4][i]; // 数字2 高字节\n\
|
|
\t\tuint8_t s5 = code12_ram[5][i]; // 数字2 低字节\n\
|
|
\t\tuint8_t s6 = code12_ram[6][i]; // 数字3 高字节\n\
|
|
\t\tuint8_t s7 = code12_ram[7][i]; // 数字3 低字节\n\
|
|
\n\
|
|
\t\tcode12_ram[2][i] = (s2 >> 1) & 0x1F; // 数字1 → 列3-7\n\
|
|
\t\tcode12_ram[3][i] = ((s2 & 0x01) << 7) | ((s3 >> 1) & 0x40) // 数字1 → 列8-9\n\
|
|
\t\t | ((s4 >> 3) & 0x07); // 数字2 → 列13-15\n\
|
|
\t\tcode12_ram[4][i] = ((s4 & 0x07) << 5) | ((s5 & 0x80) >> 3) // 数字2 → 列16-19\n\
|
|
\t\t | ((s6 >> 5) & 0x01); // 数字3 → 列23\n\
|
|
\t\tcode12_ram[5][i] = ((s6 & 0x1F) << 3) | ((s7 & 0x80) >> 5); // 数字3 → 列24-29\n\
|
|
\t}\n\
|
|
\n\
|
|
"""
|
|
|
|
new_text = text[:start] + new_seg + text[seg_end:]
|
|
open(OUT, "w", encoding="utf-8").write(new_text)
|
|
print("已生成:", OUT)
|
|
print("原始文件长度:", len(text), "→ 新文件长度:", len(new_text))
|