]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/commitdiff
Merge pull request #142 from FoamyGuy/i2c_buffer_sleepwake_fix 2.1.2
authorfoamyguy <foamyguy@gmail.com>
Wed, 20 Nov 2024 22:30:24 +0000 (16:30 -0600)
committerGitHub <noreply@github.com>
Wed, 20 Nov 2024 22:30:24 +0000 (16:30 -0600)
I2c buffer sleepwake fix

docs/conf.py
i2cdisplaybus/__init__.py

index a8628abf91ec5138961a0bfac645b469ad72b2b0..df3ec85d125f1eca37599158a757052f67491254 100644 (file)
@@ -102,17 +102,7 @@ napoleon_numpy_docstring = False
 #
 on_rtd = os.environ.get("READTHEDOCS", None) == "True"
 
-if not on_rtd:  # only import and set the theme if we're building docs locally
-    try:
-        import sphinx_rtd_theme
-
-        html_theme = "sphinx_rtd_theme"
-        html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
-    except:
-        html_theme = "default"
-        html_theme_path = ["."]
-else:
-    html_theme_path = ["."]
+html_theme = "sphinx_rtd_theme"
 
 # Add any paths that contain custom static files (such as style sheets) here,
 # relative to this directory. They are copied after the builtin static files,
index c8d64418cb708d974a9ec4ae5366213d2617fa7c..c9631583e96466c385084acce15c2b92f2cff3ac 100644 (file)
@@ -21,6 +21,8 @@ i2cdisplaybus for Blinka
 """
 
 import time
+from typing import Optional
+
 import busio
 import digitalio
 from circuitpython_typing import ReadableBuffer
@@ -87,7 +89,7 @@ class I2CDisplayBus:
         done.
         """
         self._begin_transaction()
-        self._send(DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, bytes([command] + data))
+        self._send(DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, data, command)
         self._end_transaction()
 
     def _send(
@@ -95,14 +97,24 @@ class I2CDisplayBus:
         data_type: int,
         _chip_select: int,  # Chip select behavior
         data: ReadableBuffer,
+        command: Optional[int] = None,
     ):
+        # pylint: disable=too-many-branches
         if data_type == DISPLAY_COMMAND:
             n = len(data)
+            if command is not None:
+                n += 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 command is not None:
+                        if i > 0:
+                            command_bytes[2 * i + 1] = data[i]
+                        else:
+                            command_bytes[2 * i + 1] = command
+                    else:
+                        command_bytes[2 * i + 1] = data[i]
 
             try:
                 self._i2c.writeto(self._dev_addr, buffer=command_bytes)
@@ -113,9 +125,16 @@ class I2CDisplayBus:
                     ) from error
                 raise error
         else:
-            data_bytes = bytearray(len(data) + 1)
+            size = len(data) + 1
+            if command is not None:
+                size += 1
+            data_bytes = bytearray(size)
             data_bytes[0] = 0x40
-            data_bytes[1:] = data
+            if command is not None:
+                data_bytes[1] = command
+                data_bytes[2:] = data
+            else:
+                data_bytes[1:] = data
             try:
                 self._i2c.writeto(self._dev_addr, buffer=data_bytes)
             except OSError as error: