adafruit / Adafruit-Raspberry-Pi-Python-Code

Adafruit library code for Raspberry Pi
1.43k stars 686 forks source link

Enhancement - writeRowSane() #149

Closed gavinB-orange closed 4 years ago

gavinB-orange commented 8 years ago

In Adafruit_LEDBackpack/Adafruit_8x8.py function writeRowRaw() is pretty raw - that oddity where pixel 0 is controlled by the value 128 rather than 1 is just peculiar. I propose adding the following patch to add writeRowSane():

(venv)pi@brebpi1:~/code/matrix/Adafruit-Raspberry-Pi-Python-Code $ git diff diff --git a/Adafruit_LEDBackpack/Adafruit_8x8.py b/Adafruit_LEDBackpack/Adafruit_8x8.py index df966dc..32c5e41 100644 --- a/Adafruit_LEDBackpack/Adafruit_8x8.py +++ b/Adafruit_LEDBackpack/Adafruit_8x8.py @@ -24,6 +24,16 @@ class EightByEight:

Set the appropriate row

 self.disp.setBufferRow(charNumber, value)
gavinB-orange commented 8 years ago

With the patch as a code block, so more readable :

diff --git a/Adafruit_LEDBackpack/Adafruit_8x8.py b/Adafruit_LEDBackpack/Adafruit_8x8.py
index df966dc..32c5e41 100644
--- a/Adafruit_LEDBackpack/Adafruit_8x8.py
+++ b/Adafruit_LEDBackpack/Adafruit_8x8.py
@@ -24,6 +24,16 @@ class EightByEight:
     # Set the appropriate row
     self.disp.setBufferRow(charNumber, value)

+  def writeRowSane(self, charNumber, value):
+    """
+    Sets a row of pixels using a raw 8-bit value.
+    0..128 are mapped as you'ed expect rather than
+    128 mapping around as in the raw case.
+    """
+    assert charNumber >= 0 and charNumber <=7
+    new_value = (value / 2) + ((value % 2) * 128)
+    self.writeRowRaw(charNumber, new_value)
+
   def clearPixel(self, x, y):
     "A wrapper function to clear pixels (purely cosmetic)"
     self.setPixel(x, y, 0)
ladyada commented 4 years ago

Thank you for the Issue! This library has been deprecated in favor of our python3 Blinka library. We have replaced all of the libraries that use this repo with CircuitPython libraries that are Python3 compatible, and support a wide variety of single board/linux computers!

Visit https://circuitpython.org/blinka for more information

CircuitPython has support for almost 200 different drivers, and a as well as FT232H support for Mac/Win/Linux!