diff options
author | Joshua Liu <joshua.liu@sourceobby.com> | 2025-04-30 17:05:37 -0400 |
---|---|---|
committer | Joshua Liu <joshua.liu@sourceobby.com> | 2025-04-30 17:05:37 -0400 |
commit | a962b5064fb9ca2183ece6b1696188d0f55afa44 (patch) | |
tree | 277c0518f920dd7cdca8783c7498ee96cea01635 | |
parent | dd58ddd94dfecbe378f3a0fc190a5f219321acc1 (diff) |
doc: continued to annotated the example provided by the Python version
-rw-r--r-- | annotated_example.py | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/annotated_example.py b/annotated_example.py index a602a12..f8e4400 100644 --- a/annotated_example.py +++ b/annotated_example.py @@ -9,6 +9,9 @@ # Example script showing basic library usage - updating key images with new # tiles generated at runtime, and responding to button state change events. +""" +This is my annotation of this file to get an understanding of how we are supposed to interact with the Stream Deck. Note that I will for simplicity's sake only consider the original stream deck for code expansion. +""" import os import threading @@ -105,15 +108,57 @@ def key_change_callback(deck, key, state): if __name__ == "__main__": - streamdecks = DeviceManager().enumerate() + """ + Breakdown of the line below: + What this does is it goes into DeviceManager.py, creates a giant list of all of the possible devices that it may connect to, thenuse the enumerate() method provided by hidapi to check if there is a device with said ids connected to the machine. We receive essentially a list of tuples. The first item is the index, the next is an OBJECT representing the StreamDeck (not directly interacting with the stuff) + """ + streamdecks = DeviceManager().enumerate() # So this is a list of Stream Deck objects print("Found {} Stream Deck(s).\n".format(len(streamdecks))) for index, deck in enumerate(streamdecks): + # Now we are going through each device that we detected and attempt to open it and establish a connection # This example only works with devices that have screens. if not deck.is_visual(): continue + """ + Expansion of deck.open: + self.device.open() // Open the device (this calls hidapi's open function) + + self._reset_key_stream() // Part of clean up to prevent corruption + self._setup_reader(self._read) // I believe this sets up the communication channel with the device + + Expansion of deck.reset: + + payload = bytearray(17) + payload[0:2] = [0x0B, 0x63] + self.device.write_feature(payload) + + Expansion of _reset_key_stream: + payload = bytearray(self.IMAGE_REPORT_LENGTH) + payload[0] = 0x02 + self.device.write(payload) + + Expansion of _setup_reader: + if self.read_thread is not None: + self.run_read_thread = False + + try: + self.read_thread.join() + except RuntimeError: + pass + + if callback is not None: + self.run_read_thread = True + self.read_thread = threading.Thread(target=callback) + self.read_thread.daemon = True + self.read_thread.start():write + + Breakdown + So in our list of things that we got from line 112, 'deck' is an object that represents data about the streamdeck. + so self.device.open() attempts to open the device. + """ deck.open() deck.reset() |