Protocol¶
protocol ¶
HID protocol constants, report builders, and input event parsers.
Implements the Elgato Stream Deck Main Protocol as documented in
docs/elgato-hid-protocol.md. The legacy Stream Deck Mini protocol
is not supported.
OUTPUT_REPORT_SIZE
module-attribute
¶
Maximum size of an HID output report in bytes.
INPUT_REPORT_SIZE
module-attribute
¶
Maximum size of an HID input report in bytes.
FEATURE_REPORT_SIZE
module-attribute
¶
Maximum size of an HID feature report in bytes.
ReportId ¶
Bases: IntEnum
HID report IDs used by the main protocol.
Source code in src/deux/runtime/hid/protocol.py
OutputCommand ¶
Bases: IntEnum
Command bytes for output reports (Report ID 0x02).
Source code in src/deux/runtime/hid/protocol.py
InputCommand ¶
FeatureCommand ¶
Bases: IntEnum
Command bytes for setter feature reports (Report ID 0x03).
Source code in src/deux/runtime/hid/protocol.py
TouchEventType ¶
EncoderEventType ¶
ImageRotation ¶
KeyStateEvent
dataclass
¶
One or more keys changed press state.
Attributes:
| Name | Type | Description |
|---|---|---|
states |
tuple[bool, ...]
|
Per-key pressed state. Index matches the key index. |
Source code in src/deux/runtime/hid/protocol.py
TouchTapEvent
dataclass
¶
Short tap on the touchscreen window.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
int
|
Touch X-coordinate. |
y |
int
|
Touch Y-coordinate. |
Source code in src/deux/runtime/hid/protocol.py
TouchPressEvent
dataclass
¶
Long press (hold) on the touchscreen window.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
int
|
Touch X-coordinate. |
y |
int
|
Touch Y-coordinate. |
Source code in src/deux/runtime/hid/protocol.py
TouchFlickEvent
dataclass
¶
Flick gesture on the touchscreen window.
Attributes:
| Name | Type | Description |
|---|---|---|
start_x |
int
|
Start X-coordinate. |
start_y |
int
|
Start Y-coordinate. |
end_x |
int
|
End X-coordinate. |
end_y |
int
|
End Y-coordinate. |
Source code in src/deux/runtime/hid/protocol.py
EncoderButtonEvent
dataclass
¶
One or more encoder buttons changed press state.
Attributes:
| Name | Type | Description |
|---|---|---|
states |
tuple[bool, ...]
|
Per-encoder pressed state. |
Source code in src/deux/runtime/hid/protocol.py
EncoderRotateEvent
dataclass
¶
One or more encoders were rotated.
Attributes:
| Name | Type | Description |
|---|---|---|
ticks |
tuple[int, ...]
|
Per-encoder rotation ticks. Positive = CW, negative = CCW. |
Source code in src/deux/runtime/hid/protocol.py
UnitInfo
dataclass
¶
Hardware information parsed from the Get Unit Information feature report.
Attributes:
| Name | Type | Description |
|---|---|---|
rows |
int
|
Keypad matrix rows. |
cols |
int
|
Keypad matrix columns. |
key_width |
int
|
Key/button image width in pixels. |
key_height |
int
|
Key/button image height in pixels. |
lcd_width |
int
|
Full LCD width in pixels. |
lcd_height |
int
|
Full LCD height in pixels. |
image_bpp |
int
|
Image bits per pixel. |
color_scheme |
int
|
Image color scheme identifier. |
Source code in src/deux/runtime/hid/protocol.py
parse_input_report ¶
Parse a raw HID input report into a typed event.
Handles platform differences in hid_read_timeout return data:
on macOS and Windows the Report ID byte (0x01) is included as
the first byte, while on Linux (hidraw) it is stripped. This
function detects the presence of the Report ID and skips it
automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
Raw input report bytes (up to 512 bytes). |
required |
Returns:
| Type | Description |
|---|---|
InputEvent or None
|
A typed event, or |
Source code in src/deux/runtime/hid/protocol.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
parse_unit_info ¶
Parse a Get Unit Information feature report response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
Raw feature report bytes (report ID 0x08). |
required |
Returns:
| Type | Description |
|---|---|
UnitInfo
|
Parsed hardware information. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the data is too short to parse. |
Source code in src/deux/runtime/hid/protocol.py
parse_serial_number ¶
Parse a Get Unit Serial Number feature report response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
Raw feature report bytes (report ID 0x06). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The serial number string. |
Source code in src/deux/runtime/hid/protocol.py
parse_firmware_version ¶
Parse a Get Firmware Version feature report response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
Raw feature report bytes (report ID 0x04, 0x05, or 0x07). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The firmware version string. |
Source code in src/deux/runtime/hid/protocol.py
build_key_image_reports ¶
Build output reports for Update Key Image (command 0x07).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_index
|
int
|
Zero-based key index. |
required |
jpeg_data
|
bytes
|
JPEG-encoded image data (already rotated as needed). |
required |
Returns:
| Type | Description |
|---|---|
list[bytes]
|
List of 1024-byte output reports ready for |
Source code in src/deux/runtime/hid/protocol.py
build_full_screen_reports ¶
Build output reports for Update Full Screen Image (command 0x08).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
jpeg_data
|
bytes
|
JPEG-encoded full-screen image data (already rotated as needed). |
required |
Returns:
| Type | Description |
|---|---|
list[bytes]
|
List of 1024-byte output reports ready for |
Source code in src/deux/runtime/hid/protocol.py
build_window_reports ¶
Build output reports for Update Window Image (command 0x0B).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
jpeg_data
|
bytes
|
JPEG-encoded window image data (already rotated as needed). |
required |
Returns:
| Type | Description |
|---|---|
list[bytes]
|
List of 1024-byte output reports ready for |
Source code in src/deux/runtime/hid/protocol.py
build_partial_window_reports ¶
build_partial_window_reports(x: int, y: int, width: int, height: int, jpeg_data: bytes) -> list[bytes]
Build output reports for Update Partial Window Image (command 0x0C).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int
|
X-coordinate of the region (logical, no rotation accounting). |
required |
y
|
int
|
Y-coordinate of the region. |
required |
width
|
int
|
Width of the region in pixels. |
required |
height
|
int
|
Height of the region in pixels. |
required |
jpeg_data
|
bytes
|
JPEG-encoded partial image data (already rotated as needed). |
required |
Returns:
| Type | Description |
|---|---|
list[bytes]
|
List of 1024-byte output reports ready for |
Source code in src/deux/runtime/hid/protocol.py
build_background_reports ¶
Build output reports for Update Background (command 0x0D).
Classic and XL families only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bg_index
|
int
|
Background storage index. |
required |
jpeg_data
|
bytes
|
JPEG-encoded background image data (already rotated as needed). |
required |
Returns:
| Type | Description |
|---|---|
list[bytes]
|
List of 1024-byte output reports ready for |
Notes
The Update Background command has chunk index and chunk contents
size fields swapped compared to the other output commands.
Source code in src/deux/runtime/hid/protocol.py
build_show_logo ¶
Build a Show Logo feature report.
Returns:
| Type | Description |
|---|---|
bytes
|
32-byte feature report. |
Source code in src/deux/runtime/hid/protocol.py
build_fill_lcd_color ¶
Build a Fill LCD with Color feature report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
int
|
Red component (0-255). |
required |
g
|
int
|
Green component (0-255). |
required |
b
|
int
|
Blue component (0-255). |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
32-byte feature report. |
Source code in src/deux/runtime/hid/protocol.py
build_fill_key_color ¶
Build a Fill Key with Color feature report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_index
|
int
|
Zero-based key index. |
required |
r
|
int
|
Red component (0-255). |
required |
g
|
int
|
Green component (0-255). |
required |
b
|
int
|
Blue component (0-255). |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
32-byte feature report. |
Source code in src/deux/runtime/hid/protocol.py
build_set_brightness ¶
Build a Set Backlight Brightness feature report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
percent
|
int
|
Brightness level from 0 to 100. |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
32-byte feature report. |
Source code in src/deux/runtime/hid/protocol.py
build_set_sleep_duration ¶
Build a Set Sleep Mode Duration feature report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
int
|
Duration in seconds (0 = disabled). |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
32-byte feature report. |
Source code in src/deux/runtime/hid/protocol.py
build_show_background ¶
Build a Show Background by Index feature report.
XL family only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bg_index
|
int
|
Background storage index. |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
32-byte feature report. |
Source code in src/deux/runtime/hid/protocol.py
build_get_serial_number ¶
Build a Get Unit Serial Number feature report request.
Returns:
| Type | Description |
|---|---|
bytes
|
32-byte feature report with report ID 0x06. |
Source code in src/deux/runtime/hid/protocol.py
build_get_unit_info ¶
Build a Get Unit Information feature report request.
Returns:
| Type | Description |
|---|---|
bytes
|
32-byte feature report with report ID 0x08. |
Source code in src/deux/runtime/hid/protocol.py
build_get_firmware_version ¶
Build a Get Firmware Version feature report request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
report_id
|
int
|
Report ID for the desired firmware component.
Use |
ReportId.FW_VERSION_AP2
|
Returns:
| Type | Description |
|---|---|
bytes
|
32-byte feature report. |
Source code in src/deux/runtime/hid/protocol.py
build_get_sleep_duration ¶
Build a Get Sleep Mode Duration feature report request.
Returns:
| Type | Description |
|---|---|
bytes
|
32-byte feature report with report ID 0x0A. |