Files
openhmi-nx/src/nxhmi/models.py
T

59 lines
2.7 KiB
Python
Raw Normal View History

"""Display models: id stored in main.HMI (offset 16), series byte (offset 11), native resolution.
Only series whose series byte was confirmed in the Editor are listed (Basic = 0, Intelligent = 3).
Model ids are the 32-bit values the Editor writes for each model.
"""
from __future__ import annotations
# name: (model id, series byte, width, height)
MODELS = {
"NX3224T024_011": (0xF59677A7, 0, 320, 240),
"NX3224T028_011": (0x1443383B, 0, 320, 240),
"NX4024T032_011": (0x6D494DA9, 0, 400, 240),
"NX4832T035_011": (0xB23BC018, 0, 480, 320),
"NX4827T043_011": (0xCA296EB1, 0, 480, 272),
"NX8048T050_011": (0x87AD3AE3, 0, 800, 480),
"NX8048T070_011": (0x081FBDCC, 0, 800, 480),
"NX4827P043_011": (0x181169DA, 3, 480, 272),
"NX8048P050_011": (0x55953D88, 3, 800, 480),
"NX8048P070_011": (0xDA27BAA7, 3, 800, 480),
"NX1060P070_011": (0xC43473C2, 3, 1024, 600),
"NX1060P101_011": (0x4FC44FA0, 3, 1024, 600),
}
BY_ID = {v[0]: k for k, v in MODELS.items()}
SERIES = {0: "Basic", 3: "Intelligent"}
# main.HMI offset 12: display direction, in 90-degree steps as chosen in the Editor
# (Setting > Display: 0 / 90 / 180 / 270). Basic panels are portrait at 0 degrees, so the
# landscape sizes listed above need 90 or 270; Intelligent panels are landscape at 0 and 180.
NATIVE_PORTRAIT = {0: True, 3: False}
def direction_byte(model: str, landscape: bool = True, flipped: bool = False) -> int:
"""main.HMI byte 12 for a landscape/portrait project on this model (flipped = +180 degrees)."""
portrait_native = NATIVE_PORTRAIT[lookup(model)[1]]
return (1 if landscape == portrait_native else 0) + (2 if flipped else 0)
def page_size(model: str, direction: int):
"""(width, height) of the pages for main.HMI byte 12 = direction."""
_, series, w, h = lookup(model)
landscape = (direction % 2 == 1) == NATIVE_PORTRAIT[series]
return (w, h) if landscape else (h, w)
# main.HMI offset 13: character encoding, value -> name as in the Editor's Setting > Display list.
# Measured by choosing each entry in Nextion Editor 1.68 and saving.
ENCODINGS = {
"ascii": 1, "gb2312": 2, "iso-8859-1": 3, "iso-8859-2": 4, "iso-8859-3": 5, "iso-8859-4": 6,
"iso-8859-5": 7, "iso-8859-6": 8, "iso-8859-7": 9, "iso-8859-8": 10, "iso-8859-9": 11,
"iso-8859-13": 12, "iso-8859-15": 13, "iso-8859-11": 14, "ks_c_5601-1987": 15, "big5": 16,
"windows-1255": 17, "windows-1256": 18, "windows-1257": 19, "windows-1258": 20,
"windows-874": 21, "koi8-r": 22, "shift-jis": 23, "utf-8": 24,
}
def lookup(model: str):
if model not in MODELS:
raise KeyError("unknown model %r; known: %s" % (model, ", ".join(sorted(MODELS))))
return MODELS[model]