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.
- pyvisionect/__init__.py +120 -0
- pyvisionect/devices/__init__.py +92 -0
- pyvisionect/devices/enums.py +403 -0
- pyvisionect/devices/panels.py +242 -0
- pyvisionect/devices/tclv.py +460 -0
- pyvisionect/imaging/README.md +175 -0
- pyvisionect/imaging/__init__.py +181 -0
- pyvisionect/imaging/checksum.py +114 -0
- pyvisionect/imaging/constants.py +131 -0
- pyvisionect/imaging/data/blue_noise_64.npy +0 -0
- pyvisionect/imaging/decode.py +172 -0
- pyvisionect/imaging/dither.py +357 -0
- pyvisionect/imaging/encoder.py +594 -0
- pyvisionect/imaging/geometry.py +129 -0
- pyvisionect/imaging/grey.py +104 -0
- pyvisionect/imaging/interlace.py +244 -0
- pyvisionect/imaging/pack.py +142 -0
- pyvisionect/imaging/panel.py +339 -0
- pyvisionect/imaging/partial.py +931 -0
- pyvisionect/imaging/rects.py +466 -0
- pyvisionect/io/__init__.py +33 -0
- pyvisionect/io/tcp.py +795 -0
- pyvisionect/io/usb/__init__.py +237 -0
- pyvisionect/io/usb/cli.py +278 -0
- pyvisionect/io/usb/commands.py +781 -0
- pyvisionect/io/usb/console.py +730 -0
- pyvisionect/io/usb/device.py +914 -0
- pyvisionect/io/usb/discovery.py +260 -0
- pyvisionect/io/usb/encryption.py +262 -0
- pyvisionect/io/usb/errors.py +175 -0
- pyvisionect/io/usb/fake.py +292 -0
- pyvisionect/io/usb/parsers.py +1464 -0
- pyvisionect/io/usb/provisioning.py +502 -0
- pyvisionect/packets/__init__.py +135 -0
- pyvisionect/packets/control.py +95 -0
- pyvisionect/packets/file.py +325 -0
- pyvisionect/packets/image.py +234 -0
- pyvisionect/packets/misc.py +202 -0
- pyvisionect/packets/param.py +284 -0
- pyvisionect/packets/status.py +518 -0
- pyvisionect/packets/stored.py +217 -0
- pyvisionect/py.typed +0 -0
- pyvisionect/session/__init__.py +100 -0
- pyvisionect/session/connection.py +1043 -0
- pyvisionect/session/device.py +587 -0
- pyvisionect/session/events.py +196 -0
- pyvisionect/session/filetransfer.py +251 -0
- pyvisionect/session/pending.py +425 -0
- pyvisionect/wire/__init__.py +91 -0
- pyvisionect/wire/blocks.py +350 -0
- pyvisionect/wire/checksum.py +115 -0
- pyvisionect/wire/errors.py +176 -0
- pyvisionect/wire/framing.py +334 -0
- pyvisionect-0.1.0.dist-info/METADATA +1030 -0
- pyvisionect-0.1.0.dist-info/RECORD +58 -0
- pyvisionect-0.1.0.dist-info/WHEEL +4 -0
- pyvisionect-0.1.0.dist-info/entry_points.txt +3 -0
- pyvisionect-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
"""Panel / display geometry and driver capability tables.
|
|
2
|
+
|
|
3
|
+
.. note::
|
|
4
|
+
These dataclasses are defined here so that ``imaging/`` stays importable
|
|
5
|
+
with nothing but numpy and Pillow -- no dependency on
|
|
6
|
+
:mod:`pyvisionect.devices`, :mod:`pyvisionect.wire` or
|
|
7
|
+
:mod:`pyvisionect.session`.
|
|
8
|
+
|
|
9
|
+
:mod:`pyvisionect.devices.panels` defines its own ``Panel``/``Driver`` for
|
|
10
|
+
the capability tables. :meth:`Panel.adapt` accepts those (or anything else
|
|
11
|
+
exposing ``width``/``height``/``displays`` plus a ``driver`` name or a
|
|
12
|
+
``driver_spec``), so callers can pass ``devices.panel_for(display_type)``
|
|
13
|
+
straight into :func:`pyvisionect.imaging.encode_frame` and this module never
|
|
14
|
+
has to import it.
|
|
15
|
+
|
|
16
|
+
Spec references are to ``artifacts/visionect/02-imaging-framebuffer.md``.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
from dataclasses import dataclass, field
|
|
22
|
+
from typing import Any, Mapping
|
|
23
|
+
|
|
24
|
+
__all__ = ["Driver", "Panel", "DRIVERS", "PANEL_32INCH", "DisplayGeometry"]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass(frozen=True)
|
|
28
|
+
class Driver:
|
|
29
|
+
"""The *entire* per-device pixel-path variability -- spec §1.6.
|
|
30
|
+
|
|
31
|
+
The vendor registers five drivers; they differ only in two booleans, which
|
|
32
|
+
come straight out of each driver's ``Settings()`` map:
|
|
33
|
+
|
|
34
|
+
=============================== ======== ==========
|
|
35
|
+
``Name()`` Mirroring Color
|
|
36
|
+
=============================== ======== ==========
|
|
37
|
+
``eink-generic`` false false
|
|
38
|
+
``eink-flip`` **true** false
|
|
39
|
+
``pl-generic`` false false
|
|
40
|
+
``eink-32-inch-color-mask`` false true
|
|
41
|
+
``eink-32-inch-color-mask-flip`` **true** true
|
|
42
|
+
=============================== ======== ==========
|
|
43
|
+
|
|
44
|
+
``eInkFlip`` is literally ``eInkGeneric`` wrapped so that the four ops
|
|
45
|
+
``image-encode``, ``image-decode``, ``rectangle-encode`` and
|
|
46
|
+
``rectangle-decode`` apply a horizontal flip (``imgproc.CvFlip``) --
|
|
47
|
+
``eink-flip.go:17/167/176``.
|
|
48
|
+
|
|
49
|
+
:param mirror: horizontally mirror each display's image before encoding.
|
|
50
|
+
:param color_mask: colour-mask panel (palette remap via ``GmMapImage``).
|
|
51
|
+
**Not implemented** -- the grey path ignores it; passing ``True``
|
|
52
|
+
raises from :func:`pyvisionect.imaging.encode_frame`.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
mirror: bool = False
|
|
56
|
+
color_mask: bool = False
|
|
57
|
+
name: str = ""
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
#: Vendor driver registry (``vss/pkg/driver/driver.go:46-59``). Lookup falls
|
|
61
|
+
#: back to ``eink-generic`` for ``""`` and ``"unknown"``
|
|
62
|
+
#: (``common.Display.GetDriver``, ``display-translations.go:54-58``).
|
|
63
|
+
DRIVERS: Mapping[str, Driver] = {
|
|
64
|
+
"eink-generic": Driver(mirror=False, color_mask=False, name="eink-generic"),
|
|
65
|
+
"eink-flip": Driver(mirror=True, color_mask=False, name="eink-flip"),
|
|
66
|
+
"pl-generic": Driver(mirror=False, color_mask=False, name="pl-generic"),
|
|
67
|
+
"eink-32-inch-color-mask": Driver(
|
|
68
|
+
mirror=False, color_mask=True, name="eink-32-inch-color-mask"
|
|
69
|
+
),
|
|
70
|
+
"eink-32-inch-color-mask-flip": Driver(
|
|
71
|
+
mirror=True, color_mask=True, name="eink-32-inch-color-mask-flip"
|
|
72
|
+
),
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def resolve_driver(driver: Driver | str | None) -> Driver:
|
|
77
|
+
"""Accept a :class:`Driver`, a vendor driver name, ``None`` or ``"unknown"``.
|
|
78
|
+
|
|
79
|
+
Unknown names fall back to ``eink-generic``, exactly as ``driver.Get``
|
|
80
|
+
does (``driver.go:53-59``).
|
|
81
|
+
"""
|
|
82
|
+
if isinstance(driver, Driver):
|
|
83
|
+
return driver
|
|
84
|
+
if not driver or driver == "unknown":
|
|
85
|
+
return DRIVERS["eink-generic"]
|
|
86
|
+
return DRIVERS.get(driver, DRIVERS["eink-generic"])
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@dataclass(frozen=True)
|
|
90
|
+
class DisplayGeometry:
|
|
91
|
+
"""One *logical* display's place in the session canvas -- ``common.Display``."""
|
|
92
|
+
|
|
93
|
+
id: int
|
|
94
|
+
x: int
|
|
95
|
+
y: int
|
|
96
|
+
width: int
|
|
97
|
+
height: int
|
|
98
|
+
rotation: int = 0
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
def rotated_width(self) -> int:
|
|
102
|
+
"""``Display.DimensionsRotated()`` -- ``display-translations.go:62``."""
|
|
103
|
+
return self.height if self.rotation in (1, 3) else self.width
|
|
104
|
+
|
|
105
|
+
@property
|
|
106
|
+
def rotated_height(self) -> int:
|
|
107
|
+
return self.width if self.rotation in (1, 3) else self.height
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@dataclass(frozen=True)
|
|
111
|
+
class Panel:
|
|
112
|
+
"""A panel's logical geometry, as the *server* models it.
|
|
113
|
+
|
|
114
|
+
The numbers here are the **post-** ``SetupDisplaysType`` values, not the
|
|
115
|
+
device's own ``DisplayWidth``/``DisplayHeight`` status fields. For the 32"
|
|
116
|
+
sign the device reports ``2880 x 640`` with ``NumSupportedDisplays = 2``,
|
|
117
|
+
and ``device-config/config.go:262`` rewrites that into **4 logical
|
|
118
|
+
displays of 1440 x 640**, stacked vertically (spec §1.5). The two physical
|
|
119
|
+
2880-wide panel channels are then rebuilt on the wire by the interlacer
|
|
120
|
+
(spec §1.6, :mod:`pyvisionect.imaging.interlace`).
|
|
121
|
+
|
|
122
|
+
:param width: one logical display's width in pixels.
|
|
123
|
+
:param height: one logical display's height in pixels.
|
|
124
|
+
:param displays: number of logical displays, stacked vertically.
|
|
125
|
+
:param driver: a :class:`Driver`, or a vendor driver name string.
|
|
126
|
+
:param rotation: ``common.DisplayRotation`` 0/1/2/3 == 0/90/180/270,
|
|
127
|
+
applied to every display. Only ``0`` is verified against real captured
|
|
128
|
+
traffic; 1/2/3 implement §1.5's formulas but are untested on hardware.
|
|
129
|
+
:param interlace: transmit-side interlacing mode (``getInterlacingMode``,
|
|
130
|
+
``image_interlacing.go:92``). ``None`` means *auto*: mode ``2`` when
|
|
131
|
+
``displays == 4``, else ``0`` (no interlacing). That equivalence holds
|
|
132
|
+
because ``SetupDisplaysType`` only ever produces 4 displays for
|
|
133
|
+
``HardwareNameID == 8``, which is exactly the hardware
|
|
134
|
+
``getInterlacingMode`` returns non-zero for. Pass an explicit value to
|
|
135
|
+
override (``1`` is hardware revision 1.0.0 and is **not implemented** --
|
|
136
|
+
its pairing was not recovered).
|
|
137
|
+
"""
|
|
138
|
+
|
|
139
|
+
width: int
|
|
140
|
+
height: int
|
|
141
|
+
displays: int
|
|
142
|
+
driver: Driver | str = field(default_factory=lambda: DRIVERS["eink-generic"])
|
|
143
|
+
rotation: int = 0
|
|
144
|
+
interlace: int | None = None
|
|
145
|
+
|
|
146
|
+
# -- interop ----------------------------------------------------------
|
|
147
|
+
|
|
148
|
+
@classmethod
|
|
149
|
+
def adapt(cls, panel: "Panel | Any") -> "Panel":
|
|
150
|
+
"""Coerce any panel-like object into an imaging :class:`Panel`.
|
|
151
|
+
|
|
152
|
+
Accepts an imaging :class:`Panel` unchanged. Otherwise reads
|
|
153
|
+
``width``, ``height``, ``displays`` and a driver -- from ``driver``
|
|
154
|
+
(a :class:`Driver` or a vendor name string) or from a ``driver_spec``
|
|
155
|
+
attribute, which is what :class:`pyvisionect.devices.panels.Panel`
|
|
156
|
+
exposes. ``rotation`` and ``interlace`` are taken if present and
|
|
157
|
+
default to ``0`` / auto.
|
|
158
|
+
"""
|
|
159
|
+
if isinstance(panel, cls):
|
|
160
|
+
return panel
|
|
161
|
+
try:
|
|
162
|
+
width = int(panel.width)
|
|
163
|
+
height = int(panel.height)
|
|
164
|
+
displays = int(panel.displays)
|
|
165
|
+
except AttributeError as exc:
|
|
166
|
+
raise TypeError(
|
|
167
|
+
f"{panel!r} is not panel-like: expected width/height/displays"
|
|
168
|
+
) from exc
|
|
169
|
+
driver = getattr(panel, "driver", None)
|
|
170
|
+
if not isinstance(driver, (Driver, str, type(None))):
|
|
171
|
+
driver = None
|
|
172
|
+
if driver is None:
|
|
173
|
+
spec = getattr(panel, "driver_spec", None)
|
|
174
|
+
if spec is not None:
|
|
175
|
+
driver = Driver(mirror=bool(spec.mirror),
|
|
176
|
+
color_mask=bool(spec.color_mask),
|
|
177
|
+
name=str(getattr(spec, "name", "")))
|
|
178
|
+
return cls(
|
|
179
|
+
width=width,
|
|
180
|
+
height=height,
|
|
181
|
+
displays=displays,
|
|
182
|
+
driver=driver,
|
|
183
|
+
rotation=int(getattr(panel, "rotation", 0) or 0),
|
|
184
|
+
interlace=getattr(panel, "interlace", None),
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
def __post_init__(self) -> None:
|
|
188
|
+
if self.width <= 0 or self.height <= 0:
|
|
189
|
+
raise ValueError("panel width and height must be positive")
|
|
190
|
+
if self.displays <= 0:
|
|
191
|
+
raise ValueError("panel must have at least one display")
|
|
192
|
+
if self.rotation not in (0, 1, 2, 3):
|
|
193
|
+
raise ValueError(f"bad display rotation {self.rotation!r}; expected 0..3")
|
|
194
|
+
object.__setattr__(self, "driver", resolve_driver(self.driver))
|
|
195
|
+
|
|
196
|
+
# -- derived geometry --------------------------------------------------
|
|
197
|
+
|
|
198
|
+
@property
|
|
199
|
+
def rotated_width(self) -> int:
|
|
200
|
+
return self.height if self.rotation in (1, 3) else self.width
|
|
201
|
+
|
|
202
|
+
@property
|
|
203
|
+
def rotated_height(self) -> int:
|
|
204
|
+
return self.width if self.rotation in (1, 3) else self.height
|
|
205
|
+
|
|
206
|
+
@property
|
|
207
|
+
def canvas_width(self) -> int:
|
|
208
|
+
"""Session-canvas width -- ``Displays.Borders()``, spec §1.5."""
|
|
209
|
+
return self.rotated_width
|
|
210
|
+
|
|
211
|
+
@property
|
|
212
|
+
def canvas_height(self) -> int:
|
|
213
|
+
"""Session-canvas height: the displays are stacked vertically.
|
|
214
|
+
|
|
215
|
+
``Config.ParsePageLayout()`` arrangement ``2`` (``PageLayout: "0"``) is
|
|
216
|
+
the vertical stack we observe on the sign (``config.go:273-280``).
|
|
217
|
+
Other arrangements are not implemented.
|
|
218
|
+
"""
|
|
219
|
+
return self.rotated_height * self.displays
|
|
220
|
+
|
|
221
|
+
@property
|
|
222
|
+
def canvas_shape(self) -> tuple[int, int]:
|
|
223
|
+
"""``(height, width)`` -- numpy order."""
|
|
224
|
+
return (self.canvas_height, self.canvas_width)
|
|
225
|
+
|
|
226
|
+
def geometry(self) -> tuple[DisplayGeometry, ...]:
|
|
227
|
+
"""The logical displays, top to bottom, ids ``0 .. displays-1``."""
|
|
228
|
+
return tuple(
|
|
229
|
+
DisplayGeometry(
|
|
230
|
+
id=i,
|
|
231
|
+
x=0,
|
|
232
|
+
y=i * self.rotated_height,
|
|
233
|
+
width=self.width,
|
|
234
|
+
height=self.height,
|
|
235
|
+
rotation=self.rotation,
|
|
236
|
+
)
|
|
237
|
+
for i in range(self.displays)
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
@property
|
|
241
|
+
def interlace_mode(self) -> int:
|
|
242
|
+
"""Resolved interlacing mode (see the ``interlace`` parameter)."""
|
|
243
|
+
if self.interlace is not None:
|
|
244
|
+
return self.interlace
|
|
245
|
+
return 2 if self.displays == 4 else 0
|
|
246
|
+
|
|
247
|
+
@property
|
|
248
|
+
def screens(self) -> int:
|
|
249
|
+
"""Number of *physical* panel channels the wire addresses.
|
|
250
|
+
|
|
251
|
+
Without interlacing this is just the logical display count: one
|
|
252
|
+
``ScreenID`` per display. With the mode-2 fold, two logical displays
|
|
253
|
+
share one physical ``2880 x 640`` channel, so it is ``displays // 2``.
|
|
254
|
+
"""
|
|
255
|
+
return self.displays // 2 if self.interlace_mode else self.displays
|
|
256
|
+
|
|
257
|
+
@property
|
|
258
|
+
def screen_width(self) -> int:
|
|
259
|
+
"""Width of one physical channel -- what ``RectangleHeader.X`` indexes.
|
|
260
|
+
|
|
261
|
+
``2 x 1440 = 2880`` on the interlaced sign, because a screen row is
|
|
262
|
+
two logical displays' rows interleaved 4 pixels at a time.
|
|
263
|
+
"""
|
|
264
|
+
return self.rotated_width * 2 if self.interlace_mode else self.rotated_width
|
|
265
|
+
|
|
266
|
+
@property
|
|
267
|
+
def screen_height(self) -> int:
|
|
268
|
+
"""Height of one physical channel. The fold is columns-only."""
|
|
269
|
+
return self.rotated_height
|
|
270
|
+
|
|
271
|
+
@property
|
|
272
|
+
def supports_screen_rectangles(self) -> bool:
|
|
273
|
+
"""Whether a **screen-space** partial rectangle is expressible here.
|
|
274
|
+
|
|
275
|
+
This is the complement of :attr:`forces_full_screen`, which is about
|
|
276
|
+
*canvas*-space rectangles. A canvas rectangle cannot survive the fold;
|
|
277
|
+
a screen rectangle never enters it. See
|
|
278
|
+
:func:`pyvisionect.imaging.partial.encode_partial_frame`.
|
|
279
|
+
|
|
280
|
+
True only for interlacing mode 2 at rotation 0 on a greyscale driver:
|
|
281
|
+
|
|
282
|
+
* mode 1's lane pairing was never recovered (:data:`INTERLACE_PAIRS`),
|
|
283
|
+
so there is no map to address it with;
|
|
284
|
+
* mode 0 needs no screen-space path at all -- a canvas rectangle *is*
|
|
285
|
+
the wire rectangle there, and
|
|
286
|
+
:func:`~pyvisionect.imaging.encoder.encode_frame` already emits one;
|
|
287
|
+
* a rotated display would have to rotate each lane's sub-tile
|
|
288
|
+
independently and no rotated interlaced hardware exists to check it
|
|
289
|
+
against;
|
|
290
|
+
* colour-mask drivers are not implemented at all;
|
|
291
|
+
* and a logical display whose width is not a whole number of 4-pixel
|
|
292
|
+
interleave groups has no screen column range that covers a whole
|
|
293
|
+
number of lane groups, so there is nothing legal to address.
|
|
294
|
+
|
|
295
|
+
.. warning::
|
|
296
|
+
True here means "the library can build the bytes", **not** "your
|
|
297
|
+
device will draw them". Only ``HardwareNameID 8`` hardware was
|
|
298
|
+
measured accepting these (``OPEN-QUESTIONS.md`` A10).
|
|
299
|
+
"""
|
|
300
|
+
return (
|
|
301
|
+
self.interlace_mode == 2
|
|
302
|
+
and self.rotation == 0
|
|
303
|
+
and self.rotated_width % 4 == 0
|
|
304
|
+
and not self.driver.color_mask # type: ignore[union-attr]
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
@property
|
|
308
|
+
def forces_full_screen(self) -> bool:
|
|
309
|
+
"""True when every update must be a full-screen one.
|
|
310
|
+
|
|
311
|
+
``getRectangleSupport`` returns ``false`` unconditionally for
|
|
312
|
+
``HardwareNameID == 8`` (``vss/cmd/engine/client.go:41-42``), and for a
|
|
313
|
+
**canvas-space** rectangle the reason is structural:
|
|
314
|
+
:func:`interlace_payloads` needs all four full-size display rectangles,
|
|
315
|
+
so a partial one cannot be interlaced (spec §1.6, §1.7). Neither
|
|
316
|
+
``ForceRectangleSupport`` nor ``MergeRegions=true`` can turn it on.
|
|
317
|
+
|
|
318
|
+
.. note::
|
|
319
|
+
The device itself is not the obstacle. A rectangle addressed in
|
|
320
|
+
**screen** coordinates never enters the fold, and the 31.2" sign was
|
|
321
|
+
measured accepting those on 2026-10-05 (``OPEN-QUESTIONS.md`` A10).
|
|
322
|
+
:func:`~pyvisionect.imaging.encode_frame` has no screen-space path,
|
|
323
|
+
so this property stays True for it.
|
|
324
|
+
"""
|
|
325
|
+
return self.interlace_mode != 0
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
#: Our live device: ``00112233-4455-6677-8899-aabb00000000``, ``HardwareNameID``
|
|
329
|
+
#: 8, hardware 1.1.0, driver ``eink-flip``. Server-side geometry is 4 x
|
|
330
|
+
#: 1440 x 640 stacked (canvas 1440 x 2560); the wire carries 2 interlaced
|
|
331
|
+
#: rectangles of 2880 x 640. Spec §0, §1.5, §1.6.
|
|
332
|
+
PANEL_32INCH = Panel(
|
|
333
|
+
width=1440,
|
|
334
|
+
height=640,
|
|
335
|
+
displays=4,
|
|
336
|
+
driver=DRIVERS["eink-flip"],
|
|
337
|
+
rotation=0,
|
|
338
|
+
interlace=None, # auto -> 2
|
|
339
|
+
)
|