pyvisionect 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. pyvisionect/__init__.py +120 -0
  2. pyvisionect/devices/__init__.py +92 -0
  3. pyvisionect/devices/enums.py +403 -0
  4. pyvisionect/devices/panels.py +242 -0
  5. pyvisionect/devices/tclv.py +460 -0
  6. pyvisionect/imaging/README.md +175 -0
  7. pyvisionect/imaging/__init__.py +181 -0
  8. pyvisionect/imaging/checksum.py +114 -0
  9. pyvisionect/imaging/constants.py +131 -0
  10. pyvisionect/imaging/data/blue_noise_64.npy +0 -0
  11. pyvisionect/imaging/decode.py +172 -0
  12. pyvisionect/imaging/dither.py +357 -0
  13. pyvisionect/imaging/encoder.py +594 -0
  14. pyvisionect/imaging/geometry.py +129 -0
  15. pyvisionect/imaging/grey.py +104 -0
  16. pyvisionect/imaging/interlace.py +244 -0
  17. pyvisionect/imaging/pack.py +142 -0
  18. pyvisionect/imaging/panel.py +339 -0
  19. pyvisionect/imaging/partial.py +931 -0
  20. pyvisionect/imaging/rects.py +466 -0
  21. pyvisionect/io/__init__.py +33 -0
  22. pyvisionect/io/tcp.py +795 -0
  23. pyvisionect/io/usb/__init__.py +237 -0
  24. pyvisionect/io/usb/cli.py +278 -0
  25. pyvisionect/io/usb/commands.py +781 -0
  26. pyvisionect/io/usb/console.py +730 -0
  27. pyvisionect/io/usb/device.py +914 -0
  28. pyvisionect/io/usb/discovery.py +260 -0
  29. pyvisionect/io/usb/encryption.py +262 -0
  30. pyvisionect/io/usb/errors.py +175 -0
  31. pyvisionect/io/usb/fake.py +292 -0
  32. pyvisionect/io/usb/parsers.py +1464 -0
  33. pyvisionect/io/usb/provisioning.py +502 -0
  34. pyvisionect/packets/__init__.py +135 -0
  35. pyvisionect/packets/control.py +95 -0
  36. pyvisionect/packets/file.py +325 -0
  37. pyvisionect/packets/image.py +234 -0
  38. pyvisionect/packets/misc.py +202 -0
  39. pyvisionect/packets/param.py +284 -0
  40. pyvisionect/packets/status.py +518 -0
  41. pyvisionect/packets/stored.py +217 -0
  42. pyvisionect/py.typed +0 -0
  43. pyvisionect/session/__init__.py +100 -0
  44. pyvisionect/session/connection.py +1043 -0
  45. pyvisionect/session/device.py +587 -0
  46. pyvisionect/session/events.py +196 -0
  47. pyvisionect/session/filetransfer.py +251 -0
  48. pyvisionect/session/pending.py +425 -0
  49. pyvisionect/wire/__init__.py +91 -0
  50. pyvisionect/wire/blocks.py +350 -0
  51. pyvisionect/wire/checksum.py +115 -0
  52. pyvisionect/wire/errors.py +176 -0
  53. pyvisionect/wire/framing.py +334 -0
  54. pyvisionect-0.1.0.dist-info/METADATA +1030 -0
  55. pyvisionect-0.1.0.dist-info/RECORD +58 -0
  56. pyvisionect-0.1.0.dist-info/WHEEL +4 -0
  57. pyvisionect-0.1.0.dist-info/entry_points.txt +3 -0
  58. pyvisionect-0.1.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,460 @@
