Skip to content

Commit b571dfb

Browse files
committed
Converted alt_rgb_pins to color_order
1 parent c8e016b commit b571dfb

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

adafruit_matrixportal/graphics.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +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 list alt_rgb_pins: An alternate set of rgb 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"
4647
:param debug: Turn on debug print outs. Defaults to False.
4748
4849
"""
@@ -56,7 +57,7 @@ def __init__(
5657
height=32,
5758
bit_depth=2,
5859
alt_addr_pins=None,
59-
alt_rgb_pins=None,
60+
color_order="RGB",
6061
debug=False
6162
):
6263

@@ -66,7 +67,7 @@ def __init__(
6667
width=width,
6768
height=height,
6869
alt_addr_pins=alt_addr_pins,
69-
alt_rgb_pins=alt_rgb_pins,
70+
color_order=color_order,
7071
)
7172
self.display = matrix.display
7273

adafruit_matrixportal/matrix.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,25 @@ 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 list alt_rgb_pins: An alternate set of rgb 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"
4950
5051
"""
5152

5253
# pylint: disable=too-few-public-methods,too-many-branches
5354
def __init__(
54-
self, *, width=64, height=32, bit_depth=2, alt_addr_pins=None, alt_rgb_pins=None
55+
self, *, width=64, height=32, bit_depth=2, alt_addr_pins=None, color_order="RGB"
5556
):
5657

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")
66+
5767
if "Matrix Portal M4" in os.uname().machine:
5868
# MatrixPortal M4 Board
5969
addr_pins = [board.MTX_ADDRA, board.MTX_ADDRB, board.MTX_ADDRC]
@@ -108,10 +118,6 @@ def __init__(
108118
latch_pin = board.D10
109119
oe_pin = board.D9
110120

111-
# Alternate Address Pins
112-
if alt_rgb_pins is not None:
113-
rgb_pins = alt_rgb_pins
114-
115121
# Alternate Address Pins
116122
if alt_addr_pins is not None:
117123
addr_pins = alt_addr_pins
@@ -122,7 +128,14 @@ def __init__(
122128
width=width,
123129
height=height,
124130
bit_depth=bit_depth,
125-
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+
),
126139
addr_pins=addr_pins,
127140
clock_pin=clock_pin,
128141
latch_pin=latch_pin,

adafruit_matrixportal/matrixportal.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +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 list alt_rgb_pins: An alternate set of rgb 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"
6263
:param debug: Turn on debug print outs. Defaults to False.
6364
6465
"""
@@ -78,7 +79,7 @@ def __init__(
7879
external_spi=None,
7980
bit_depth=2,
8081
alt_addr_pins=None,
81-
alt_rgb_pins=None,
82+
color_order="RGB",
8283
debug=False
8384
):
8485

@@ -89,7 +90,7 @@ def __init__(
8990
width=64,
9091
height=32,
9192
alt_addr_pins=alt_addr_pins,
92-
alt_rgb_pins=alt_rgb_pins,
93+
color_order=color_order,
9394
debug=debug,
9495
)
9596
self.display = self.graphics.display

0 commit comments

Comments
 (0)