Skip to content

Commit a85d015

Browse files
authored
Merge pull request #38 from makermelissa/refactor
Updated manual merge of all existing outstanding PRs
2 parents 52dad15 + 3fa3ffe commit a85d015

22 files changed

+604
-323
lines changed

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,23 @@ Matrix:
6767

6868
.. code:: python
6969
70-
import adafruit_is31fl3731
70+
from adafruit_is31fl3731.matrix import Matrix
7171
import board
7272
import busio
7373
with busio.I2C(board.SCL, board.SDA) as i2c:
74-
display = adafruit_is31fl3731.Matrix(i2c)
74+
display = Matrix(i2c)
7575
display.fill(127)
7676
7777
7878
Charlie Wing:
7979

8080
.. code:: python
8181
82-
import adafruit_is31fl3731
82+
from adafruit_is31fl3731.charlie_wing import CharlieWing
8383
import board
8484
import busio
8585
with busio.I2C(board.SCL, board.SDA) as i2c:
86-
display = adafruit_is31fl3731.CharlieWing(i2c)
86+
display = CharlieWing(i2c)
8787
display.fill(127)
8888
8989
# Turn off pixel 4,4, change its brightness and turn it back on

adafruit_is31fl3731.py renamed to adafruit_is31fl3731/__init__.py

Lines changed: 24 additions & 197 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
99
CircuitPython driver for the IS31FL3731 charlieplex IC.
1010
11+
Base library.
1112
12-
* Author(s): Tony DiCola, Melissa LeBlanc-Williams
13+
* Author(s): Tony DiCola, Melissa LeBlanc-Williams, David Glaude
1314
1415
Implementation Notes
1516
--------------------
@@ -22,16 +23,29 @@
2223
* `Adafruit 15x7 CharliePlex LED Matrix Display FeatherWings
2324
<https://www.adafruit.com/product/2965>`_
2425
25-
* Pimoroni LED SHIM
26-
<https://shop.pimoroni.com/products/led-shim>_
26+
* `Adafruit 16x8 CharliePlex LED Matrix Bonnets
27+
<https://www.adafruit.com/product/4127>`_
2728
28-
* Pimoroni Keybow 2040
29-
<https://shop.pimoroni.com/products/keybow-2040>_
29+
* `Pimoroni 17x7 Scroll pHAT HD
30+
<https://www.adafruit.com/product/3473>`_
31+
32+
* `Pimoroni 28x3 (r,g,b) Led Shim
33+
<https://www.adafruit.com/product/3831>`_
34+
35+
* `Pimoroni LED SHIM
36+
<https://shop.pimoroni.com/products/led-shim>`_
37+
38+
* `Pimoroni Keybow 2040
39+
<https://shop.pimoroni.com/products/keybow-2040>`_
40+
41+
* `Pimoroni 11x7 LED Matrix Breakout
42+
<https://shop.pimoroni.com/products/11x7-led-matrix-breakout>`_
3043
3144
**Software and Dependencies:**
3245
33-
* Adafruit CircuitPython firmware (2.2.0+) for the ESP8622 and M0-based boards:
46+
* Adafruit CircuitPython firmware for the supported boards:
3447
https://github.com/adafruit/circuitpython/releases
48+
3549
"""
3650

3751
# imports
@@ -66,9 +80,10 @@
6680
_COLOR_OFFSET = const(0x24)
6781

6882

69-
class Matrix:
83+
class IS31FL3731:
7084
"""
71-
The Matrix class support the main function for driving the 16x9 matrix Display
85+
The IS31FL3731 is an abstract class contain the main function related to this chip.
86+
Each board needs to define width, height and pixel_addr.
7287
7388
:param ~adafruit_bus_device.i2c_device i2c_device: the connected i2c bus i2c_device
7489
:param address: the device address; defaults to 0x74
@@ -283,6 +298,7 @@ def fill(self, color=None, blink=None, frame=None):
283298
for col in range(18):
284299
self._register(frame, _BLINK_OFFSET + col, data)
285300

