Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert to known-good header for StreamDeck Original V1 #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 31 additions & 34 deletions src/StreamDeck/Devices/StreamDeckOriginal.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ class StreamDeckOriginal(StreamDeck):
KEY_PIXEL_WIDTH = 72
KEY_PIXEL_HEIGHT = 72
KEY_IMAGE_FORMAT = "BMP"
KEY_PIXEL_DEPTH = 3
KEY_FLIP = (True, True)
KEY_ROTATION = 0

KEY_IMAGE_SIZE = KEY_PIXEL_WIDTH * KEY_PIXEL_HEIGHT * KEY_PIXEL_DEPTH
DECK_TYPE = "Stream Deck Original"

IMAGE_REPORT_LENGTH = 8191
IMAGE_REPORT_HEADER_LENGTH = 16
IMAGE_BYTES_PAGE_1 = 2583 * 3

# 72 x 72 black BMP
BLANK_KEY_IMAGE = [
Expand Down Expand Up @@ -146,42 +148,37 @@ def set_key_image(self, key, image):
color.
"""

image = bytes(image or self.KEY_IMAGE_SIZE)

if min(max(key, 0), self.KEY_COUNT) != key:
raise IndexError("Invalid key index {}.".format(key))

image = bytes(image or self.BLANK_KEY_IMAGE)
image_report_payload_length = len(image) // 2
if len(image) != self.KEY_IMAGE_SIZE:
raise ValueError("Invalid image size {}.".format(len(image)))

key = self._convert_key_id_origin(key)

page_number = 0
bytes_remaining = len(image)
while bytes_remaining > 0:
this_length = min(bytes_remaining, image_report_payload_length)
bytes_sent = page_number * image_report_payload_length

header = [
0x02,
0x01,
page_number + 1,
0,
1 if this_length == bytes_remaining else 0,
key + 1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
]

payload = bytes(header) + image[bytes_sent:bytes_sent + this_length]
padding = bytearray(self.IMAGE_REPORT_LENGTH - len(payload))
self.device.write(payload + padding)

bytes_remaining = bytes_remaining - this_length
page_number = page_number + 1
is_start_page = 0x01
is_not_start_page = 0x00

header_1 = [
0x02, 0x01, is_start_page, 0x00, 0x00, key + 1, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x42, 0x4d, 0xf6, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00,
0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x48, 0x00,
0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0xc0, 0x3c, 0x00, 0x00, 0xc4, 0x0e,
0x00, 0x00, 0xc4, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
]
header_2 = [
0x02, 0x01, 0x02, is_not_start_page, 0x01, key + 1, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
]

payload_1 = bytes(header_1) + image[: self.IMAGE_BYTES_PAGE_1]
payload_2 = bytes(header_2) + image[self.IMAGE_BYTES_PAGE_1:]

self.device.write(payload_1)
self.device.write(payload_2)