🚗 LED 3位数点阵显示工程:数字布局调整为 [2空+7亮+1空]x3 + 左右各1列边界(附模拟器/C验证)
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""生成 C 验证程序: 独立复刻填充+新移位逻辑, 输出点阵供与 Python 模拟对照"""
|
||||
import re
|
||||
|
||||
SRC = "/root/.openclaw/media/inbound/led3number---69efe51a-567a-4354-a1b8-6c796c184183.txt"
|
||||
text = open(SRC, encoding="utf-8", errors="replace").read().replace("\r\n", "\n")
|
||||
m = re.search(r"Code_Number_16_12\[17\]\[32\]\s*=\s*\{(.*?)\n\};", text, re.S)
|
||||
entries = re.findall(r"\{([^{}]*)\}", m.group(1))
|
||||
fonts = []
|
||||
for e in entries:
|
||||
fonts.append([int(x, 16) for x in re.findall(r"0[xX][0-9A-Fa-f]+", e)])
|
||||
# 补到 17 个(未初始化的补 0)
|
||||
while len(fonts) < 17:
|
||||
fonts.append([0]*32)
|
||||
|
||||
# 生成 C 字库
|
||||
rows = []
|
||||
for idx, f in enumerate(fonts):
|
||||
vals = ", ".join(f"0x{v:02X}" for v in f)
|
||||
rows.append(f" /* {idx} */ {{ {vals} }}")
|
||||
font_tbl = ",\n".join(rows)
|
||||
|
||||
c_code = f'''#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
static const unsigned char Code_Number_16_12[17][32] = {{
|
||||
{font_tbl}
|
||||
}};
|
||||
|
||||
/* 模拟: 填充 + 新移位 (照抄 led3number_new.c 逻辑) */
|
||||
static void process(const uint8_t chars[4], uint8_t out[4][16])
|
||||
{{
|
||||
uint8_t code12[8][16];
|
||||
int roll, i;
|
||||
memset(code12, 0, sizeof(code12));
|
||||
for (roll = 0; roll < 4; roll++) {{
|
||||
uint8_t cc = chars[roll];
|
||||
for (i = 0; i < 16; i++) {{
|
||||
if (cc == 0x20) {{
|
||||
code12[roll*2][i] = Code_Number_16_12[10][i*2];
|
||||
code12[roll*2+1][i] = Code_Number_16_12[10][i*2+1];
|
||||
}} else {{
|
||||
code12[roll*2][i] = Code_Number_16_12[cc-0x30][i*2];
|
||||
code12[roll*2+1][i] = (uint8_t)(Code_Number_16_12[cc-0x30][i*2+1] << 6);
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
for (i = 0; i < 16; i++) {{
|
||||
uint8_t s2 = code12[2][i];
|
||||
uint8_t s3 = code12[3][i];
|
||||
uint8_t s4 = code12[4][i];
|
||||
uint8_t s5 = code12[5][i];
|
||||
uint8_t s6 = code12[6][i];
|
||||
uint8_t s7 = code12[7][i];
|
||||
|
||||
code12[2][i] = (uint8_t)((s2 >> 1) & 0x1F);
|
||||
code12[3][i] = (uint8_t)(((s2 & 0x01) << 7) | ((s3 >> 1) & 0x40) | ((s4 >> 3) & 0x07));
|
||||
code12[4][i] = (uint8_t)(((s4 & 0x07) << 5) | ((s5 & 0x80) >> 3) | ((s6 >> 5) & 0x01));
|
||||
code12[5][i] = (uint8_t)(((s6 & 0x1F) << 3) | ((s7 & 0x80) >> 5));
|
||||
}}
|
||||
memcpy(out, &code12[2][0], 64);
|
||||
}}
|
||||
|
||||
static void render(const char *name, const uint8_t out[4][16])
|
||||
{{
|
||||
int r, c;
|
||||
printf("=== %s ===\\n", name);
|
||||
printf("col: ");
|
||||
for (c = 0; c < 32; c++) printf("%d", c % 10);
|
||||
printf("\\n");
|
||||
for (r = 0; r < 16; r++) {{
|
||||
printf("%2d ", r);
|
||||
for (c = 0; c < 32; c++) {{
|
||||
uint8_t byte = out[c/8][r];
|
||||
int bit = (byte >> (7 - (c % 8))) & 1;
|
||||
putchar(bit ? '#' : '.');
|
||||
}}
|
||||
printf("\\n");
|
||||
}}
|
||||
}}
|
||||
|
||||
int main(void)
|
||||
{{
|
||||
uint8_t out[4][16];
|
||||
/* 字符: 第1个被丢弃(协议), 后3个显示; 0x20=空格 */
|
||||
process((uint8_t[]){{'1','2','3','0'}}, out); render("NEW 123+0", out);
|
||||
process((uint8_t[]){{' ','4','5','6'}}, out); render("NEW 456+7", out);
|
||||
process((uint8_t[]){{'8','8','8','8'}}, out); render("NEW 888+8", out);
|
||||
return 0;
|
||||
}}
|
||||
'''
|
||||
open("/root/.openclaw/workspace/led3number_test.c", "w").write(c_code)
|
||||
print("已生成 led3number_test.c")
|
||||
Reference in New Issue
Block a user