1
+ """The TCLV parameter table -- 235 entries, shipped as **data**.
2
+
3
+ Source: the v1 package's ``proto.paramTypes``
4
+ (``map[uint16]proto.paramType``, global @ ``0x26f5760``, built by
5
+ ``vss/proto.map.init.3`` from ``tclv-table.go``, ``makemap(235)``). The vendor
6
+ covers eleven hardware families with one code path by deriving nothing from the
7
+ model, so this is a lookup table and not a class hierarchy.
8
+
9
+ Three id banks:
10
+
11
+ * ``0..178`` main MCU (178 entries -- id 94 genuinely does not exist)
12
+ * ``1000..1022`` SCPU, the sensor / front-light co-processor
13
+ * ``1300..1303`` SCPU control commands
14
+ * ``2000..2025`` DPU, the display power unit
15
+ * ``2300..2303`` DPU control commands
16
+
17
+ The **same numeric id space** is used by the device's USB ASCII CLI -- its ~160
18
+ commands map 1:1 onto these ids. Only the *encoding* differs: USB speaks
19
+ ``<command> <args>`` text, the network speaks ``packet.ParamPayload`` TLVs.
20
+
21
+ ``network_writable``
22
+ --------------------
23
+
24
+ Eight ids are marked ``canWrite: false`` in the server's own admin-UI descriptor
25
+ table (``vss/data/admin/all.js``): the server can **read** them over the network
26
+ but will never write them. They are exactly the network/bootstrap
27
+ configuration, which is why USB provisioning is unavoidable -- you cannot tell a
28
+ sign about a new WiFi network over the network it does not have yet.
29
+ """
30
+
31
+ from __future__ import annotations
32
+
33
+ from dataclasses import dataclass
34
+
35
+ __all__ = [
36
+ "TclvEntry",
37
+ "TCLV",
38
+ "NETWORK_READ_ONLY",
39
+ "USB_HINTS",
40
+ "BANK_MCU",
41
+ "BANK_SCPU",
42
+ "BANK_DPU",
43
+ "lookup",
44
+ "name_of",
45
+ "check_writable",
46
+ "DEFAULT_VALUE_WIDTH",
47
+ "VALUE_WIDTHS",
48
+ "width_of",
49
+ ]
50
+
51
+ BANK_MCU = range(0, 179)
52
+ BANK_SCPU = range(1000, 1304)
53
+ BANK_DPU = range(2000, 2304)
54
+
55
+
56
+ @dataclass(frozen=True, slots=True)
57
+ class TclvEntry:
58
+ """One row of the vendor's TCLV table."""
59
+
60
+ id: int
61
+ name: str
62
+ """Verbatim from the binary's string table."""
63
+
64
+ network_writable: bool
65
+ """False for the eight ids the admin UI marks ``canWrite: false``."""
66
+
67
+ v1_set_handler: str | None = None
68
+ """Name of the v1 ``valueSet`` function, or None. Tells you the value's text form."""
69
+
70
+ v1_get_handler: str | None = None
71
+ """Name of the v1 ``valueHandler`` function, or None."""
72
+
73
+ @property
74
+ def bank(self) -> str:
75
+ if self.id in BANK_MCU:
76
+ return "mcu"
77
+ if self.id in BANK_SCPU:
78
+ return "scpu"
79
+ if self.id in BANK_DPU:
80
+ return "dpu"
81
+ return "unknown"
82
+
83
+
84
+ NETWORK_READ_ONLY: frozenset[int] = frozenset({2, 18, 19, 65, 66, 67, 68, 70})
85
+ """``canWrite: false`` in ``vss/data/admin/all.js``: CONN_TYPE, IPV4_SERVER_IP,
86
+ IPV4_SERVER_PORT, WIFI_SSID, WIFI_SECURITY, WIFI_PSK, WIFI_BAND, MOB_SECURITY."""
87
+
88
+ USB_HINTS: dict[int, str] = {
89
+ 2: "conn_type_set <type>",
90
+ 18: "server_tcp_set <ip|dns> <port>",
91
+ 19: "server_tcp_set <ip|dns> <port>",
92
+ 65: "wifi_ssid_set <ssid> (or wifi_conf_set <ssid> <psk> <security> <band>)",
93
+ 66: "wifi_security_set <none|wpa2|wpa2e> (or wifi_conf_set arg 3)",
94
+ 67: "wifi_psk_set <psk> (or wifi_conf_set arg 2)",
95
+ 68: "wifi_conf_set <ssid> <psk> <security> <band> (arg 4)",
96
+ 70: "mobile_conf_set <apn> <security> <user> <psk> <band> (arg 2)",
97
+ }
98
+ """The USB CLI command that *can* set each network-read-only id.
99
+
100
+ From the vendor CLI reference (docs.visionect.com PlaceAndPlay/DeviceConfiguration/CLI).
101
+ """
102
+
103
+ # Well-known ids worth naming in code rather than spelling as integers.
104
+ ID_TCLV_MAGIC = 0
105
+ ID_TCLV_VERSION = 1
106
+ ID_CONN_TYPE = 2
107
+ ID_IPV4_SERVER_IP = 18
108
+ ID_IPV4_SERVER_PORT = 19
109
+ ID_DISPLAY_TYPE = 28
110
+ ID_HEARTBEAT = 29
111
+ ID_CMD_FLASH_SAVE = 53
112
+ ID_WIFI_SSID = 65
113
+ ID_WIFI_SECURITY = 66
114
+ ID_WIFI_PSK = 67
115
+ ID_WIFI_BAND = 68
116
+ ID_SLEEP_MODE = 52
117
+ ID_GTIN = 108
118
+ ID_DEVICE_UUID = 89
119
+ ID_TLS_MODE = 145
120
+ ID_DISPLAY_WIDTH = 152
121
+ ID_DISPLAY_HEIGHT = 153
122
+
123
+ _ROWS: tuple[tuple[int, str, str | None, str | None], ...] = (
124
+ (0, 'TCLV Magic number', None, None),
125
+ (1, 'TCLV table version', None, None),
126
+ (2, 'Connectivity type', None, None),
127
+ (3, 'Wifi ACK or NACK timeout and Waiting for next block timeout', None, None),
128
+ (4, 'Wifi power saving timeout', None, None),
129
+ (5, 'WiFi DTIM skip interval in msec', None, None),
130
+ (6, 'Mobile ACK or NACK timeout and Waiting for next block timeout', None, None),
131
+ (7, 'Mobile power saving timeout', None, None),
132
+ (8, 'Ethernet MAC address', None, None),
133
+ (9, 'Ethernet TCP retry count', None, None),
134
+ (10, 'Ethernet TCP retry timeout [100ms]', None, None),
135
+ (11, 'Ethernet ACK or NACK timeout and Waiting for next block timeout', None, None),
136
+ (12, 'Ethernet power saving timeout', None, None),
137
+ (13, 'IPv4 static IP', None, None),
138
+ (14, 'IPv4 static Netmask', None, None),
139
+ (15, 'IPv4 static Gateway', None, None),
140
+ (16, 'IPv4 static DNS server', None, None),
141
+ (17, 'IPv4 mode: 0=Static IP, 1=DHCP', None, None),
142
+ (18, 'Server IP', None, None),
143
+ (19, 'Server port', 'u16ValueSet', None),
144
+ (20, 'VCOM of Display 0', 'u16ValueSet', None),
145
+ (21, 'VCOM of Display 1', 'u16ValueSet', None),
146
+ (22, 'VCOM of Display 2', 'u16ValueSet', None),
147
+ (23, 'VCOM of Display 3', 'u16ValueSet', None),
148
+ (24, 'VCOM of Display 4', 'u16ValueSet', None),
149
+ (25, 'VCOM of Display 5', 'u16ValueSet', None),
150
+ (26, 'VCOM of Display 6', 'u16ValueSet', None),
151
+ (27, 'VCOM of Display 7', 'u16ValueSet', None),
152
+ (28, 'Display Type', None, None),
153
+ (29, 'Heart beat interval', None, None),
154
+ (30, 'Network error retry interval', None, None),
155
+ (31, 'Proximity: offset calibration parameter', None, None),
156
+ (32, 'Proximity: threshold in %', None, None),
157
+ (33, 'Proximity: diode current in 10mA', None, None),
158
+ (34, 'Accelerometer threshold count', None, None),
159
+ (35, 'Accelerometer debounce count', None, None),
160
+ (36, 'Battery OFF threshold', 'u16ValueSet', None),
161
+ (37, 'Battery ON threshold', 'u16ValueSet', None),
162
+ (38, 'Battery threshold count', None, None),
163
+ (39, 'Front light map 0: PWM+LDR', 'tclvHandlerFlightSet', 'tclvHandlerFlightGet'),
164
+ (40, 'Front light map 1: PWM+LDR', 'tclvHandlerFlightSet', 'tclvHandlerFlightGet'),
165
+ (41, 'Front light map 2: PWM+LDR', 'tclvHandlerFlightSet', 'tclvHandlerFlightGet'),
166
+ (42, 'Front light map 3: PWM+LDR', 'tclvHandlerFlightSet', 'tclvHandlerFlightGet'),
167
+ (43, 'Front light map 4: PWM+LDR', 'tclvHandlerFlightSet', 'tclvHandlerFlightGet'),
168
+ (44, 'Front light map 5: PWM+LDR', 'tclvHandlerFlightSet', 'tclvHandlerFlightGet'),
169
+ (45, 'Front light map 6: PWM+LDR', 'tclvHandlerFlightSet', 'tclvHandlerFlightGet'),
170
+ (46, 'Front light map 7: PWM+LDR', 'tclvHandlerFlightSet', 'tclvHandlerFlightGet'),
171
+ (47, 'Front light threshold', None, None),
172
+ (48, 'Front light server control', None, None),
173
+ (49, 'System screens: 1=Battery, 2=Not connected, 3=Battery+Not connected', None, None),
174
+ (50, 'Touch mode: 0=OFF, 1=ON, 3=ON+Beep', None, None),
175
+ (51, 'Shipping mode: 0=OFF, 1=ON', None, None),
176
+ (52, 'Sleep mode disable: 0=Sleep mode enabled, 1=Sleep mode disabled', None, None),
177
+ (53, 'Command to save parameters to flash', None, None),
178
+ (54, 'Roaming mode: 0=Roaming disabled, 1=Roaming enabled', None, None),
179
+ (55, 'Roaming threshold in dBm', None, None),
180
+ (56, 'Roaming hysteresis in dBm', None, None),
181
+ (57, 'Writes EAP certificate chunk', None, None),
182
+ (58, 'Writes EAP certificate descriptor', None, None),
183
+ (59, 'Erases EAP certificate', None, None),
184
+ (60, 'Certificate entry 0', 'tclvStringValue', None),
185
+ (61, 'Certificate entry 1', 'tclvStringValue', None),
186
+ (62, 'Certificate entry 2', 'tclvStringValue', None),
187
+ (63, 'Certificate entry 3', 'tclvStringValue', None),
188
+ (64, 'Certificate entry 4', 'tclvStringValue', None),
189
+ (65, 'WiFi SSID', 'tclvStringValue', None),
190
+ (66, 'WiFi security mode', 'tclvStringValue', None),
191
+ (67, 'WiFi password', None, None),
192
+ (68, 'WiFi band: 0=dual, 1=2.4GHz, 2=5GHz', None, None),
193
+ (69, 'Mobile APN string', None, None),
194
+ (70, 'Mobile security mode', 'tclvStringValue', None),
195
+ (71, 'Mobile username', 'tclvStringValue', None),
196
+ (72, 'Mobile password', None, None),
197
+ (73, 'Mobile: not used. Set to 0', None, None),
198
+ (74, 'WiFi EAP method', 'tclvStringValue', None),
199
+ (75, 'Set WiFi EAP password', 'tclvStringValue', None),
200
+ (76, 'Set WiFi EAP username', 'tclvStringValue', None),
201
+ (77, 'Enable feature', None, None),
202
+ (78, 'Disable feature', None, None),
203
+ (79, 'Write: Play RTTTL song [text]. Read: play status: 0=Idle, 1=Playing', None, None),
204
+ (80, 'Force connection establish. Read requested connection status', None, None),
205
+ (81, 'Read connection status', None, None),
206
+ (82, 'Application name', None, None),
207
+ (83, 'Connectivity support: bit0=Wifi, bit1=Ethernet, bit2=Mobile', None, None),
208
+ (84, 'Connectivity drivers: see CLI command conn_type_list', None, None),
209
+ (85, 'Disable connectivity for N minutes', None, None),
210
+ (86, 'HW version: ID, Major, Minor, BOM', None, None),
211
+ (87, 'Application version: Major, Minor, Revision', None, None),
212
+ (88, 'Bootloader version: Major, Minor, Revision', None, None),
213
+ (89, 'Device UUID', None, None),
214
+ (90, 'Application ready status: 0:Not ready, 1:Ready', None, None),
215
+ (91, 'Reboot device, optional argument: 1 = upgrade, 0 = boot', None, None),
216
+ (92, 'Jump to application', None, None),
217
+ (93, 'Connectivity FW version', None, None),
218
+ (95, 'Touch FW version', None, None),
219
+ (96, 'If 1, device successfully sent status packet to server, 0 otherwise', None, None),
220
+ (97, 'Frontlight LDR filter coefficient', None, None),
221
+ (98, 'Frontlight PWM filter coefficient', None, None),
222
+ (99, 'Front light sensor timeout', None, None),
223
+ (100, 'Heater low temperature limit', None, None),
224
+ (101, 'Heater high temperature limit', None, None),
225
+ (102, 'Heater operation mode', None, None),
226
+ (103, 'Extension battery threshold. Extension powered off if battery voltage below this', None, None),
227
+ (104, 'Extension operation minimal temperature', None, None),
228
+ (105, 'Extension operation maximal temperature', None, None),
229
+ (106, 'Extension operation mode', None, None),
230
+ (107, 'Used (compiled) display type', None, None),
231
+ (108, 'GTIN', 'stringValueSet', None),
232
+ (109, 'EPD border mode: 0=server, 1=white, 2=black', None, None),
233
+ (110, 'WiFi MAC', None, None),
234
+ (111, 'T2S enable', None, None),
235
+ (112, 'T2S speech voice', 'u8ValueSet', None),
236
+ (113, 'T2S speech rate', 'u16ValueSet', None),
237
+ (114, 'T2S volume', 'u8ValueSet', None),
238
+ (115, 'T2S timeout', 'u8ValueSet', None),
239
+ (116, 'T2S speak', None, None),
240
+ (117, 'External battery used for battery screens (0 = disabled, 1 = enabled', None, None),
241
+ (118, 'EPD temperature limit mode', None, None),
242
+ (119, 'Temp high', 'u16ValueSet', None),
243
+ (120, 'Temp low', 'u16ValueSet', None),
244
+ (121, 'Displays preloaded local image', None, None),
245
+ (122, 'SNTP server address', None, None),
246
+ (123, 'SNTP server port', None, None),
247
+ (124, 'HTP server URL', None, None),
248
+ (125, 'HTP server port', None, None),
249
+ (126, 'Sets CLI password', None, None),
250
+ (127, 'Resets CLI password and all security related settings', None, None),
251
+ (128, 'CLI login', None, None),
252
+ (129, 'CLI security state: 1:unlocked 0:locked', None, None),
253
+ (130, 'Outbound encryption: 0=Disabled, 1=Enabled', None, None),
254
+ (131, 'Encryption key', None, None),
255
+ (132, 'Mobile connection IMEI', None, None),
256
+ (133, 'Executes application upgrade', None, None),
257
+ (134, 'T2S button 1 text', 'string128ValueSet', None),
258
+ (135, 'T2S button 2 text', 'string128ValueSet', None),
259
+ (136, 'T2S button 3 text', 'string128ValueSet', None),
260
+ (137, 'T2S button 4 text', 'string128ValueSet', None),
261
+ (138, 'BLE MAC', None, None),
262
+ (139, 'Performs WiFi scan', None, None),
263
+ (140, 'BLE advertising data', None, None),
264
+ (141, 'MPPT: VFB voltage [mV]', None, None),
265
+ (142, 'MPPT: MPPT voltage [mV]', None, None),
266
+ (143, 'Executes WiFi module upgrade', None, None),
267
+ (144, 'Set WiFi region: 0=Default, 1=US, 2=EUROPE, 3=JAPAN', None, None),
268
+ (145, 'TLS mode: 0=disabled, 1=TLS 1.3', None, None),
269
+ (146, 'EPD count', None, None),
270
+ (147, 'Panel orientation: 0=Portrait, 1=Landscape', None, None),
271
+ (148, 'Panel alignment: 0=Vertical, 1=Horizontal', None, None),
272
+ (149, 'Panel rotation: 0=No rotation, 1=180deg rotation', None, None),
273
+ (150, 'Panel update order: 0=Ascending, 1=Descending', None, None),
274
+ (151, 'Restart JS engine', None, None),
275
+ (152, 'Display width in pixels', None, None),
276
+ (153, 'Display height in pixels', None, None),
277
+ (154, 'Mobile preferred mode: 0=Disabled, 2=Auto, 38=LTE only,...', None, None),
278
+ (155, 'BLE mode: 0=Disabled, 1=Enabled', None, None),
279
+ (156, 'EPD temperature', None, None),
280
+ (157, 'Format the file system', None, None),
281
+ (158, 'Reads the 16-byte wall-mount ID', None, None),
282
+ (159, 'Sets the PoE wall-mount LEDs', None, None),
283
+ (160, 'JS engine status', None, None),
284
+ (161, 'Flushes the syslog to the file system', None, None),
285
+ (162, 'Halt JS app execution', None, None),
286
+ (163, 'Sends device to sleep mode.', None, None),
287
+ (164, 'JSE eval', 'stringValueSet', None),
288
+ (165, 'Reads Wall-mount HW version: ID, Major, Minor, BOM', None, None),
289
+ (166, 'Changes the server URL and/or port: [Server URL]:[Server port]', 'stringValueSet', None),
290
+ (167, 'Connectivity link type: 0=None, 1=WiFi, 2=Mobile, 3=Ethernet', None, None),
291
+ (168, 'Executes JS application patch upgrade', None, None),
292
+ (169, 'Cleans the file system of any previous JS upgrades', None, None),
293
+ (170, 'Read BSSID of the currently connected AP', 'tclvStringValue', None),
294
+ (171, 'Set M2M mode for N minutes (0 to disable) or read remaining M2M time in minutes', None, None),
295
+ (172, 'Sets battery charging mode: 0 = Normal (default), 1 = Charging disabled', None, None),
296
+ (173, 'Set WiFi mode: 0=Default, 1=Disable broadcast filtering 2=enable Enhanced max PSP mode, 3=Disable broadcast+enable Enhanced max PSP', None, None),
297
+ (174, 'Opens a file for reading [filename]:[r] or writing [filename]:[w]', 'stringValueSet', None),
298
+ (175, 'Reads/writes file data', 'stringValueSet', 'tclvStringValue'),
299
+ (176, 'Closes an opened file', None, None),
300
+ (177, 'Returns a S-box hash over a file content and size of a file specified with [filename]', 'stringValueSet', None),
301
+ (178, 'Removes a file from the file system specified with [filename]', 'stringValueSet', None),
302
+ (1000, 'TCLV table version', None, None),
303
+ (1001, 'TCLV SCPU Frontlight Mode', None, None),
304
+ (1002, 'SCPU Front light map 0: PWM+LDR', 'tclvHandlerFlightSet', 'tclvHandlerFlightGet'),
305
+ (1003, 'SCPU Front light map 1: PWM+LDR', 'tclvHandlerFlightSet', 'tclvHandlerFlightGet'),
306
+ (1004, 'SCPU Front light map 2: PWM+LDR', 'tclvHandlerFlightSet', 'tclvHandlerFlightGet'),
307
+ (1005, 'SCPU Front light map 3: PWM+LDR', 'tclvHandlerFlightSet', 'tclvHandlerFlightGet'),
308
+ (1006, 'SCPU Front light map 4: PWM+LDR', 'tclvHandlerFlightSet', 'tclvHandlerFlightGet'),
309
+ (1007, 'SCPU Front light map 5: PWM+LDR', 'tclvHandlerFlightSet', 'tclvHandlerFlightGet'),
310
+ (1008, 'SCPU Front light map 6: PWM+LDR', 'tclvHandlerFlightSet', 'tclvHandlerFlightGet'),
311
+ (1009, 'SCPU Front light map 7: PWM+LDR', 'tclvHandlerFlightSet', 'tclvHandlerFlightGet'),
312
+ (1010, 'SCPU Frontlight PWM frequency in Hz', 'u16ValueSet', None),
313
+ (1011, 'SCPU Frontlight samplerate in sec', 'u16ValueSet', None),
314
+ (1012, 'SCPU Frontlight prefilter [0 .. 100]', 'u16ValueSet', None),
315
+ (1013, 'SCPU Frontlight postfilter [0 .. 100]', 'u16ValueSet', None),
316
+ (1014, 'TCLV SCPU Frontlight sensor timeout in sec', None, None),
317
+ (1015, 'TCLV SCPU Heater Mode', None, None),
318
+ (1016, 'SCPU Heater OFF temperature in °C', 'u16ValueSet', None),
319
+ (1017, 'SCPU Heater ON temperature in °C', 'u16ValueSet', None),
320
+ (1018, 'TCLV SCPU Device Mode', None, None),
321
+ (1019, 'SCPU Minimal OFF temperature in °C', 'u16ValueSet', None),
322
+ (1020, 'SCPU Maximal OFF temperature in °C', 'u16ValueSet', None),
323
+ (1021, 'TCLV SCPU Battery threshold in mV', None, None),
324
+ (1022, 'SCPU Frontlight PWM limit in %', 'u16ValueSet', None),
325
+ (1300, 'Command to push parameters to SCPU', None, None),
326
+ (1301, 'Command to pull parameters from SCPU', None, None),
327
+ (1302, 'Command to save parameters to SCPU', None, None),
328
+ (1303, 'Reboots the SCPU', None, None),
329
+ (2000, 'TCLV table version', None, None),
330
+ (2001, 'TCLV DPU mode', None, None),
331
+ (2002, 'TCLV DPU VSPOS rail voltage in mV', None, None),
332
+ (2003, 'TCLV DPU VSNEG rail voltage in mV', None, None),
333
+ (2004, 'TCLV DPU VGPOS rail voltage in mV', None, None),
334
+ (2005, 'TCLV DPU VGNEG rail voltage in mV', None, None),
335
+ (2006, 'TCLV DPU VCOM1 rail voltage in mV', None, None),
336
+ (2007, 'TCLV DPU VCOM2 rail voltage in mV', None, None),
337
+ (2008, 'TCLV DPU VCOM3 rail voltage in mV', None, None),
338
+ (2009, 'TCLV DPU VCOM4 rail voltage in mV', None, None),
339
+ (2010, 'TCLV DPU sequence 0 ON: delay in ms + rail ID', None, None),
340
+ (2011, 'TCLV DPU sequence 1 ON: delay in ms + rail ID', None, None),
341
+ (2012, 'TCLV DPU sequence 2 ON: delay in ms + rail ID', None, None),
342
+ (2013, 'TCLV DPU sequence 3 ON: delay in ms + rail ID', None, None),
343
+ (2014, 'TCLV DPU sequence 4 ON: delay in ms + rail ID', None, None),
344
+ (2015, 'TCLV DPU sequence 5 ON: delay in ms + rail ID', None, None),
345
+ (2016, 'TCLV DPU sequence 6 ON: delay in ms + rail ID', None, None),
346
+ (2017, 'TCLV DPU sequence 7 ON: delay in ms + rail ID', None, None),
347
+ (2018, 'TCLV DPU sequence 0 OFF: delay in ms + rail ID', None, None),
348
+ (2019, 'TCLV DPU sequence 1 OFF: delay in ms + rail ID', None, None),
349
+ (2020, 'TCLV DPU sequence 2 OFF: delay in ms + rail ID', None, None),
350
+ (2021, 'TCLV DPU sequence 3 OFF: delay in ms + rail ID', None, None),
351
+ (2022, 'TCLV DPU sequence 4 OFF: delay in ms + rail ID', None, None),
352
+ (2023, 'TCLV DPU sequence 5 OFF: delay in ms + rail ID', None, None),
353
+ (2024, 'TCLV DPU sequence 6 OFF: delay in ms + rail ID', None, None),
354
+ (2025, 'TCLV DPU sequence 7 OFF: delay in ms + rail ID', None, None),
355
+ (2300, 'Command to push parameters to SCPU', None, None),
356
+ (2301, 'Command to pull parameters from SCPU', None, None),
357
+ (2302, 'Command to save parameters to SCPU', None, None),
358
+ (2303, 'Reboots the SCPU', None, None),
359
+ )
360
+
361
+ TCLV: dict[int, TclvEntry] = {
362
+ pid: TclvEntry(
363
+ id=pid,
364
+ name=name,
365
+ network_writable=pid not in NETWORK_READ_ONLY,
366
+ v1_set_handler=setter,
367
+ v1_get_handler=getter,
368
+ )
369
+ for pid, name, setter, getter in _ROWS
370
+ }
371
+
372
+ assert len(TCLV) == 235, f"the vendor table has 235 entries, got {len(TCLV)}"
373
+
374
+
375
+ def lookup(param_id: int) -> TclvEntry | None:
376
+ """Return the table row for *param_id*, or None if it is not a known id."""
377
+ return TCLV.get(param_id)
378
+
379
+
380
+ def name_of(param_id: int) -> str:
381
+ """Human name for *param_id*, or ``"unknown(<id>)"``."""
382
+ entry = TCLV.get(param_id)
383
+ return entry.name if entry else f"unknown({param_id})"
384
+
385
+
386
+ def check_writable(param_id: int) -> None:
387
+ """Raise :class:`~pyvisionect.wire.errors.ReadOnlyParameter` if a network write is futile.
388
+
389
+ The eight network-read-only ids are the ones a first-time provisioning
390
+ actually needs, so the error names the USB command that can do the job.
391
+ """
392
+ from ..wire.errors import ReadOnlyParameter
393
+
394
+ if param_id in NETWORK_READ_ONLY:
395
+ raise ReadOnlyParameter(
396
+ param_id, name_of(param_id), USB_HINTS.get(param_id, "see the USB CLI reference")
397
+ )
398
+
399
+ DEFAULT_VALUE_WIDTH = 4
400
+ """Bytes to use for an integer write to a parameter of unmeasured width.
401
+
402
+ Four, because the parameter channel's docstring records the vendor convention
403
+ as "a uint32 for numeric keys", and because the device **rejects a write whose
404
+ value is the wrong width** -- with its own error code, distinct from the one it
405
+ gives for an id it does not implement (see :data:`VALUE_WIDTHS`).
406
+ """
407
+
408
+ VALUE_WIDTHS: dict[int, int] = {
409
+ # Measured on a live 31.2" Place&Play (firmware 7.4.4407) by reading each
410
+ # id back and recording the Length the device itself put on the wire.
411
+ # These are **not** from the vendor table, which carries no width column.
412
+ 0: 4, # TCLV magic (efbeadde)
413
+ 1: 4, # TCLV table version
414
+ 2: 4, # Connectivity type
415
+ 3: 4, # Wifi ACK/NACK timeout
416
+ 4: 4, # Wifi power saving timeout
417
+ 5: 4, # WiFi DTIM skip interval
418
+ 9: 1, # Ethernet TCP retry count
419
+ 10: 2, # Ethernet TCP retry timeout
420
+ 17: 4, # IPv4 mode
421
+ 19: 2, # Server port (692b = 11113)
422
+ 22: 2, # VCOM of display 2
423
+ 27: 2, # VCOM of display 7
424
+ 28: 4, # Display type
425
+ 29: 4, # Heart beat interval
426
+ 52: 4, # Sleep mode disable
427
+ 53: 1, # flash_save -- command-shaped, and one byte is what the device
428
+ # has been accepting from this library all along.
429
+ 68: 4, # WiFi band
430
+ 130: 4, # Outbound encryption
431
+ 144: 4, # WiFi region
432
+ 152: 4, # Display width
433
+ 153: 4, # Display height
434
+ 154: 4, # Mobile preferred mode
435
+ 155: 4, # BLE mode
436
+ 156: 2, # EPD temperature
437
+ }
438
+ """id -> value width in bytes, as measured from the device's own read replies.
439
+
440
+ Widths are **per parameter** and cannot be inferred from the value: the
441
+ heartbeat is a uint32 that is normally 1, the server port is a uint16 that is
442
+ normally 11113, and the Ethernet retry count is a single byte. Guessing the
443
+ narrowest type that fits -- which this library used to do -- produces a
444
+ one-byte write to the heartbeat, and the device answers that with a write
445
+ error. Nothing in the vendor's parameter table records a width, so this had to
446
+ be measured.
447
+
448
+ Ids absent here fall back to :data:`DEFAULT_VALUE_WIDTH`. Some of those are
449
+ certainly wrong -- the VCOM block at 20..27 is two bytes and only two of its
450
+ entries were measured -- so an unexpected write error on an id not listed here
451
+ is the first thing to suspect.
452
+ """
453
+
454
+
455
+ def width_of(param_id: int) -> int:
456
+ """Value width in bytes for an integer write to *param_id*.
457
+
458
+ :data:`DEFAULT_VALUE_WIDTH` for an id whose width has not been measured.
459
+ """
460
+ return VALUE_WIDTHS.get(param_id, DEFAULT_VALUE_WIDTH)
@@ -0,0 +1,175 @@
1
+ # `pyvisionect.imaging`
2
+
3
+ The whole pixel pipeline for a Visionect e-ink sign. Pure functions; no sockets, no
4
+ clock, no global state. Needs only **numpy** and **Pillow** (`pip install
5
+ pyvisionect[imaging]`).
6
+
7
+ ```python
8
+ from pyvisionect.devices import panel_for
9
+ from pyvisionect.imaging import Dithering, encode_frame
10
+
11
+ frame = encode_frame(
12
+ pil_image, # 1440x2560 for the 32" sign
13
+ panel=panel_for(display_type), # or imaging.PANEL_32INCH
14
+ encoding=4, # 4 bpp / 16 greys
15
+ dithering=Dithering.BLUE_NOISE,
16
+ )
17
+ # frame.rectangles -> list[EncodedRect]: x, y, w, h, screen_id, options, data
18
+ # frame.state_checksum -> ImageHeader.Checksum
19
+ # frame.state -> pass back as prev_state next time
20
+ ```
21
+
22
+ ## Why the library owns all of this
23
+
24
+ The device does **waveform drive and nothing else**. It receives data that is already
25
+ greyscale-reduced and already bit-packed, so every decision about how the sign looks is
26
+ made here. There is no "let the panel dither it" option.
27
+
28
+ ```
29
+ grey8 -> (Beautify) -> change-detect -> rect list -> merge/limit(<=15)
30
+ -> align to 16-bit quanta -> crop/rotate per display -> dither
31
+ -> bit-pack 1bpp/4bpp -> per-display interlace
32
+ ```
33
+
34
+ ## Encodings
35
+
36
+ Two exist. Nothing else is legal anywhere in the vendor's code.
37
+
38
+ | `Encoding` | bpp | levels | output ramp | alignment quantum |
39
+ |---|---|---|---|---|
40
+ | `1` | 1 | 2 | `0`, `255` | 16 sub-pixels |
41
+ | `4` | 4 | 16 | `n * 17` | 4 sub-pixels |
42
+
43
+ * 4 bpp: the **even** pixel goes in the **low** nibble, and the nibble is the top 4 bits
44
+ of the 8-bit grey (truncation, not rounding).
45
+ * 1 bpp: **MSB-first**, hard threshold at `>= 0x80`.
46
+ * **`stride == width`, zero row padding.** The pack runs linearly across row
47
+ boundaries, which is why the alignment rule is on `width * height`, not on width.
48
+ Payload is exactly `W*H/2` or `W*H/8`.
49
+
50
+ ## Dithering
51
+
52
+ | value | name | notes |
53
+ |---|---|---|
54
+ | `0` | `default` | **invalid at the encoder** -- raises |
55
+ | `1` | `none` | top-nibble truncation (4 bpp) / MSB threshold (1 bpp) |
56
+ | `2` | `bayer` | **bi-level only** -- warns at 4 bpp |
57
+ | `3` | `floyd-steinberg` | error diffusion onto the uniform ramp |
58
+ | `4` | `blue-noise` | **our extension, not the vendor's** |
59
+
60
+ **`4` is safe to invent because the dithering mode never appears on the wire.** The
61
+ device gets pre-quantised bits; the number is a server-side knob and we replace the
62
+ server. `1`-`3` keep the vendor's meanings for compatibility.
63
+
64
+ ### Prefer blue noise at 4 bpp
65
+
66
+ * `bayer` is bi-level: GraphicsMagick's `OrderedDitherImage()` takes no level
67
+ parameter, so a 4 bpp bayer rectangle throws away 14 of the 16 greys the panel can
68
+ show. We reproduce that (with a warning) rather than silently invent a 16-level
69
+ "bayer". Pass `dither_levels=16` to opt into a multi-level ordered dither.
70
+ * `floyd-steinberg` is **spatially unstable**. Error diffuses across the rest of the
71
+ image, so a one-word text change dirties far more than the edit. Measured on a
72
+ 256x256 test image with a 16x16 (256 px) edit:
73
+
74
+ | mode | dirty pixels | dirty bounding box |
75
+ |---|---|---|
76
+ | `none` | 256 | 256 |
77
+ | `bayer` | 126 | 256 |
78
+ | `blue-noise` | 256 | 256 |
79
+ | `floyd-steinberg` | **1077** | **20592** |
80
+
81
+ That 80x bounding-box inflation feeds straight into change detection: more
82
+ rectangles, more pressure on the 15-region limit, more panel flashing.
83
+ * `blue-noise` gets ordered-dither stability **without** Bayer's cross-hatch. The
84
+ 64x64 matrix is generated by void-and-cluster (Ulichney, sigma 1.5, fixed seed) and
85
+ **committed** as `data/blue_noise_64.npy`, so output is reproducible across runs and
86
+ machines. Regenerate with `tools/gen_blue_noise.py`.
87
+
88
+ Pass `blue_noise_matrix=` to use your own matrix -- e.g. the exact one your renderer
89
+ already uses -- and get identical pixels on both sides.
90
+
91
+ ### Ordered dithers tile in canvas coordinates
92
+
93
+ `none`, `bayer` and `blue-noise` are pixel-local, so they are applied once over the
94
+ whole session canvas with the matrix phased on the **absolute** canvas coordinate. Two
95
+ partial updates that abut therefore produce exactly the pixels one combined update
96
+ would have -- no seam. `floyd-steinberg` cannot work that way and is run per rectangle
97
+ in display-local space, which is where the vendor runs it.
98
+
99
+ ### If your renderer already dithered
100
+
101
+ Use `dithering=1` (`none`). It is a bit-for-bit identity on content already on the
102
+ `n * 17` ramp, because `(n * 17) >> 4 == n`. That is how the live session is driven.
103
+
104
+ ## The 32" sign
105
+
106
+ The device has **two physical 2880x640 channels**; the server models **four logical
107
+ 1440x640 displays stacked vertically** (canvas 1440x2560) and folds them back into two
108
+ on the wire by interleaving each pair at **4-pixel granularity**.
109
+
110
+ ```
111
+ ScreenID 0 <- interlace(band 0, band 1)
112
+ ScreenID 1 <- interlace(band 3, band 2) <-- lanes SWAPPED
113
+ ```
114
+
115
+ The driver is `eink-flip`: each 1440-wide band is **horizontally mirrored** before
116
+ packing. Get the mirror or the swap wrong and the sign shows a mirrored or scrambled
117
+ image. Both are verified byte-exactly against captured traffic.
118
+
119
+ Consequence: **every push `encode_frame` produces for this hardware is full-screen.**
120
+ `getRectangleSupport` returns false unconditionally for it, and the interlacer needs all
121
+ four full-size rectangles, so a partial rectangle in *canvas* coordinates cannot be sent.
122
+ `encode_frame` enforces this (`Panel.forces_full_screen`).
123
+
124
+ The device is not the limit, though. A rectangle addressed in **screen** coordinates
125
+ never enters the fold, and the sign accepts those: measured on 2026-10-05, acked, drawn
126
+ only where addressed, checksum echoed back. There is no screen-space encoder here yet —
127
+ see `OPEN-QUESTIONS.md` A10 for what one needs to do.
128
+
129
+ ## The state checksum
130
+
131
+ `ImageHeader.Checksum` is **XXHash32, seed 0, over the raw 8-bit state image**, with a
132
+ result of `0` remapped to `1`. It is *not* a CRC (transport checksums are CRC-32/IEEE)
133
+ and *not* over the encoded data.
134
+
135
+ The device stores the tag of the last image it applied and echoes it as
136
+ `DisplayStateCRC`. Send `frame.state_checksum` in every `ImagePacket` and keep
137
+ `frame.state` for the next call. A mismatch costs one redundant full-screen redraw --
138
+ a quality bug, not a hard failure.
139
+
140
+ `xxhash` (a core dependency) is used when importable; a pure-Python XXH32 is included
141
+ so `imaging/` works without it, and the test suite checks the two against each other.
142
+
143
+ ## Inverse (ghost-clearing) updates
144
+
145
+ `encode_frame(..., inverse=True)` **clears** `RectangleHeader.Options` bit `0x0002` on
146
+ every rectangle of one full-screen frame. Clear means inverse; set means an ordinary
147
+ update.
148
+
149
+ **Verified on hardware**, by A/B on the live sign: `options=0` makes the firmware log
150
+ `inv: 1` and `Force Inverse and full area update`, `options=2` makes it log `inv: 0` with
151
+ no such line (`ImgOpt=0x00003024` against `0x00000124`). The vendor's admin UI writes the
152
+ same key from its "Inverse updates" dropdown, where `0` is "Enable" and `2` is "Disable".
153
+
154
+ So with the vendor's shipped `RectangleFlags = 0` the bit is **already clear and every
155
+ full-screen push inverts.** `inverse=True` is therefore a no-op on a default
156
+ configuration; pass `rect_options` with bit 1 set to get ordinary updates, and clear it
157
+ again for the pushes you want inverted.
158
+
159
+ ## What is verified against real device bytes
160
+
161
+ `tests/imaging/test_golden_capture.py` replays the 1.84 MB image push captured from the
162
+ live sign and reproduces **both 2880x640 payloads byte-for-byte** plus
163
+ `ImageHeader.Checksum == 3741864387` -- the value the device itself echoed back. One
164
+ test pins down the nibble order, the ramp, the linear packing, the interlace
165
+ granularity, the screen-1 lane swap, the mirror, the band order and the hash at once.
166
+
167
+ Not verified against hardware: display rotations 1/2/3 (self-consistency only, our sign
168
+ runs rotation 0), interlacing mode 1 (hardware revision 1.0.0 -- raises rather than
169
+ guess), colour-mask drivers (not implemented), and `Beautify`'s exact shift term.
170
+
171
+ **Not bit-exact to GraphicsMagick**, and not claimed to be: `bayer`'s matrix and
172
+ `floyd-steinberg`'s error weights are our own. GM's `QuantizeImage` also derives its
173
+ 16-colour palette from the image histogram, which the packer then truncates to nibbles;
174
+ we quantise to the uniform ramp the wire format actually carries. No GM output was
175
+ available to diff against.