"""Display models: id stored in main.HMI (offset 16), series byte (offset 11), native resolution. Every model in Nextion Editor 1.68's model dialog, with the series byte and model id the Editor writes (Basic = 0, Enhanced = 1, Intelligent = 3, Edge = 6, Discovery = 100). Sizes are listed landscape (width >= height). """ 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), "NX8048P043_011": (0xA859A323, 3, 800, 480), # Discovery (F) "NX3224F024_011": (0x5B49C1BC, 100, 320, 240), "NX3224F028_011": (0xBA9C8E20, 100, 320, 240), "NX4832F035_011": (0x1CE47603, 100, 480, 320), # Enhanced (K) "NX3224K024_011": (0x5C7E9301, 1, 320, 240), "NX3224K028_011": (0xBDABDC9D, 1, 320, 240), "NX4024K032_011": (0xC4A1A90F, 1, 400, 240), "NX4832K035_011": (0x1BD324BE, 1, 480, 320), "NX4827K043_011": (0x63C18A17, 1, 480, 272), "NX8048K050_011": (0x2E45DE45, 1, 800, 480), "NX8048K070_011": (0xA1F7596A, 1, 800, 480), # Edge (E) "NX4848E021_011": (0xA2770AFE, 6, 480, 480), "NX4848E028_011": (0x0B3DB14B, 6, 480, 480), "NX4848E040_011": (0x21B2AF65, 6, 480, 480), "NX4880E043_011": (0xB7A00D7C, 6, 800, 480), } BY_ID = {v[0]: k for k, v in MODELS.items()} SERIES = {0: "Basic", 1: "Enhanced", 3: "Intelligent", 6: "Edge", 100: "Discovery"} # 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, 1: True, 3: False, 6: True, 100: True} # as listed in the model dialog 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 storage_direction(series: int, direction: int) -> int: """Direction pictures and fonts are stored in (their byte 0 / 3 = 0x0A + this): the project direction, except Discovery, which always stores row by row (0) -- measured in Editor 1.68.""" return 0 if series == 100 else direction % 4 def picture_format(series: int) -> int: """N.i format the Editor writes: 0 raw (Basic, Enhanced), 4 run-length/JPEG (Intelligent, Edge), 3 raw with a 20-byte zero header (Discovery).""" return {3: 4, 6: 4, 100: 3}.get(series, 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]