From 4c33f50fda33b4baa1e16b6f9903569d61aa924f Mon Sep 17 00:00:00 2001 From: "E. A. Graham Jr" <10370165+EAGrahamJr@users.noreply.github.com> Date: Thu, 16 Feb 2023 13:42:49 -0800 Subject: [PATCH 1/8] Return from fade on "None" Fixes #52 with a return when both fade params are `None`. Also updates the default pause value to not throw math errors on `0`. (Added another `venv` variation to the ..gitignore) Note: the values in the doc are incorrect; the functionality doesn't seem to be suppoted on the shim or this isn't working as expected. --- .gitignore | 1 + adafruit_is31fl3731/__init__.py | 4 ++-- examples/is31fl3731_ledshim_fade.py | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 examples/is31fl3731_ledshim_fade.py diff --git a/.gitignore b/.gitignore index db3d538..546a827 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ _build # Virtual environment-specific files .env .venv +venv # MacOS-specific files *.DS_Store diff --git a/adafruit_is31fl3731/__init__.py b/adafruit_is31fl3731/__init__.py index c8cd30c..be47d47 100644 --- a/adafruit_is31fl3731/__init__.py +++ b/adafruit_is31fl3731/__init__.py @@ -190,7 +190,7 @@ def autoplay(self, delay=0, loops=0, frames=0): self._register(_CONFIG_BANK, _AUTOPLAY2_REGISTER, delay % 64) self._mode(_AUTOPLAY_MODE | self._frame) - def fade(self, fade_in=None, fade_out=None, pause=0): + def fade(self, fade_in=None, fade_out=None, pause=26): """ Start and stop the fade feature. If both fade_in and fade_out are None (the default), the breath feature is used for fading. if fade_in is None, then @@ -201,7 +201,7 @@ def fade(self, fade_in=None, fade_out=None, pause=0): :param pause: breath register 2 pause value """ if fade_in is None and fade_out is None: - self._register(_CONFIG_BANK, _BREATH2_REGISTER, 0) + return self._register(_CONFIG_BANK, _BREATH2_REGISTER, 0) elif fade_in is None: fade_in = fade_out elif fade_out is None: diff --git a/examples/is31fl3731_ledshim_fade.py b/examples/is31fl3731_ledshim_fade.py new file mode 100644 index 0000000..ac3837c --- /dev/null +++ b/examples/is31fl3731_ledshim_fade.py @@ -0,0 +1,25 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + +import time +import board +import busio +from adafruit_is31fl3731.led_shim import LedShim as Display + +i2c = busio.I2C(board.SCL, board.SDA) + +# initial display if you are using Pimoroni LED SHIM +display = Display(i2c) + +y = 1 +for x in range(28): + display.pixel(x, y, 255) + + +try: + display.fade(fade_in=100, pause=26) + while True: + time.sleep(1) +except: + display.sleep(True) + exit From 9693a2fde137b493312037234c135f2bf6e82abe Mon Sep 17 00:00:00 2001 From: "E. A. Graham Jr" <10370165+EAGrahamJr@users.noreply.github.com> Date: Thu, 16 Feb 2023 13:47:16 -0800 Subject: [PATCH 2/8] Simple example to run fade - doesn't seem to actually do anything --- examples/is31fl3731_ledshim_fade.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/is31fl3731_ledshim_fade.py b/examples/is31fl3731_ledshim_fade.py index ac3837c..1aa0d80 100644 --- a/examples/is31fl3731_ledshim_fade.py +++ b/examples/is31fl3731_ledshim_fade.py @@ -15,11 +15,11 @@ for x in range(28): display.pixel(x, y, 255) +display.fade(fade_in=104, pause=250) try: - display.fade(fade_in=100, pause=26) while True: - time.sleep(1) + time.sleep(10) except: display.sleep(True) exit From 70413400dccb8c2062f3749b6d5c91816e76e6e5 Mon Sep 17 00:00:00 2001 From: "E. A. (Ed) Graham, Jr" <10370165+EAGrahamJr@users.noreply.github.com> Date: Fri, 17 Feb 2023 09:08:24 -0800 Subject: [PATCH 3/8] Add author info --- adafruit_is31fl3731/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_is31fl3731/__init__.py b/adafruit_is31fl3731/__init__.py index be47d47..f8a8f9f 100644 --- a/adafruit_is31fl3731/__init__.py +++ b/adafruit_is31fl3731/__init__.py @@ -10,7 +10,7 @@ Base library. -* Author(s): Tony DiCola, Melissa LeBlanc-Williams, David Glaude +* Author(s): Tony DiCola, Melissa LeBlanc-Williams, David Glaude, E. A. Graham Jr. Implementation Notes -------------------- From 855ed3c3481b6cb61795c4a830e7e1a5a23f5ac7 Mon Sep 17 00:00:00 2001 From: "E. A. (Ed) Graham, Jr" <10370165+EAGrahamJr@users.noreply.github.com> Date: Fri, 17 Feb 2023 09:18:04 -0800 Subject: [PATCH 4/8] Fix pylint --- adafruit_is31fl3731/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/adafruit_is31fl3731/__init__.py b/adafruit_is31fl3731/__init__.py index f8a8f9f..0fbce45 100644 --- a/adafruit_is31fl3731/__init__.py +++ b/adafruit_is31fl3731/__init__.py @@ -201,8 +201,9 @@ def fade(self, fade_in=None, fade_out=None, pause=26): :param pause: breath register 2 pause value """ if fade_in is None and fade_out is None: - return self._register(_CONFIG_BANK, _BREATH2_REGISTER, 0) - elif fade_in is None: + self._register(_CONFIG_BANK, _BREATH2_REGISTER, 0) + return + if fade_in is None: fade_in = fade_out elif fade_out is None: fade_out = fade_in From d008291e03deaf56add9e93d8e1e395ead3635ee Mon Sep 17 00:00:00 2001 From: "E. A. Graham Jr" <10370165+EAGrahamJr@users.noreply.github.com> Date: Fri, 17 Feb 2023 09:42:24 -0800 Subject: [PATCH 5/8] Fix missing specific exception --- examples/is31fl3731_ledshim_fade.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/is31fl3731_ledshim_fade.py b/examples/is31fl3731_ledshim_fade.py index 1aa0d80..01c6390 100644 --- a/examples/is31fl3731_ledshim_fade.py +++ b/examples/is31fl3731_ledshim_fade.py @@ -20,6 +20,6 @@ try: while True: time.sleep(10) -except: +except KeyboardInterrupt: display.sleep(True) exit From e86d99e8fe92e54f28e5182d29f0db046e444c5e Mon Sep 17 00:00:00 2001 From: "E. A. Graham Jr" <10370165+EAGrahamJr@users.noreply.github.com> Date: Fri, 17 Feb 2023 09:45:31 -0800 Subject: [PATCH 6/8] Wow, this thing is picky --- examples/is31fl3731_ledshim_fade.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/is31fl3731_ledshim_fade.py b/examples/is31fl3731_ledshim_fade.py index 01c6390..fa8f809 100644 --- a/examples/is31fl3731_ledshim_fade.py +++ b/examples/is31fl3731_ledshim_fade.py @@ -22,4 +22,3 @@ time.sleep(10) except KeyboardInterrupt: display.sleep(True) - exit From fa7437c8eafc48c60c4946bd8ba55a6dba56d68f Mon Sep 17 00:00:00 2001 From: "E. A. Graham Jr" <10370165+EAGrahamJr@users.noreply.github.com> Date: Fri, 17 Feb 2023 09:50:23 -0800 Subject: [PATCH 7/8] I'll get this right eventually... --- adafruit_is31fl3731/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_is31fl3731/__init__.py b/adafruit_is31fl3731/__init__.py index 0fbce45..edd7224 100644 --- a/adafruit_is31fl3731/__init__.py +++ b/adafruit_is31fl3731/__init__.py @@ -202,7 +202,7 @@ def fade(self, fade_in=None, fade_out=None, pause=26): """ if fade_in is None and fade_out is None: self._register(_CONFIG_BANK, _BREATH2_REGISTER, 0) - return + return if fade_in is None: fade_in = fade_out elif fade_out is None: From 701cb1138ddd8fe7d7e285b0dbeb509e7a15bb27 Mon Sep 17 00:00:00 2001 From: "E. A. Graham Jr" <10370165+EAGrahamJr@users.noreply.github.com> Date: Tue, 21 Feb 2023 16:09:55 -0800 Subject: [PATCH 8/8] Refactor to cover all math errors --- adafruit_is31fl3731/__init__.py | 12 ++++++++---- examples/is31fl3731_ledshim_fade.py | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/adafruit_is31fl3731/__init__.py b/adafruit_is31fl3731/__init__.py index edd7224..49290a4 100644 --- a/adafruit_is31fl3731/__init__.py +++ b/adafruit_is31fl3731/__init__.py @@ -190,7 +190,7 @@ def autoplay(self, delay=0, loops=0, frames=0): self._register(_CONFIG_BANK, _AUTOPLAY2_REGISTER, delay % 64) self._mode(_AUTOPLAY_MODE | self._frame) - def fade(self, fade_in=None, fade_out=None, pause=26): + def fade(self, fade_in=None, fade_out=None, pause=0): """ Start and stop the fade feature. If both fade_in and fade_out are None (the default), the breath feature is used for fading. if fade_in is None, then @@ -207,9 +207,13 @@ def fade(self, fade_in=None, fade_out=None, pause=26): fade_in = fade_out elif fade_out is None: fade_out = fade_in - fade_in = int(math.log(fade_in / 26, 2)) - fade_out = int(math.log(fade_out / 26, 2)) - pause = int(math.log(pause / 26, 2)) + + if fade_in != 0: + fade_in = int(math.log(fade_in / 26, 2)) + if fade_out != 0: + fade_out = int(math.log(fade_out / 26, 2)) + if pause != 0: + pause = int(math.log(pause / 26, 2)) if not 0 <= fade_in <= 7: raise ValueError("Fade in out of range") if not 0 <= fade_out <= 7: diff --git a/examples/is31fl3731_ledshim_fade.py b/examples/is31fl3731_ledshim_fade.py index fa8f809..eb7ecda 100644 --- a/examples/is31fl3731_ledshim_fade.py +++ b/examples/is31fl3731_ledshim_fade.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2023 E. A. Graham, Jr. # SPDX-License-Identifier: MIT import time