tft: picture, crop, progress bar, checkbox, radio; page RAM header fix; README sub-goals

- five more Basic types in tft_types (default variants; others refused)
- the page RAM image starts with 4 x FF + one FF per component (padded to 4)
- README: .tft status split into sub-goals with a stated basis each
- sample generator: display direction and gradient pictures; regression test
  walks sub-folders (84 Editor samples reproduced)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Fable 5.2 committed 2026-11-16 23:31:12 +01:00
1 parent a8622e7462
commit 0287cf21e4
8 files changed
+101 -10

No files matched your search

+20 -1
View File
@@ -32,7 +32,26 @@ Every percentage is a count with a stated basis, so it can be checked (details i
| Readable attribute names in JSON | **100 %** (31/31 types) | every value list the Editor documents, incl. the Intelligent-only types and load effects | | Readable attribute names in JSON | **100 %** (31/31 types) | every value list the Editor documents, incl. the Intelligent-only types and load effects |
| Rendering, Basic components | **100 %** (20/20 pixel-exact) | incl. gauges and QR codes (own encoder, no dependencies) | | Rendering, Basic components | **100 %** (20/20 pixel-exact) | incl. gauges and QR codes (own encoder, no dependencies) |
| Rendering, all components | **94 %** (29/31 pixel-exact) | Intelligent ComboBox and Switch are drawn, but their anti-aliased edges are approximate (~99 % / ~92 % of pixels exact) | | Rendering, all components | **94 %** (29/31 pixel-exact) | Intelligent ComboBox and Switch are drawn, but their anti-aliased edges are approximate (~99 % / ~92 % of pixels exact) |
| `.tft` compilation | **81 %** (6.5/8 milestones) | `nxhmi build-tft`: byte-identical to the Editor for NX4832T035 projects with pages, hotspots, plain text, int variables, timers, touch caps, pictures, fonts and script (assignments, arithmetic, 27 commands, if/else/while/for, global variables); the other component types not yet; never tried on a display |
### `.tft` compilation (`nxhmi build-tft`)
Research stage. The goal is output byte-identical to Nextion Editor's; anything not measured is
refused with the reason instead of guessed. Checked against 84 Editor-compiled sample projects.
The firmware files inside every `.tft` are read from your own Editor installation at build time.
| Sub-goal | Status | Basis |
|---|---|---|
| File container | **done** (4/4) | header, layout table, the four checksums, resource area |
| Pictures and fonts in the `.tft` | **done** (2/2) | any number of each (Basic picture format) |
| Page section structure | **done** | code blob, name hashes, RAM image, attribute records, page table, object records |
| Script: statements | **mostly** | assignments, arithmetic, numbers, global `int` variables, attribute references, `if` / `else if` / `else` / `while` / `for`. Not yet: `>=` (inferred only), mixed `&&`/`||`, string attributes and string functions, negative global initial values |
| Script: commands | **39 %** (25/64) | commands whose token was read from a compiled sample |
| Script: system variables and colours | **40 %** (29/72) | same basis |
| Component types (Basic) | **65 %** (13/20) | page, hotspot, text, number, button, picture, crop, progress bar, checkbox, radio, int variable, timer, touch cap. Missing: slider, dual-state button, float, scrolling text, gauge, waveform, QR code |
| Component variants | **partly** | number: all backgrounds and border styles. Button: all 5 styles, solid background only. Text: flat on solid colour only. Progress bar: horizontal, solid colours only. Checkbox: default style only. Page: solid colour only. No global (`vscope`) components, no drag / effects |
| Display directions | **25 %** (1/4) | 90 degrees (landscape) only |
| Display models | **4 %** (1/27) | NX4832T035 only |
| Tested on a real display | **no** | byte-identity with the Editor is the only evidence so far |
## Compatibility ## Compatibility
+1 -1
View File
@@ -113,7 +113,7 @@ byte for byte, or a file written by nxhmi was opened in the Editor and showed th
| Trailer checksum | solved for any length (`tft.trailer`); one model measured | | Trailer checksum | solved for any length (`tft.trailer`); one model measured |
| 3 header checksums (0x44, 0xC4, 0x18C) | solved (`tft.header_checksums`, `tft.seal`) | | 3 header checksums (0x44, 0xC4, 0x18C) | solved (`tft.header_checksums`, `tft.seal`) |
| Pictures and fonts inside the TFT | solved (FORMAT.md 7.2) | | Pictures and fonts inside the TFT | solved (FORMAT.md 7.2) |
| Compiled page format | structure solved (code blob, name hashes, RAM image, attribute records, page table, object records -- FORMAT.md 7.3-7.5); per-type tables done for page, hotspot, text (solid background, flat style), int variable, timer, touch cap; the other types need their slot tables and generated draw scripts | | Compiled page format | structure solved (code blob, name hashes, RAM image, attribute records, page table, object records -- FORMAT.md 7.3-7.5); 13 of 20 Basic types in `nxhmi.tft_types` (page, hotspot, text, number, button, picture, crop, progress bar, checkbox, radio, int variable, timer, touch cap; variants and limits in the README table); missing: slider, dual-state button, float, scrolling text, gauge, waveform, QR code |
| Event-code tokens | solved for what was sampled (FORMAT.md 7.6): 27 commands, 33 system variables/colours, numbers, global variables, attribute references, if/else/while/for. Not sampled: string functions and attributes, the remaining commands and system variables, `>=` op code | | Event-code tokens | solved for what was sampled (FORMAT.md 7.6): 27 commands, 33 system variables/colours, numbers, global variables, attribute references, if/else/while/for. Not sampled: string functions and attributes, the remaining commands and system variables, `>=` op code |
| Builder (`nxhmi build-tft`) | byte-identical to the Editor for the supported subset (one model: NX4832T035); refuses anything else. **Never tested on a real display** | | Builder (`nxhmi build-tft`) | byte-identical to the Editor for the supported subset (one model: NX4832T035); refuses anything else. **Never tested on a real display** |
| Licensing | every `.tft` embeds Nextion's firmware files; the repo must never ship them -- a builder would read them from the user's own Editor installation | | Licensing | every `.tft` embeds Nextion's firmware files; the repo must never ship them -- a builder would read them from the user's own Editor installation |
+2 -1
View File
@@ -418,7 +418,8 @@ tokenised script line; an empty chunk ends a section.
(timer: 7.6; slider, touch cap -- **OPEN**); the page's Preinitialize lines; the chunk (timer: 7.6; slider, touch cap -- **OPEN**); the page's Preinitialize lines; the chunk
`09 21 08`; the page's Postinitialize lines; empty chunk. `09 21 08`; the page's Postinitialize lines; empty chunk.
RAM image: 8 x FF, then every RAM-stored attribute of every component in component order, RAM image: 4 x FF, one FF per component of the page (the page included) padded with FF to a
multiple of 4, then every RAM-stored attribute of every component in component order,
each aligned to its size, each component padded to 4. For a page: `sta` (u8), pad, `bco` (u16). each aligned to its size, each component padded to 4. For a page: `sta` (u8), pad, `bco` (u16).
### 7.4 Attribute records (24 bytes) ### 7.4 Attribute records (24 bytes)
+11
View File
@@ -221,3 +221,14 @@ The generated scripts are ordinary Nextion script compiled by the same compiler
attributes written as literals and RAM attributes as record references. `nxhmi.tft_types` attributes written as literals and RAM attributes as record references. `nxhmi.tft_types`
therefore describes a type as: visible attributes, record kinds, RAM order, script templates. therefore describes a type as: visible attributes, record kinds, RAM order, script templates.
The RAM order and the unnamed drawing commands still have to be read from samples per type. The RAM order and the unnamed drawing commands still have to be read from samples per type.
State on 2026-11-17 (paused by the owner mid-way): 13 Basic types compile, 84 samples reproduced.
Page RAM image starts with 4 x FF plus one FF per component padded to 4 (found when a page
with five components failed). Read from samples but not yet in the builder: vertical progress
bar (`sys05_4=val*h/100`, fill from `endy+1-sys05_4`), text with border / crop / picture
background (same `_back` / `_border` rules as number, but `sta`, `style`, `borderc`, `borderw`,
`spax`, `spay` are constants there and are written into the script as literals).
Samples waiting to be compiled: `g3.json` in the session scratchpad (directions 0/180/270,
`>=`, mixed `&&`/`||`, string attributes, negative globals, more variants) -- regenerate with
`tools/make_tft_samples.py` (`direction` and `gradient` keys) if the scratchpad is gone.
New sample pairs live in `D:\Claude\nextion-tft-samples\2026-11-17` (outside the repo).
+5 -3
View File
@@ -25,7 +25,7 @@ BLOCK = 0x10000
_RECT = ("x", "y", "w", "h", "endx", "endy") _RECT = ("x", "y", "w", "h", "endx", "endy")
_RECT_REC = {"x": (9, 0x0B, 6000, -6000), "y": (10, 0x0C, 6000, -6000), "w": (11, 0x0D, 2000, -2000), _RECT_REC = {"x": (9, 0x0B, 6000, -6000), "y": (10, 0x0C, 6000, -6000), "w": (11, 0x0D, 2000, -2000),
"h": (12, 0x0E, 2000, -2000), "endx": (13, 0x08, 32767, -32768), "endy": (14, 0x08, 32767, -32768)} "h": (12, 0x0E, 2000, -2000), "endx": (13, 0x08, 32767, -32768), "endy": (14, 0x08, 32767, -32768)}
_CONST_KINDS = (0x01, 0x02) _CONST_KINDS = (0x01, 0x02, 0x08)
def _chunk(b: bytes) -> bytes: def _chunk(b: bytes) -> bytes:
@@ -184,7 +184,9 @@ def compile_pages(pages: list[Page], program: str, nfonts: int = 0, npics: int =
section(program_lines + ["page 0"]) section(program_lines + ["page 0"])
records, objects, table = bytearray(), bytearray(), [] records, objects, table = bytearray(), bytearray(), []
for pi, row in enumerate(comps): for pi, row in enumerate(comps):
ram = bytearray(b"\xff" * 8) # RAM image: 4 x FF, one FF per component (padded to 4), then the attributes
ram = bytearray(b"\xff" * (4 + 4 * ((len(row) + 3) // 4)))
head = len(ram)
prec, first_obj, comp_names, init = bytearray(), len(objects) // tft.OBJ_SIZE, [], [] prec, first_obj, comp_names, init = bytearray(), len(objects) // tft.OBJ_SIZE, [], []
pre, post = [], [] pre, post = [], []
current[0] = row[0].name current[0] = row[0].name
@@ -192,7 +194,7 @@ def compile_pages(pages: list[Page], program: str, nfonts: int = 0, npics: int =
d, tid, cid = k.d, k.tid, k.v["id"] d, tid, cid = k.d, k.tid, k.v["id"]
current[1] = k current[1] = k
owner = struct.pack("<BB", pi, cid) if d.get("owner", True) else b"\xff\xff" owner = struct.pack("<BB", pi, cid) if d.get("owner", True) else b"\xff\xff"
group = g + 4 + (4 if tid == 121 else len(ram)) # RAM address of the component's data group = g + (head if tid == 121 else 4 + len(ram)) # RAM address of the component's data
recs = [bytes(tft.REC_SIZE)] * k.nslots recs = [bytes(tft.REC_SIZE)] * k.nslots
amap = [0xFFFF] * 88 amap = [0xFFFF] * 88
+50 -2
View File
@@ -22,8 +22,8 @@ from .tft_code import Unsupported
# attribute -> position in the object record's map (u16 table at +0x38) # attribute -> position in the object record's map (u16 table at +0x38)
MAP = {"vscope": 1, "sta": 2, "bco": 4, "picc": 5, "pic": 6, "pco2": 12, "pco": 16, "val": 20, "bco2": 24, MAP = {"vscope": 1, "sta": 2, "bco": 4, "picc": 5, "pic": 6, "pco2": 12, "pco": 16, "val": 20, "bco2": 24,
"font": 25, "xcen": 26, "ycen": 27, "txt": 28, "txt_maxl": 29, "tim": 33, "en": 34, "lenth": 41, "x": 42, "font": 25, "xcen": 26, "dez": 30, "dis": 55, "ycen": 27, "txt": 28, "txt_maxl": 29, "tim": 33, "en": 34, "lenth": 41, "x": 42,
"y": 43, "endx": 44, "endy": 45, "w": 46, "h": 47, "id": 49, "isbr": 54, "spax": 56, "spay": 57, "pw": 58, "y": 43, "endx": 44, "endy": 45, "w": 46, "h": 47, "id": 49, "vvs0": 50, "vvs1": 51, "isbr": 54, "spax": 56, "spay": 57, "pw": 58,
"style": 59, "borderc": 60, "borderw": 61, "type": 62, "format": 64} "style": 59, "borderc": 60, "borderw": 61, "type": 62, "format": 64}
U8, U16, COLOR = (0x31, 1, 255, 0), (0x32, 2, 65535, 0), (0x32, 2, 65535, 0) U8, U16, COLOR = (0x31, 1, 255, 0), (0x32, 2, 65535, 0), (0x32, 2, 65535, 0)
TOUCH = (("down", "codesdown", ()), ("up", "codesup", ())) TOUCH = (("down", "codesdown", ()), ("up", "codesup", ()))
@@ -143,6 +143,49 @@ def _button(v, s, env):
events=(("down", "codesdown", ("@val=1", refresh)), ("up", "codesup", ("@val=0", refresh)))) events=(("down", "codesdown", ("@val=1", refresh)), ("up", "codesup", ("@val=0", refresh))))
def _picture(v, s, env):
return dict(vis=["pic"], rec={"pic": (0x32, 2, "pics", 0)}, ram=["pic"], flag=0x37, events=TOUCH,
draw=["cmd01_4 @x,@y,@pic"])
def _crop(v, s, env):
offset = (0x08, 2, 2147483647, -2147483648)
_need("crop", v, vvs0=0, vvs1=0) # the 6 RAM bytes after picc may hold them
return dict(vis=["picc", "vvs0", "vvs1"], rec={"picc": (0x32, 2, "pics", 0), "vvs0": offset, "vvs1": offset},
ram=["picc", 6], flag=0x37, events=TOUCH, draw=["cmd0A_4 @x,@y,@w,@h,@x+@vvs0,@y+@vvs1,@picc"])
TOGGLE = ("if(@val==1)", "{", "@val=0", "}else", "{", "@val=1", "}")
def _progress_bar(v, s, env):
_need("progress bar", v, sta=0, dez=0)
return dict(vis=["sta", "dez", "val", "dis", "bco", "pco"],
rec={"sta": (0x21, 1, 1, 0), "dez": (0x21, 1, 1, 0), "val": (0x31, 1, 100, 0), "dis": (0x31, 1, 100, 0),
"bco": COLOR, "pco": COLOR},
ram=["sta", "dez", "val", "dis", "bco", "pco"], flag=0x37, events=TOUCH,
draw=["sys05_4=@val*@w/100", "fill @x,@y,sys05_4,@h,@pco", "fill @x+sys05_4,@y,@w-sys05_4,@h,@bco"])
def _checkbox(v, s, env):
_need("checkbox", v, style=2)
return dict(vis=["style", "bco", "pco", "val"],
rec={"style": (0x21, 1, 3, 0), "bco": COLOR, "pco": COLOR, "val": (0x31, 1, 1, 0)},
ram=["style", 3, "bco", "pco", "val"], flag=0x37,
draw=["sys05_4=@w/4", "sys07_4=@w-sys05_4-sys05_4", "fill @x,@y,@w,@h,@bco", "if(@val==1)", "{",
"fill @x+sys05_4,@y+sys05_4,sys07_4,sys07_4,@pco", "}", "cmd07_8 @x,@y,@w,@h,16936,59164,1"],
events=(("down", "codesdown", TOGGLE), ("up", "codesup", ())))
def _radio(v, s, env):
return dict(vis=["bco", "pco", "val"], rec={"bco": COLOR, "pco": COLOR, "val": (0x31, 1, 1, 0)},
ram=["bco", "pco", "val"], flag=0x37,
draw=["sys05_4=@w&1", "if(sys05_4==0)", "{", "sys05_4=@w/2-1", "}else", "{", "sys05_4=@w/2", "}",
"cirs @x+sys05_4,@y+sys05_4,sys05_4,@bco", "cir @x+sys05_4,@y+sys05_4,sys05_4,16936",
"if(@val==1)", "{", "cirs @x+sys05_4,@y+sys05_4,sys05_4/2,@pco", "}"],
events=(("down", "codesdown", TOGGLE), ("up", "codesup", ())))
# type id -> (name, has a rectangle and the 19 common attributes, describe) # type id -> (name, has a rectangle and the 19 common attributes, describe)
TYPES = { TYPES = {
121: ("page", True, _page), 121: ("page", True, _page),
@@ -153,4 +196,9 @@ TYPES = {
116: ("text", True, _text), 116: ("text", True, _text),
54: ("number", True, _number), 54: ("number", True, _number),
98: ("button", True, _button), 98: ("button", True, _button),
112: ("picture", True, _picture),
113: ("crop", True, _crop),
106: ("progress_bar", True, _progress_bar),
56: ("checkbox", True, _checkbox),
57: ("radio", True, _radio),
} }
+2 -1
View File
@@ -138,7 +138,7 @@ class Build(unittest.TestCase):
def test_against_editor_samples(self): def test_against_editor_samples(self):
from nxhmi.container import HMIFile from nxhmi.container import HMIFile
done = 0 done = 0
for ref in sorted(glob.glob(os.path.join(SAMPLES, "*.tft"))): for ref in sorted(glob.glob(os.path.join(SAMPLES, "**", "*.tft"), recursive=True)):
hmi = ref[:-4] + ".HMI" hmi = ref[:-4] + ".HMI"
if not os.path.exists(hmi): if not os.path.exists(hmi):
continue continue
@@ -149,6 +149,7 @@ class Build(unittest.TestCase):
with open(ref, "rb") as fh: with open(ref, "rb") as fh:
self.assertEqual(out, fh.read(), os.path.basename(ref)) self.assertEqual(out, fh.read(), os.path.basename(ref))
done += 1 done += 1
print("%d samples reproduced byte for byte" % done, end=" ")
self.assertGreater(done, 0) self.assertGreater(done, 0)
+10 -1
View File
@@ -25,12 +25,21 @@ from nxhmi.page import Page # noqa: E402
def make(spec): def make(spec):
kw = {"program": spec["program"]} if "program" in spec else {} kw = {"program": spec["program"]} if "program" in spec else {}
h = project.new_project("NX4832T035_011", **kw) h = project.new_project("NX4832T035_011", **kw)
if "direction" in spec: # 0..3 = 0/90/180/270 degrees (main.HMI byte 12)
from nxhmi import models
from nxhmi.container import build
w, hh = models.page_size("NX4832T035_011", spec["direction"])
h = build([("main.HMI", project.make_main("NX4832T035_011", [("pa", "0.pa")], "iso-8859-1", spec["direction"])),
("Program.s", h.read("Program.s")), ("0.pa", C.new_page("page0", w=w, h=hh).pack())])
for height in spec.get("fonts", []): for height in spec.get("fonts", []):
project.add_font(h, fonts.from_ttf(None, height)) project.add_font(h, fonts.from_ttf(None, height))
for i, (w, hh) in enumerate(spec.get("pics", [])): for i, (w, hh) in enumerate(spec.get("pics", [])):
from PIL import Image from PIL import Image
b = io.BytesIO() b = io.BytesIO()
Image.new("RGB", (w, hh), (200, 40 + 30 * i, 40)).save(b, "PNG") im = Image.new("RGB", (w, hh), (200, 40 + 30 * i, 40))
if spec.get("gradient"): # every pixel different: shows how pictures are rotated
im.putdata([((x * 8) & 255, (y * 8) & 255, (x + y) & 255) for y in range(hh) for x in range(w)])
im.save(b, "PNG")
project.add_picture(h, b.getvalue()) project.add_picture(h, b.getvalue())
for pi, ps in enumerate(spec.get("pages", [spec])): for pi, ps in enumerate(spec.get("pages", [spec])):
if pi: if pi: