Skip to content

Commit f19cfe7

Browse files
authored
Merge pull request #26 from makermelissa/master
Fixes an issue with Adafruit_CircuitPython_Requests and adds color_order
2 parents 56b59fb + b571dfb commit f19cfe7

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

adafruit_matrixportal/graphics.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class Graphics:
4242
:param int height: The height of the display in Pixels. Defaults to 32.
4343
:param int bit_depth: The number of bits per color channel. Defaults to 2.
4444
:param list alt_addr_pins: An alternate set of address pins to use. Defaults to None
45+
:param string color_order: A string containing the letter "R", "G", and "B" in the
46+
order you want. Defaults to "RGB"
4547
:param debug: Turn on debug print outs. Defaults to False.
4648
4749
"""
@@ -55,12 +57,17 @@ def __init__(
5557
height=32,
5658
bit_depth=2,
5759
alt_addr_pins=None,
60+
color_order="RGB",
5861
debug=False
5962
):
6063

6164
self._debug = debug
6265
matrix = Matrix(
63-
bit_depth=bit_depth, width=width, height=height, alt_addr_pins=alt_addr_pins
66+
bit_depth=bit_depth,
67+
width=width,
68+
height=height,
69+
alt_addr_pins=alt_addr_pins,
70+
color_order=color_order,
6471
)
6572
self.display = matrix.display
6673

adafruit_matrixportal/matrix.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,24 @@ class Matrix:
4545
:param int height: The height of the display in Pixels. Defaults to 32.
4646
:param int bit_depth: The number of bits per color channel. Defaults to 2.
4747
:param list alt_addr_pins: An alternate set of address pins to use. Defaults to None
48+
:param string color_order: A string containing the letter "R", "G", and "B" in the
49+
order you want. Defaults to "RGB"
4850
4951
"""
5052

5153
# pylint: disable=too-few-public-methods,too-many-branches
52-
def __init__(self, *, width=64, height=32, bit_depth=2, alt_addr_pins=None):
54+
def __init__(
55+
self, *, width=64, height=32, bit_depth=2, alt_addr_pins=None, color_order="RGB"
56+
):
57+
58+
if not isinstance(color_order, str):
59+
raise ValueError("color_index should be a string")
60+
color_order = color_order.lower()
61+
red_index = color_order.find("r")
62+
green_index = color_order.find("g")
63+
blue_index = color_order.find("b")
64+
if -1 in (red_index, green_index, blue_index):
65+
raise ValueError("color_order should contain R, G, and B")
5366

5467
if "Matrix Portal M4" in os.uname().machine:
5568
# MatrixPortal M4 Board
@@ -115,7 +128,14 @@ def __init__(self, *, width=64, height=32, bit_depth=2, alt_addr_pins=None):
115128
width=width,
116129
height=height,
117130
bit_depth=bit_depth,
118-
rgb_pins=rgb_pins,
131+
rgb_pins=(
132+
rgb_pins[red_index],
133+
rgb_pins[green_index],
134+
rgb_pins[blue_index],
135+
rgb_pins[red_index + 3],
136+
rgb_pins[green_index + 3],
137+
rgb_pins[blue_index + 3],
138+
),
119139
addr_pins=addr_pins,
120140
clock_pin=clock_pin,
121141
latch_pin=latch_pin,

adafruit_matrixportal/matrixportal.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class MatrixPortal:
5858
:param busio.SPI external_spi: A previously declared spi object. Defaults to ``None``.
5959
:param int bit_depth: The number of bits per color channel. Defaults to 2.
6060
:param list alt_addr_pins: An alternate set of address pins to use. Defaults to None
61+
:param string color_order: A string containing the letter "R", "G", and "B" in the
62+
order you want. Defaults to "RGB"
6163
:param debug: Turn on debug print outs. Defaults to False.
6264
6365
"""
@@ -77,6 +79,7 @@ def __init__(
7779
external_spi=None,
7880
bit_depth=2,
7981
alt_addr_pins=None,
82+
color_order="RGB",
8083
debug=False
8184
):
8285

@@ -87,6 +90,7 @@ def __init__(
8790
width=64,
8891
height=32,
8992
alt_addr_pins=alt_addr_pins,
93+
color_order=color_order,
9094
debug=debug,
9195
)
9296
self.display = self.graphics.display

adafruit_matrixportal/network.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,6 @@ def fetch(self, url, *, headers=None, timeout=10):
395395
self.neo_status(STATUS_DATA_RECEIVED) # green = got data
396396
print("Reply is OK!")
397397

398-
if self._debug:
399-
print(response.text)
400-
401398
return response
402399

403400
def fetch_data(
@@ -417,6 +414,8 @@ def fetch_data(
417414
try:
418415
gc.collect()
419416
json_out = response.json()
417+
if self._debug:
418+
print(json_out)
420419
gc.collect()
421420
except ValueError: # failed to parse?
422421
print("Couldn't parse json: ", response.text)

0 commit comments

Comments
 (0)