Skip to content

Commit

Permalink
Merge pull request #59 from makermelissa/master
Browse files Browse the repository at this point in the history
Add support for multiple rows of panels
  • Loading branch information
makermelissa committed Feb 2, 2021
2 parents 885fb7e + 6290e0c commit 83a4eab
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 26 deletions.
12 changes: 10 additions & 2 deletions adafruit_matrixportal/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ class Graphics(GraphicsBase):
:param default_bg: The path to your default background image file or a hex color.
Defaults to 0x000000.
:param int width: The width of the display in Pixels. Defaults to 64.
:param int height: The height of the display in Pixels. Defaults to 32.
:param int width: The total width of the display(s) in Pixels. Defaults to 64.
:param int height: The total height of the display(s) 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 bool Serpentine: Used when panels are arranged in a serpentine pattern rather
than a Z-pattern. Defaults to True.
:param int tiles_rows: Used to indicate the number of rows the panels are arranged in.
Defaults to 1.
:param debug: Turn on debug print outs. Defaults to False.
"""
Expand All @@ -58,6 +62,8 @@ def __init__(
bit_depth=2,
alt_addr_pins=None,
color_order="RGB",
serpentine=True,
tile_rows=1,
debug=False
):

Expand All @@ -67,6 +73,8 @@ def __init__(
height=height,
alt_addr_pins=alt_addr_pins,
color_order=color_order,
serpentine=serpentine,
tile_rows=tile_rows,
)

super().__init__(matrix.display, default_bg=default_bg, debug=debug)
90 changes: 66 additions & 24 deletions adafruit_matrixportal/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,29 @@ class Matrix:
: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 int width: The total width of the display(s) in Pixels. Defaults to 64.
:param int height: The total height of the display(s) in Pixels. Defaults to 32.
:param bool Serpentine: Used when panels are arranged in a serpentine pattern rather
than a Z-pattern. Defaults to True.
:param int tiles_rows: Used to indicate the number of rows the panels are arranged in.
Defaults to 1.
"""

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

panel_height = height // tile_rows

if not isinstance(color_order, str):
raise ValueError("color_index should be a string")
color_order = color_order.lower()
Expand All @@ -67,9 +82,9 @@ def __init__(
if "Matrix Portal M4" in os.uname().machine:
# MatrixPortal M4 Board
addr_pins = [board.MTX_ADDRA, board.MTX_ADDRB, board.MTX_ADDRC]
if height > 16:
if panel_height > 16:
addr_pins.append(board.MTX_ADDRD)
if height > 32:
if panel_height > 32:
addr_pins.append(board.MTX_ADDRE)
rgb_pins = [
board.MTX_R1,
Expand All @@ -87,13 +102,13 @@ def __init__(
if "nrf52" in os.uname().sysname:
# nrf52840 Style Feather
addr_pins = [board.D11, board.D5, board.D13]
if height > 16:
if panel_height > 16:
addr_pins.append(board.D9)
rgb_pins = [board.D6, board.A5, board.A1, board.A0, board.A4, board.D11]
clock_pin = board.D12
else:
addr_pins = [board.A5, board.A4, board.A3]
if height > 16:
if panel_height > 16:
addr_pins.append(board.A2)
rgb_pins = [
board.D6,
Expand Down Expand Up @@ -124,23 +139,50 @@ def __init__(

try:
displayio.release_displays()
matrix = rgbmatrix.RGBMatrix(
width=width,
height=height,
bit_depth=bit_depth,
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,
output_enable_pin=oe_pin,
)
if tile_rows > 1:
matrix = rgbmatrix.RGBMatrix(
width=width,
height=height,
bit_depth=bit_depth,
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,
output_enable_pin=oe_pin,
tile=tile_rows,
serpentine=serpentine,
)
else:
matrix = rgbmatrix.RGBMatrix(
width=width,
height=height,
bit_depth=bit_depth,
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,
output_enable_pin=oe_pin,
)
self.display = framebufferio.FramebufferDisplay(matrix)
except TypeError:
if tile_rows > 1:
raise RuntimeError(
"Make sure you are running CircuitPython 6.2.0.alpha-1 or later"
) from TypeError
raise
except ValueError:
raise RuntimeError("Failed to initialize RGB Matrix") from ValueError
10 changes: 10 additions & 0 deletions adafruit_matrixportal/matrixportal.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ class MatrixPortal(PortalBase):
: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.
:param int width: The total width of the display(s) in Pixels. Defaults to 64.
:param int height: The total height of the display(s) in Pixels. Defaults to 32.
:param bool Serpentine: Used when panels are arranged in a serpentine pattern rather
than a Z-pattern. Defaults to True.
:param int tiles_rows: Used to indicate the number of rows the panels are arranged in.
Defaults to 1.
"""

Expand All @@ -83,6 +89,8 @@ def __init__(
debug=False,
width=64,
height=32,
serpentine=True,
tile_rows=1,
):

graphics = Graphics(
Expand All @@ -92,6 +100,8 @@ def __init__(
height=height,
alt_addr_pins=alt_addr_pins,
color_order=color_order,
serpentine=serpentine,
tile_rows=tile_rows,
debug=debug,
)

Expand Down

0 comments on commit 83a4eab

Please sign in to comment.