Skip to content

Fixes an issue with Adafruit_CircuitPython_Requests and adds color_order #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion adafruit_matrixportal/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Graphics:
:param int height: The height of the display in Pixels. Defaults to 32.
:param int bit_depth: The number of bits per color channel. Defaults to 2.
:param list alt_addr_pins: An alternate set of address pins to use. Defaults to None
:param string color_order: A string containing the letter "R", "G", and "B" in the
order you want. Defaults to "RGB"
:param debug: Turn on debug print outs. Defaults to False.

"""
Expand All @@ -55,12 +57,17 @@ def __init__(
height=32,
bit_depth=2,
alt_addr_pins=None,
color_order="RGB",
debug=False
):

self._debug = debug
matrix = Matrix(
bit_depth=bit_depth, width=width, height=height, alt_addr_pins=alt_addr_pins
bit_depth=bit_depth,
width=width,
height=height,
alt_addr_pins=alt_addr_pins,
color_order=color_order,
)
self.display = matrix.display

Expand Down
24 changes: 22 additions & 2 deletions adafruit_matrixportal/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,24 @@ class Matrix:
:param int height: The height of the display in Pixels. Defaults to 32.
:param int bit_depth: The number of bits per color channel. Defaults to 2.
:param list alt_addr_pins: An alternate set of address pins to use. Defaults to None
:param string color_order: A string containing the letter "R", "G", and "B" in the
order you want. Defaults to "RGB"

"""

# pylint: disable=too-few-public-methods,too-many-branches
def __init__(self, *, width=64, height=32, bit_depth=2, alt_addr_pins=None):
def __init__(
self, *, width=64, height=32, bit_depth=2, alt_addr_pins=None, color_order="RGB"
):

if not isinstance(color_order, str):
raise ValueError("color_index should be a string")
color_order = color_order.lower()
red_index = color_order.find("r")
green_index = color_order.find("g")
blue_index = color_order.find("b")
if -1 in (red_index, green_index, blue_index):
raise ValueError("color_order should contain R, G, and B")

if "Matrix Portal M4" in os.uname().machine:
# MatrixPortal M4 Board
Expand Down Expand Up @@ -115,7 +128,14 @@ def __init__(self, *, width=64, height=32, bit_depth=2, alt_addr_pins=None):
width=width,
height=height,
bit_depth=bit_depth,
rgb_pins=rgb_pins,
rgb_pins=(
rgb_pins[red_index],
rgb_pins[green_index],
rgb_pins[blue_index],
rgb_pins[red_index + 3],
rgb_pins[green_index + 3],
rgb_pins[blue_index + 3],
),
addr_pins=addr_pins,
clock_pin=clock_pin,
latch_pin=latch_pin,
Expand Down
4 changes: 4 additions & 0 deletions adafruit_matrixportal/matrixportal.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class MatrixPortal:
:param busio.SPI external_spi: A previously declared spi object. Defaults to ``None``.
:param int bit_depth: The number of bits per color channel. Defaults to 2.
:param list alt_addr_pins: An alternate set of address pins to use. Defaults to None
:param string color_order: A string containing the letter "R", "G", and "B" in the
order you want. Defaults to "RGB"
:param debug: Turn on debug print outs. Defaults to False.

"""
Expand All @@ -77,6 +79,7 @@ def __init__(
external_spi=None,
bit_depth=2,
alt_addr_pins=None,
color_order="RGB",
debug=False
):

Expand All @@ -87,6 +90,7 @@ def __init__(
width=64,
height=32,
alt_addr_pins=alt_addr_pins,
color_order=color_order,
debug=debug,
)
self.display = self.graphics.display
Expand Down
5 changes: 2 additions & 3 deletions adafruit_matrixportal/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,6 @@ def fetch(self, url, *, headers=None, timeout=10):
self.neo_status(STATUS_DATA_RECEIVED) # green = got data
print("Reply is OK!")

if self._debug:
print(response.text)

return response

def fetch_data(
Expand All @@ -417,6 +414,8 @@ def fetch_data(
try:
gc.collect()
json_out = response.json()
if self._debug:
print(json_out)
gc.collect()
except ValueError: # failed to parse?
print("Couldn't parse json: ", response.text)
Expand Down