1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
from StreamDeck.Devices import StreamDeck
class StreamDeckMock(StreamDeck.StreamDeck):
"""
Represents a physically attached StreamDeck Original device.
"""
KEY_COUNT = 24
KEY_COLS = 6
KEY_ROWS = 4
KEY_PIXEL_WIDTH = 72
KEY_PIXEL_HEIGHT = 72
KEY_IMAGE_FORMAT = "BMP"
KEY_FLIP = (True, True)
KEY_ROTATION = 0
DECK_TYPE = "Stream Deck Original"
IMAGE_REPORT_LENGTH = 8191
IMAGE_REPORT_HEADER_LENGTH = 16
# fmt: off
# 72 x 72 black BMP
BLANK_KEY_IMAGE = [
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
] + [0] * (KEY_PIXEL_WIDTH * KEY_PIXEL_HEIGHT * 3)
# fmt: on
def _convert_key_id_origin(self, key):
"""
Converts a key index from or to a origin at the physical top-left of
the StreamDeck device.
:param int key: Index of the button with either a device or top-left origin.
:rtype: int
:return: Key index converted to the opposite key origin (device or top-left).
"""
key_col = key % self.KEY_COLS
return (key - key_col) + ((self.KEY_COLS - 1) - key_col)
def _read_key_states(self):
"""
Reads the key states of the StreamDeck. This is used internally by
:func:`~StreamDeck._read` to talk to the actual device.
:rtype: list(bool)
:return: Button states, with the origin at the top-left of the deck.
"""
return None
def __del__(self):
"""
Delete handler for the StreamDeck, automatically closing the transport
if it is currently open and terminating the transport reader thread.
"""
pass
# states = self.device.read(1 + self.KEY_COUNT)
# if states is None:
# return None
# states = states[1:]
# return [bool(states[s]) for s in map(self._convert_key_id_origin, range(self.KEY_COUNT))]
def open(self):
"""
Opens the device for input/output. This must be called prior to setting
or retrieving any device state.
.. seealso:: See :func:`~StreamDeck.close` for the corresponding close method.
"""
# self.device.open()
# self._reset_key_stream()
# self._setup_reader(self._read)
def close(self):
"""
Closes the device for input/output.
.. seealso:: See :func:`~StreamDeck.open` for the corresponding open method.
"""
pass
def is_open(self):
"""
Indicattes if the StreamDeck device is currently open and ready for use..
:rtype: bool
:return: `True` if the deck is open, `False` otherwise.
"""
return True
def connected(self):
"""
Indicates if the physical StreamDeck device this instance is attached to
is still connected to the host.
:rtype: bool
:return: `True` if the deck is still connected, `False` otherwise.
"""
return True
def id(self):
"""
Retrieves the physical ID of the attached StreamDeck. This can be used
to differentiate one StreamDeck from another.
:rtype: str
:return: Identifier for the attached device.
"""
return "/dev/dummy"
def _reset_key_stream(self):
"""
Sends a blank key report to the StreamDeck, resetting the key image
streamer in the device. This prevents previously started partial key
writes that were not completed from corrupting images sent from this
application.
"""
payload = bytearray(self.IMAGE_REPORT_LENGTH)
payload[0] = 0x02
# self.device.write(payload)
def reset(self):
"""
Resets the StreamDeck, clearing all button images and showing the
standby image.
"""
payload = bytearray(17)
payload[0:2] = [0x0B, 0x63]
# self.device.write_feature(payload)
def set_brightness(self, percent):
"""
Sets the global screen brightness of the StreamDeck, across all the
physical buttons.
:param int/float percent: brightness percent, from [0-100] as an `int`,
or normalized to [0.0-1.0] as a `float`.
"""
print(f"Dummy brightness changed to: {percent}")
if isinstance(percent, float):
percent = int(100.0 * percent)
percent = min(max(percent, 0), 100)
payload = bytearray(17)
payload[0:6] = [0x05, 0x55, 0xAA, 0xD1, 0x01, percent]
# self.device.write_feature(payload)
def get_serial_number(self):
"""
Gets the serial number of the attached StreamDeck.
:rtype: str
:return: String containing the serial number of the attached device.
"""
# serial = self.device.read_feature(0x03, 17)
# return self._extract_string(serial[5:])
return "FAKE"
def get_firmware_version(self):
"""
Gets the firmware version of the attached StreamDeck.
:rtype: str
:return: String containing the firmware version of the attached device.
"""
# version = self.device.read_feature(0x04, 17)
# return self._extract_string(version[5:])
return "1.0"
def set_key_image(self, key, image):
"""
Sets the image of a button on the StreamDeck to the given image. The
image being set should be in the correct format for the device, as an
enumerable collection of bytes.
.. seealso:: See :func:`~StreamDeck.get_key_image_format` method for
information on the image format accepted by the device.
:param int key: Index of the button whose image is to be updated.
:param enumerable image: Raw data of the image to set on the button.
If `None`, the key will be cleared to a black
color.
"""
pass
|