301+
# This function must be replaced for each board
286302
@staticmethod
287303
def pixel_addr(x, y):
288304
"""Calulate the offset into the device array for x,y pixel"""
@@ -348,192 +364,3 @@ def image(self, img, blink=None, frame=None):
348364
for x in range(self.width): # yes this double loop is slow,
349365
for y in range(self.height): # but these displays are small!
350366
self.pixel(x, y, pixels[(x, y)], blink=blink, frame=frame)
351-
352-
353-
class CharlieWing(Matrix):
354-
"""Supports the Charlieplexed feather wing"""
355-
356-
width = 15
357-
height = 7
358-
359-
@staticmethod
360-
def pixel_addr(x, y):
361-
"""Calulate the offset into the device array for x,y pixel"""
362-
if x > 7:
363-
x = 15 - x
364-
y += 8
365-
else:
366-
y = 7 - y
367-
return x * 16 + y
368-
369-
370-
class CharlieBonnet(Matrix):
371-
"""Supports the Charlieplexed bonnet"""
372-
373-
width = 16
374-
height = 8
375-
376-
@staticmethod
377-
def pixel_addr(x, y):
378-
"""Calulate the offset into the device array for x,y pixel"""
379-
if x >= 8:
380-
return (x - 6) * 16 - (y + 1)
381-
return (x + 1) * 16 + (7 - y)
382-
383-
384-
class ScrollPhatHD(Matrix):
385-
"""Supports the Scroll pHAT HD by Pimoroni"""
386-
387-
width = 17
388-
height = 7
389-
390-
@staticmethod
391-
def pixel_addr(x, y):
392-
"""Translate an x,y coordinate to a pixel index."""
393-
if x <= 8:
394-
x = 8 - x
395-
y = 6 - y
396-
else:
397-
x = x - 8
398-
y = y - 8
399-
return x * 16 + y
400-
401-
402-
class LedShim(Matrix):
403-
"""Supports the LED SHIM by Pimoroni"""
404-
405-
width = 28
406-
height = 3
407-
408-
def __init__(self, i2c, address=0x75):
409-
super().__init__(i2c, address)
410-
411-
# pylint: disable-msg=too-many-arguments
412-
def pixelrgb(self, x, r, g, b, blink=None, frame=None):
413-
"""
414-
Blink or brightness for x-pixel
415-
416-
:param x: horizontal pixel position
417-
:param r: red brightness value 0->255
418-
:param g: green brightness value 0->255
419-
:param b: blue brightness value 0->255
420-
:param blink: True to blink
421-
:param frame: the frame to set the pixel
422-
"""
423-
super().pixel(x, 0, r, blink, frame)
424-
super().pixel(x, 1, g, blink, frame)
425-
super().pixel(x, 2, b, blink, frame)
426-
427-
# pylint: disable=inconsistent-return-statements
428-
# pylint: disable=too-many-return-statements
429-
# pylint: disable=too-many-branches
430-
431-
@staticmethod
432-
def pixel_addr(x, y):
433-
"""Translate an x,y coordinate to a pixel index."""
434-
if y == 0:
435-
if x < 7:
436-
return 118 - x
437-
if x < 15:
438-
return 141 - x
439-
if x < 21:
440-
return 106 + x
441-
if x == 21:
442-
return 15
443-
return x - 14
444-
445-
if y == 1:
446-
if x < 2:
447-
return 69 - x
448-
if x < 7:
449-
return 86 - x
450-
if x < 12:
451-
return 28 - x
452-
if x < 14:
453-
return 45 - x
454-
if x == 14:
455-
return 47
456-
if x == 15:
457-
return 41
458-
if x < 21:
459-
return x + 9
460-
if x == 21:
461-
return 95
462-
if x < 26:
463-
return x + 67
464-
return x + 50
465-
466-
if x == 0:
467-
return 85
468-
if x < 7:
469-
return 102 - x
470-
if x < 11:
471-
return 44 - x
472-
if x < 14:
473-
return 61 - x
474-
if x == 14:
475-
return 63
476-
if x < 17:
477-
return 42 + x
478-
if x < 21:
479-
return x + 25
480-
if x == 21:
481-
return 111
482-
if x < 27:
483-
return x + 83
484-
return 93
485-
486-
487-
class Keybow2040(Matrix):
488-
"""Supports the Pimoroni Keybow 2040 with 4x4 matrix of RGB LEDs """
489-
490-
width = 16
491-
height = 3
492-
493-
# pylint: disable=too-many-arguments
494-
495-
def pixelrgb(self, x, y, r, g, b, blink=None, frame=None):
496-
"""
497-
Blink or brightness for x, y-pixel
498-
499-
:param x: horizontal pixel position
500-
:param y: vertical pixel position
501-
:param r: red brightness value 0->255
502-
:param g: green brightness value 0->255
503-
:param b: blue brightness value 0->255
504-
:param blink: True to blink
505-
:param frame: the frame to set the pixel
506-
"""
507-
x = x + (4 * y)
508-
509-
super().pixel(x, 0, r, blink, frame)
510-
super().pixel(x, 1, g, blink, frame)
511-
super().pixel(x, 2, b, blink, frame)
512-
513-
# pylint: disable=inconsistent-return-statements
514-
# pylint: disable=too-many-return-statements
515-
# pylint: disable=too-many-branches
516-
517-
@staticmethod
518-
def pixel_addr(x, y):
519-
520-
lookup = [
521-
(120, 88, 104), # 0, 0
522-
(136, 40, 72), # 1, 0
523-
(112, 80, 96), # 2, 0
524-
(128, 32, 64), # 3, 0
525-
(121, 89, 105), # 0, 1
526-
(137, 41, 73), # 1, 1
527-
(113, 81, 97), # 2, 1
528-
(129, 33, 65), # 3, 1
529-
(122, 90, 106), # 0, 2
530-
(138, 25, 74), # 1, 2
531-
(114, 82, 98), # 2, 2
532-
(130, 17, 66), # 3, 2
533-
(123, 91, 107), # 0, 3
534-
(139, 26, 75), # 1, 3
535-
(115, 83, 99), # 2, 3
536-
(131, 18, 67), # 3, 3
537-
]
538-
539-
return lookup[x][y]

adafruit_is31fl3731/charlie_bonnet.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SPDX-FileCopyrightText: Tony DiCola 2017 for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
`adafruit_is31fl3731.charlie_bonnet`
7+
====================================================
8+
9+
CircuitPython driver for the IS31FL3731 charlieplex IC.
10+
11+
12+
* Author(s): Tony DiCola, Melissa LeBlanc-Williams
13+
14+
Implementation Notes
15+
--------------------
16+
17+
**Hardware:**
18+
19+
* `Adafruit 16x8 CharliePlex LED Matrix Bonnets
20+
<https://www.adafruit.com/product/4127>`_
21+
22+
23+
**Software and Dependencies:**
24+
25+
* Adafruit CircuitPython firmware for the supported boards:
26+
https://github.com/adafruit/circuitpython/releases
27+
28+
"""
29+
30+
# imports
31+
from . import IS31FL3731
32+
33+
34+
class CharlieBonnet(IS31FL3731):
35+
"""Supports the Charlieplexed bonnet"""
36+
37+
width = 16
38+
height = 8
39+
40+
@staticmethod
41+
def pixel_addr(x, y):
42+
"""Calulate the offset into the device array for x,y pixel"""
43+
if x >= 8:
44+
return (x - 6) * 16 - (y + 1)
45+
return (x + 1) * 16 + (7 - y)

adafruit_is31fl3731/charlie_wing.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# SPDX-FileCopyrightText: Tony DiCola 2017 for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
`adafruit_is31fl3731.charlie_wing`
7+
====================================================
8+
9+
CircuitPython driver for the IS31FL3731 charlieplex IC.
10+
11+
12+
* Author(s): Tony DiCola, Melissa LeBlanc-Williams
13+
14+
Implementation Notes
15+
--------------------
16+
17+
**Hardware:**
18+
19+
* `Adafruit 15x7 CharliePlex LED Matrix Display FeatherWings
20+
<https://www.adafruit.com/product/2965>`_
21+
22+
**Software and Dependencies:**
23+
24+
* Adafruit CircuitPython firmware for the supported boards:
25+
https://github.com/adafruit/circuitpython/releases
26+
27+
"""
28+
29+
# imports
30+
from . import IS31FL3731
31+
32+
33+
class CharlieWing(IS31FL3731):
34+
"""Supports the Charlieplexed feather wing"""
35+
36+
width = 15
37+
height = 7
38+
39+
@staticmethod
40+
def pixel_addr(x, y):
41+
"""Calulate the offset into the device array for x,y pixel"""
42+
if x > 7:
43+
x = 15 - x
44+
y += 8
45+
else:
46+
y = 7 - y
47+
return x * 16 + y

0 commit comments

Comments
 (0)