]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/commitdiff
add command to _send()
authorfoamyguy <foamyguy@gmail.com>
Fri, 15 Nov 2024 16:35:30 +0000 (10:35 -0600)
committerfoamyguy <foamyguy@gmail.com>
Fri, 15 Nov 2024 16:35:30 +0000 (10:35 -0600)
i2cdisplaybus/__init__.py

index b004e54ec4ebbc49322a391ad691e5835376fca6..f1b2d15fddc2a3b7843b198b0a3b7d6686e66baf 100644 (file)
@@ -88,8 +88,9 @@ class I2CDisplayBus:
         """
         self._begin_transaction()
         # re-wrap in case of byte-string
-        buffer = list(data) if isinstance(data, bytes) else data
-        self._send(DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, bytes([command] + buffer))
+        #buffer = list(data) if isinstance(data, bytes) else data
+        #self._send(DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, bytes([command] + buffer))
+        self._send(DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, data, command)
         self._end_transaction()
 
     def _send(
@@ -97,14 +98,18 @@ class I2CDisplayBus:
         data_type: int,
         _chip_select: int,  # Chip select behavior
         data: ReadableBuffer,
+        command: int,
     ):
         if data_type == DISPLAY_COMMAND:
-            n = len(data)
+            n = len(data) + 1
             if n > 0:
                 command_bytes = bytearray(n * 2)
                 for i in range(n):
                     command_bytes[2 * i] = 0x80
-                    command_bytes[2 * i + 1] = data[i]
+                    if i > 0:
+                        command_bytes[2 * i + 1] = data[i]
+                    else:
+                        command_bytes[2 * i + 1] = command
 
             try:
                 self._i2c.writeto(self._dev_addr, buffer=command_bytes)
@@ -115,9 +120,10 @@ class I2CDisplayBus:
                     ) from error
                 raise error
         else:
-            data_bytes = bytearray(len(data) + 1)
+            data_bytes = bytearray(len(data) + 2)
             data_bytes[0] = 0x40
-            data_bytes[1:] = data
+            data_bytes[1] = command
+            data_bytes[2:] = data
             try:
                 self._i2c.writeto(self._dev_addr, buffer=data_bytes)
             except OSError as error: