Skip to content

Commit

Permalink
Merge pull request #38 from makermelissa/refactor
Browse files Browse the repository at this point in the history
Updated manual merge of all existing outstanding PRs
  • Loading branch information
makermelissa committed Mar 8, 2021
2 parents 52dad15 + 3fa3ffe commit a85d015
Show file tree
Hide file tree
Showing 22 changed files with 604 additions and 323 deletions.
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,23 @@ Matrix:

.. code:: python
import adafruit_is31fl3731
from adafruit_is31fl3731.matrix import Matrix
import board
import busio
with busio.I2C(board.SCL, board.SDA) as i2c:
display = adafruit_is31fl3731.Matrix(i2c)
display = Matrix(i2c)
display.fill(127)
Charlie Wing:

.. code:: python
import adafruit_is31fl3731
from adafruit_is31fl3731.charlie_wing import CharlieWing
import board
import busio
with busio.I2C(board.SCL, board.SDA) as i2c:
display = adafruit_is31fl3731.CharlieWing(i2c)
display = CharlieWing(i2c)
display.fill(127)
# Turn off pixel 4,4, change its brightness and turn it back on
Expand Down
221 changes: 24 additions & 197 deletions adafruit_is31fl3731.py → adafruit_is31fl3731/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
CircuitPython driver for the IS31FL3731 charlieplex IC.
Base library.
* Author(s): Tony DiCola, Melissa LeBlanc-Williams
* Author(s): Tony DiCola, Melissa LeBlanc-Williams, David Glaude
Implementation Notes
--------------------
Expand All @@ -22,16 +23,29 @@
* `Adafruit 15x7 CharliePlex LED Matrix Display FeatherWings
<https://www.adafruit.com/product/2965>`_
* Pimoroni LED SHIM
<https://shop.pimoroni.com/products/led-shim>_
* `Adafruit 16x8 CharliePlex LED Matrix Bonnets
<https://www.adafruit.com/product/4127>`_
* Pimoroni Keybow 2040
<https://shop.pimoroni.com/products/keybow-2040>_
* `Pimoroni 17x7 Scroll pHAT HD
<https://www.adafruit.com/product/3473>`_
* `Pimoroni 28x3 (r,g,b) Led Shim
<https://www.adafruit.com/product/3831>`_
* `Pimoroni LED SHIM
<https://shop.pimoroni.com/products/led-shim>`_
* `Pimoroni Keybow 2040
<https://shop.pimoroni.com/products/keybow-2040>`_
* `Pimoroni 11x7 LED Matrix Breakout
<https://shop.pimoroni.com/products/11x7-led-matrix-breakout>`_
**Software and Dependencies:**
* Adafruit CircuitPython firmware (2.2.0+) for the ESP8622 and M0-based boards:
* Adafruit CircuitPython firmware for the supported boards:
https://github.com/adafruit/circuitpython/releases
"""

# imports
Expand Down Expand Up @@ -66,9 +80,10 @@
_COLOR_OFFSET = const(0x24)


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

# This function must be replaced for each board
@staticmethod
def pixel_addr(x, y):
"""Calulate the offset into the device array for x,y pixel"""
Expand Down Expand Up @@ -348,192 +364,3 @@ def image(self, img, blink=None, frame=None):
for x in range(self.width): # yes this double loop is slow,
for y in range(self.height): # but these displays are small!
self.pixel(x, y, pixels[(x, y)], blink=blink, frame=frame)


class CharlieWing(Matrix):
"""Supports the Charlieplexed feather wing"""

width = 15
height = 7

@staticmethod
def pixel_addr(x, y):
"""Calulate the offset into the device array for x,y pixel"""
if x > 7:
x = 15 - x
y += 8
else:
y = 7 - y
return x * 16 + y


class CharlieBonnet(Matrix):
"""Supports the Charlieplexed bonnet"""

width = 16
height = 8

@staticmethod
def pixel_addr(x, y):
"""Calulate the offset into the device array for x,y pixel"""
if x >= 8:
return (x - 6) * 16 - (y + 1)
return (x + 1) * 16 + (7 - y)


class ScrollPhatHD(Matrix):
"""Supports the Scroll pHAT HD by Pimoroni"""

width = 17
height = 7

@staticmethod
def pixel_addr(x, y):
"""Translate an x,y coordinate to a pixel index."""
if x <= 8:
x = 8 - x
y = 6 - y
else:
x = x - 8
y = y - 8
return x * 16 + y


class LedShim(Matrix):
"""Supports the LED SHIM by Pimoroni"""

width = 28
height = 3

def __init__(self, i2c, address=0x75):
super().__init__(i2c, address)

# pylint: disable-msg=too-many-arguments
def pixelrgb(self, x, r, g, b, blink=None, frame=None):
"""
Blink or brightness for x-pixel
:param x: horizontal pixel position
:param r: red brightness value 0->255
:param g: green brightness value 0->255
:param b: blue brightness value 0->255
:param blink: True to blink
:param frame: the frame to set the pixel
"""
super().pixel(x, 0, r, blink, frame)
super().pixel(x, 1, g, blink, frame)
super().pixel(x, 2, b, blink, frame)

# pylint: disable=inconsistent-return-statements
# pylint: disable=too-many-return-statements
# pylint: disable=too-many-branches

@staticmethod
def pixel_addr(x, y):
"""Translate an x,y coordinate to a pixel index."""
if y == 0:
if x < 7:
return 118 - x
if x < 15:
return 141 - x
if x < 21:
return 106 + x
if x == 21:
return 15
return x - 14

if y == 1:
if x < 2:
return 69 - x
if x < 7:
return 86 - x
if x < 12:
return 28 - x
if x < 14:
return 45 - x
if x == 14:
return 47
if x == 15:
return 41
if x < 21:
return x + 9
if x == 21:
return 95
if x < 26:
return x + 67
return x + 50

if x == 0:
return 85
if x < 7:
return 102 - x
if x < 11:
return 44 - x
if x < 14:
return 61 - x
if x == 14:
return 63
if x < 17:
return 42 + x
if x < 21:
return x + 25
if x == 21:
return 111
if x < 27:
return x + 83
return 93


class Keybow2040(Matrix):
"""Supports the Pimoroni Keybow 2040 with 4x4 matrix of RGB LEDs """

width = 16
height = 3

# pylint: disable=too-many-arguments

def pixelrgb(self, x, y, r, g, b, blink=None, frame=None):
"""
Blink or brightness for x, y-pixel
:param x: horizontal pixel position
:param y: vertical pixel position
:param r: red brightness value 0->255
:param g: green brightness value 0->255
:param b: blue brightness value 0->255
:param blink: True to blink
:param frame: the frame to set the pixel
"""
x = x + (4 * y)

super().pixel(x, 0, r, blink, frame)
super().pixel(x, 1, g, blink, frame)
super().pixel(x, 2, b, blink, frame)

# pylint: disable=inconsistent-return-statements
# pylint: disable=too-many-return-statements
# pylint: disable=too-many-branches

@staticmethod
def pixel_addr(x, y):

lookup = [
(120, 88, 104), # 0, 0
(136, 40, 72), # 1, 0
(112, 80, 96), # 2, 0
(128, 32, 64), # 3, 0
(121, 89, 105), # 0, 1
(137, 41, 73), # 1, 1
(113, 81, 97), # 2, 1
(129, 33, 65), # 3, 1
(122, 90, 106), # 0, 2
(138, 25, 74), # 1, 2
(114, 82, 98), # 2, 2
(130, 17, 66), # 3, 2
(123, 91, 107), # 0, 3
(139, 26, 75), # 1, 3
(115, 83, 99), # 2, 3
(131, 18, 67), # 3, 3
]

return lookup[x][y]
45 changes: 45 additions & 0 deletions adafruit_is31fl3731/charlie_bonnet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# SPDX-FileCopyrightText: Tony DiCola 2017 for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
`adafruit_is31fl3731.charlie_bonnet`
====================================================
CircuitPython driver for the IS31FL3731 charlieplex IC.
* Author(s): Tony DiCola, Melissa LeBlanc-Williams
Implementation Notes
--------------------
**Hardware:**
* `Adafruit 16x8 CharliePlex LED Matrix Bonnets
<https://www.adafruit.com/product/4127>`_
**Software and Dependencies:**
* Adafruit CircuitPython firmware for the supported boards:
https://github.com/adafruit/circuitpython/releases
"""

# imports
from . import IS31FL3731


class CharlieBonnet(IS31FL3731):
"""Supports the Charlieplexed bonnet"""

width = 16
height = 8

@staticmethod
def pixel_addr(x, y):
"""Calulate the offset into the device array for x,y pixel"""
if x >= 8:
return (x - 6) * 16 - (y + 1)
return (x + 1) * 16 + (7 - y)
47 changes: 47 additions & 0 deletions adafruit_is31fl3731/charlie_wing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# SPDX-FileCopyrightText: Tony DiCola 2017 for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
`adafruit_is31fl3731.charlie_wing`
====================================================
CircuitPython driver for the IS31FL3731 charlieplex IC.
* Author(s): Tony DiCola, Melissa LeBlanc-Williams
Implementation Notes
--------------------
**Hardware:**
* `Adafruit 15x7 CharliePlex LED Matrix Display FeatherWings
<https://www.adafruit.com/product/2965>`_
**Software and Dependencies:**
* Adafruit CircuitPython firmware for the supported boards:
https://github.com/adafruit/circuitpython/releases
"""

# imports
from . import IS31FL3731


class CharlieWing(IS31FL3731):
"""Supports the Charlieplexed feather wing"""

width = 15
height = 7

@staticmethod
def pixel_addr(x, y):
"""Calulate the offset into the device array for x,y pixel"""
if x > 7:
x = 15 - x
y += 8
else:
y = 7 - y
return x * 16 + y

0 comments on commit a85d015

Please sign in to comment.