From 1190ffe24474f9a6963177c752cadc33f20ff136 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Mon, 28 Sep 2020 15:58:53 -0500 Subject: [PATCH 01/88] Initial commit --- adafruit_led_animation/animation/volume.py | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 adafruit_led_animation/animation/volume.py diff --git a/adafruit_led_animation/animation/volume.py b/adafruit_led_animation/animation/volume.py new file mode 100644 index 0000000..85bcd7a --- /dev/null +++ b/adafruit_led_animation/animation/volume.py @@ -0,0 +1,38 @@ +from adafruit_led_animation.animation import Animation + +class Volume(Animation): + """ + Animate the brightness and number of pixels based on volume. + :param pixel_object: The initialised LED object. + :param float speed: Animation update speed in seconds, e.g. ``0.1``. + :param brightest_color: Color at max volume ``(r, g, b)`` tuple, or ``0x000000`` hex format + """ + + def __init__(self, pixel_object, speed, brightest_color, decoder, max_volume=500, name=None): + self._decoder = decoder + self._num_pixels = len(pixel_object) + self._max_volume = max_volume + self._brigthest_color = brightest_color + super().__init__(pixel_object, speed, brightest_color, name=name) + + def _set_color(self, brightest_color): + self.colors = [brightest_color] + + def map_range(self, x, in_min, in_max, out_min, out_max): + mapped = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min + if out_min <= out_max: + return max(min(mapped, out_max), out_min) + + return min(max(mapped, out_max), out_min) + + def draw(self): + red = int(self.map_range(self._decoder.rms_level, 0, self._max_volume, 0, self._brigthest_color[0])) + green = int(self.map_range(self._decoder.rms_level, 0, self._max_volume, 0, self._brigthest_color[1])) + blue = int(self.map_range(self._decoder.rms_level, 0, self._max_volume, 0, self._brigthest_color[2])) + + lit_pixels = int(self.map_range(self._decoder.rms_level, 0, self._max_volume, 0, self._num_pixels)) + if lit_pixels > self._num_pixels: + lit_pixels = self._num_pixels + + self.pixel_object[0:lit_pixels] = [(red,green,blue)] * lit_pixels + self.pixel_object[lit_pixels:self._num_pixels] = [(0,0,0)] * (self._num_pixels-lit_pixels) From d12b7fb50b74aabfc603b710a39bac6e78fa5533 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Mon, 28 Sep 2020 16:03:36 -0500 Subject: [PATCH 02/88] Added license and documentation --- adafruit_led_animation/animation/volume.py | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/adafruit_led_animation/animation/volume.py b/adafruit_led_animation/animation/volume.py index 85bcd7a..6d61bdb 100644 --- a/adafruit_led_animation/animation/volume.py +++ b/adafruit_led_animation/animation/volume.py @@ -1,3 +1,37 @@ +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +""" +`adafruit_led_animation.animation.volume` +================================================================================ +Volume animation for CircuitPython helper library for LED animations. +* Author(s): Mark Komus +Implementation Notes +-------------------- +**Hardware:** +* `Adafruit NeoPixels `_ +* `Adafruit DotStars `_ +**Software and Dependencies:** +* Adafruit CircuitPython firmware for the supported boards: + https://circuitpython.org/downloads +""" + from adafruit_led_animation.animation import Animation class Volume(Animation): @@ -6,6 +40,8 @@ class Volume(Animation): :param pixel_object: The initialised LED object. :param float speed: Animation update speed in seconds, e.g. ``0.1``. :param brightest_color: Color at max volume ``(r, g, b)`` tuple, or ``0x000000`` hex format + :param decoder: a MP3Decoder object that the volume will be taken from + :param float max_volume: what volume is considered maximum where everything is lit up """ def __init__(self, pixel_object, speed, brightest_color, decoder, max_volume=500, name=None): From eb86bf0b4eb038a4c1d1a47bb171af4099d569e2 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Mon, 28 Sep 2020 16:32:30 -0500 Subject: [PATCH 03/88] Fixed errors from pylint and black --- adafruit_led_animation/animation/volume.py | 76 +++++++++++++++++----- 1 file changed, 59 insertions(+), 17 deletions(-) diff --git a/adafruit_led_animation/animation/volume.py b/adafruit_led_animation/animation/volume.py index 6d61bdb..5827ba1 100644 --- a/adafruit_led_animation/animation/volume.py +++ b/adafruit_led_animation/animation/volume.py @@ -34,6 +34,20 @@ from adafruit_led_animation.animation import Animation + +def map_range(x, in_min, in_max, out_min, out_max): + """ + Maps a number from one range to another. + :return: Returns value mapped to new range + :rtype: float + """ + mapped = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min + if out_min <= out_max: + return max(min(mapped, out_max), out_min) + + return min(max(mapped, out_max), out_min) + + class Volume(Animation): """ Animate the brightness and number of pixels based on volume. @@ -44,31 +58,59 @@ class Volume(Animation): :param float max_volume: what volume is considered maximum where everything is lit up """ - def __init__(self, pixel_object, speed, brightest_color, decoder, max_volume=500, name=None): + # pylint: disable=too-many-arguments + def __init__( + self, pixel_object, speed, brightest_color, decoder, max_volume=500, name=None + ): self._decoder = decoder self._num_pixels = len(pixel_object) self._max_volume = max_volume - self._brigthest_color = brightest_color + self._brightest_color = brightest_color super().__init__(pixel_object, speed, brightest_color, name=name) - def _set_color(self, brightest_color): - self.colors = [brightest_color] - - def map_range(self, x, in_min, in_max, out_min, out_max): - mapped = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min - if out_min <= out_max: - return max(min(mapped, out_max), out_min) - - return min(max(mapped, out_max), out_min) + def set_brightest_color(self, brightest_color): + """ + Animate the brightness and number of pixels based on volume. + :param brightest_color: Color at max volume ``(r, g, b)`` tuple, or ``0x000000`` hex format + """ + self._brightest_color = brightest_color def draw(self): - red = int(self.map_range(self._decoder.rms_level, 0, self._max_volume, 0, self._brigthest_color[0])) - green = int(self.map_range(self._decoder.rms_level, 0, self._max_volume, 0, self._brigthest_color[1])) - blue = int(self.map_range(self._decoder.rms_level, 0, self._max_volume, 0, self._brigthest_color[2])) + red = int( + map_range( + self._decoder.rms_level, + 0, + self._max_volume, + 0, + self._brightest_color[0], + ) + ) + green = int( + map_range( + self._decoder.rms_level, + 0, + self._max_volume, + 0, + self._brightest_color[1], + ) + ) + blue = int( + map_range( + self._decoder.rms_level, + 0, + self._max_volume, + 0, + self._brightest_color[2], + ) + ) - lit_pixels = int(self.map_range(self._decoder.rms_level, 0, self._max_volume, 0, self._num_pixels)) + lit_pixels = int( + map_range(self._decoder.rms_level, 0, self._max_volume, 0, self._num_pixels) + ) if lit_pixels > self._num_pixels: lit_pixels = self._num_pixels - self.pixel_object[0:lit_pixels] = [(red,green,blue)] * lit_pixels - self.pixel_object[lit_pixels:self._num_pixels] = [(0,0,0)] * (self._num_pixels-lit_pixels) + self.pixel_object[0:lit_pixels] = [(red, green, blue)] * lit_pixels + self.pixel_object[lit_pixels : self._num_pixels] = [(0, 0, 0)] * ( + self._num_pixels - lit_pixels + ) From 766b22615336808f0c339f02e874c90310bd8f4b Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Mon, 28 Sep 2020 17:08:26 -0500 Subject: [PATCH 04/88] Initial commit --- adafruit_led_animation/timedsequence.py | 100 ++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 adafruit_led_animation/timedsequence.py diff --git a/adafruit_led_animation/timedsequence.py b/adafruit_led_animation/timedsequence.py new file mode 100644 index 0000000..cc97f9a --- /dev/null +++ b/adafruit_led_animation/timedsequence.py @@ -0,0 +1,100 @@ +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +""" +`adafruit_led_animation.timedsequence` +================================================================================ + +Animation timed sequence helper for CircuitPython helper library for LED animations. + + +* Author(s): Mark Komus + +Implementation Notes +-------------------- + +**Hardware:** + +* `Adafruit NeoPixels `_ +* `Adafruit DotStars `_ + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://circuitpython.org/downloads + +""" + +from adafruit_led_animation.sequence import AnimationSequence +from . import MS_PER_SECOND + + +class TimedAnimationSequence(AnimationSequence): + """ + A sequence of Animations to run in succession, each animation running for an + individual amount of time. + :param members: The animation objects or groups followed by how long the animation + should run in seconds. + :param bool auto_clear: Clear the pixels between animations. If ``True``, the current animation + will be cleared from the pixels before the next one starts. + Defaults to ``False``. + :param bool random_order: Activate the animations in a random order. Defaults to ``False``. + :param bool auto_reset: Automatically call reset() on animations when changing animations. + .. code-block:: python + import board + import neopixel + from adafruit_led_animation.timedsequence import TimedAnimationSequence + import adafruit_led_animation.animation.comet as comet_animation + import adafruit_led_animation.animation.sparkle as sparkle_animation + import adafruit_led_animation.animation.blink as blink_animation + import adafruit_led_animation.color as color + strip_pixels = neopixel.NeoPixel(board.A1, 30, brightness=1, auto_write=False) + blink = blink_animation.Blink(strip_pixels, 0.2, color.RED) + comet = comet_animation.Comet(strip_pixels, 0.1, color.BLUE) + sparkle = sparkle_animation.Sparkle(strip_pixels, 0.05, color.GREEN) + animations = AnimationSequence(blink, 5, comet, 3, sparkle, 7) + while True: + animations.animate() + """ + + # pylint: disable=too-many-instance-attributes + def __init__( + self, *members, auto_clear=True, random_order=False, auto_reset=False, name=None + ): + self._animation_members = [] + self._animation_timings = [] + for x, item in enumerate(members): + if not x % 2: + self._animation_members.append(item) + else: + self._animation_timings.append(item) + + super().__init__( + *self._animation_members, + auto_clear=auto_clear, + random_order=random_order, + auto_reset=auto_reset, + advance_on_cycle_complete=False, + name=name + ) + self._advance_interval = self._animation_timings[self._current] * MS_PER_SECOND + + def activate(self, index): + super().activate(index) + self._advance_interval = self._animation_timings[self._current] * MS_PER_SECOND From 27f313650b337092e240273417cfb4f60b20cb52 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Mon, 28 Sep 2020 17:10:29 -0500 Subject: [PATCH 05/88] Fixed example code --- adafruit_led_animation/timedsequence.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_led_animation/timedsequence.py b/adafruit_led_animation/timedsequence.py index cc97f9a..f4530dd 100644 --- a/adafruit_led_animation/timedsequence.py +++ b/adafruit_led_animation/timedsequence.py @@ -68,7 +68,7 @@ class TimedAnimationSequence(AnimationSequence): blink = blink_animation.Blink(strip_pixels, 0.2, color.RED) comet = comet_animation.Comet(strip_pixels, 0.1, color.BLUE) sparkle = sparkle_animation.Sparkle(strip_pixels, 0.05, color.GREEN) - animations = AnimationSequence(blink, 5, comet, 3, sparkle, 7) + animations = TimedAnimationSequence(blink, 5, comet, 3, sparkle, 7) while True: animations.animate() """ From 63ab8dae843947f7b9f39f937150d17435082158 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Mon, 28 Sep 2020 19:09:44 -0500 Subject: [PATCH 06/88] Fixed black error --- adafruit_led_animation/timedsequence.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_led_animation/timedsequence.py b/adafruit_led_animation/timedsequence.py index f4530dd..42773c6 100644 --- a/adafruit_led_animation/timedsequence.py +++ b/adafruit_led_animation/timedsequence.py @@ -91,7 +91,7 @@ def __init__( random_order=random_order, auto_reset=auto_reset, advance_on_cycle_complete=False, - name=name + name=name, ) self._advance_interval = self._animation_timings[self._current] * MS_PER_SECOND From 4b2cb10efc1a961d047a45beb46fcb1f1525e91f Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 23 Nov 2021 13:14:31 -0600 Subject: [PATCH 07/88] update rtd py version --- .readthedocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 95ec218..1335112 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -9,7 +9,7 @@ version: 2 python: - version: "3.6" + version: "3.7" install: - requirements: docs/requirements.txt - requirements: requirements.txt From e296e6f67a3689b28a6d65d4c48a139e1398faba Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Tue, 21 Dec 2021 11:17:31 -0500 Subject: [PATCH 08/88] Remove specific Python, use 3.x --- .github/workflows/build.yml | 6 +++--- .github/workflows/release.yml | 8 ++++---- .readthedocs.yaml | 2 +- docs/conf.py | 2 +- setup.py | 2 -- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ca35544..474520d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,10 +22,10 @@ jobs: awk -F '\/' '{ print tolower($2) }' | tr '_' '-' ) - - name: Set up Python 3.7 - uses: actions/setup-python@v1 + - name: Set up Python 3.x + uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: "3.x" - name: Versions run: | python3 --version diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6d0015a..a65e5de 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,10 +24,10 @@ jobs: awk -F '\/' '{ print tolower($2) }' | tr '_' '-' ) - - name: Set up Python 3.6 - uses: actions/setup-python@v1 + - name: Set up Python 3.x + uses: actions/setup-python@v2 with: - python-version: 3.6 + python-version: "3.x" - name: Versions run: | python3 --version @@ -67,7 +67,7 @@ jobs: echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) - name: Set up Python if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: '3.x' - name: Install dependencies diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 1335112..f8b2891 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -9,7 +9,7 @@ version: 2 python: - version: "3.7" + version: "3.x" install: - requirements: docs/requirements.txt - requirements: requirements.txt diff --git a/docs/conf.py b/docs/conf.py index ded1695..79d3bf3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -29,7 +29,7 @@ intersphinx_mapping = { - "python": ("https://docs.python.org/3.4", None), + "python": ("https://docs.python.org/3", None), "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), } diff --git a/setup.py b/setup.py index 7a2e0b9..9693e76 100644 --- a/setup.py +++ b/setup.py @@ -46,8 +46,6 @@ "Topic :: System :: Hardware", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.4", - "Programming Language :: Python :: 3.5", ], # What does your project relate to? keywords="adafruit blinka circuitpython micropython led animation led colors animations", From 6fb700333b279005ef20965aedfc1057ebd14180 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 10 Jan 2022 23:07:11 -0500 Subject: [PATCH 09/88] Update README to use adafruit_led_animation.animation.blink --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 6a8c1e1..981830d 100644 --- a/README.rst +++ b/README.rst @@ -57,7 +57,7 @@ Usage Example import board import neopixel - from adafruit_led_animation.animation import Blink + from adafruit_led_animation.animation.blink import Blink import adafruit_led_animation.color as color # Works on Circuit Playground Express and Bluefruit. From 7892d09962b662fc0a702e0aaca6fb1b7cc7e476 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 24 Jan 2022 16:46:16 -0500 Subject: [PATCH 10/88] Updated docs link, updated python docs link, updated setup.py --- README.rst | 4 ++-- docs/conf.py | 2 +- docs/index.rst | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 981830d..830f70e 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ Introduction ============ .. image:: https://readthedocs.org/projects/adafruit_circuitpython_led_animation/badge/?version=latest - :target: https://circuitpython.readthedocs.io/projects/led-animation/en/latest/ + :target: https://docs.circuitpython.org/projects/led-animation/en/latest/ :alt: Documentation Status .. image:: https://img.shields.io/discord/327254708534116352.svg @@ -75,7 +75,7 @@ Usage Example Documentation ============= -API documentation for this library can be found on `Read the Docs `_. +API documentation for this library can be found on `Read the Docs `_. Contributing ============ diff --git a/docs/conf.py b/docs/conf.py index 79d3bf3..83db1bc 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -30,7 +30,7 @@ intersphinx_mapping = { "python": ("https://docs.python.org/3", None), - "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), + "CircuitPython": ("https://docs.circuitpython.org/en/latest/", None), } # Add any paths that contain templates here, relative to this directory. diff --git a/docs/index.rst b/docs/index.rst index 23d7f74..1d10e2c 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -37,7 +37,7 @@ Table of Contents :caption: Other Links Download - CircuitPython Reference Documentation + CircuitPython Reference Documentation CircuitPython Support Forum Discord Chat Adafruit Learning System From 376c9e1f8bcaf72ea641d84debf0e31003f3b786 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 1 Feb 2022 21:52:48 -0500 Subject: [PATCH 11/88] Add examples for freezing, resuming, and cycling animations via push button --- examples/led_animation_cycle_animations.py | 45 ++++++++++++++++++++++ examples/led_animation_freeze_animation.py | 38 ++++++++++++++++++ examples/led_animation_resume_animation.py | 40 +++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 examples/led_animation_cycle_animations.py create mode 100644 examples/led_animation_freeze_animation.py create mode 100644 examples/led_animation_resume_animation.py diff --git a/examples/led_animation_cycle_animations.py b/examples/led_animation_cycle_animations.py new file mode 100644 index 0000000..6954a3b --- /dev/null +++ b/examples/led_animation_cycle_animations.py @@ -0,0 +1,45 @@ +# SPDX-FileCopyrightText: 2021 Alec Delaney +# SPDX-License-Identifier: MIT + +""" +This example uses AnimationsSequence along with a connected push button to cycle through +two animations + +For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using +a different form of NeoPixels. +""" +import board +import time +import neopixel +from digitalio import DigitalInOut, Direction, Pull + +from adafruit_led_animation.animation.solid import Solid +from adafruit_led_animation.sequence import AnimationSequence +from adafruit_led_animation.color import RED, BLUE + +# Update to match the pin connected to your NeoPixels +pixel_pin = board.D6 +# Update to match the number of NeoPixels you have connected +pixel_num = 32 + +# Update to matchpin connected to button that connect logic high when pushed +button_pin = board.D3 + +pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False) +button = DigitalInOut(button_pin) +button.direction = Direction.INPUT +button.pull = Pull.DOWN + +solid_blue = Solid(pixels, color=BLUE) +solid_red = Solid(pixels, color=RED) +animation_sequence = AnimationSequence(solid_blue, solid_red, auto_clear=True) + +while True: + animation_sequence.animate() + + # Pressing the button pauses the animation permanently + if button.value: + animation_sequence.next() + while button.value: + time.sleep(0.1) # Used for button debouncing + \ No newline at end of file diff --git a/examples/led_animation_freeze_animation.py b/examples/led_animation_freeze_animation.py new file mode 100644 index 0000000..ddc0f46 --- /dev/null +++ b/examples/led_animation_freeze_animation.py @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: 2021 Alec Delaney +# SPDX-License-Identifier: MIT + +""" +This example uses Pulse animation along with a connected push button to freeze +the animation permanently when pressed + +For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using +a different form of NeoPixels. +""" +import board +import neopixel +from digitalio import DigitalInOut, Direction, Pull + +from adafruit_led_animation.animation.pulse import Pulse +from adafruit_led_animation.color import RED + +# Update to match the pin connected to your NeoPixels +pixel_pin = board.D6 +# Update to match the number of NeoPixels you have connected +pixel_num = 32 + +# Update to matchpin connected to button that connect logic high when pushed +button_pin = board.D3 + +pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False) +button = DigitalInOut(button_pin) +button.direction = Direction.INPUT +button.pull = Pull.DOWN + +pulse_animation = Pulse(pixels, speed=0.1, period=1, color=RED) + +while True: + pulse_animation.animate() + + # Pressing the button pauses the animation permanently + if button.value: + pulse_animation.freeze() diff --git a/examples/led_animation_resume_animation.py b/examples/led_animation_resume_animation.py new file mode 100644 index 0000000..5c5f24d --- /dev/null +++ b/examples/led_animation_resume_animation.py @@ -0,0 +1,40 @@ +# SPDX-FileCopyrightText: 2021 Alec Delaney +# SPDX-License-Identifier: MIT + +""" +This example uses Pulse animation along with a connected push button to start +the animation when pressed + +For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using +a different form of NeoPixels. +""" +import board +import neopixel +from digitalio import DigitalInOut, Direction, Pull + +from adafruit_led_animation.animation.pulse import Pulse +from adafruit_led_animation.color import RED + +# Update to match the pin connected to your NeoPixels +pixel_pin = board.D6 +# Update to match the number of NeoPixels you have connected +pixel_num = 32 + +# Update to matchpin connected to button that connect logic high when pushed +button_pin = board.D3 + +pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False) +button = DigitalInOut(button_pin) +button.direction = Direction.INPUT +button.pull = Pull.DOWN + +# Create the animation and freeze it afterwards +pulse_animation = Pulse(pixels, speed=0.1, period=1, color=RED) +pulse_animation.freeze() + +while True: + pulse_animation.animate() + + # Pressing the button resumes (or in this case starts) the animation permanently + if button.value: + pulse_animation.resume() From d33a887bf4bf06eeb9dae6b3958397e67f613235 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 1 Feb 2022 21:55:58 -0500 Subject: [PATCH 12/88] Reformatted per pre-commit --- examples/led_animation_cycle_animations.py | 3 +-- examples/led_animation_resume_animation.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/led_animation_cycle_animations.py b/examples/led_animation_cycle_animations.py index 6954a3b..800762c 100644 --- a/examples/led_animation_cycle_animations.py +++ b/examples/led_animation_cycle_animations.py @@ -41,5 +41,4 @@ if button.value: animation_sequence.next() while button.value: - time.sleep(0.1) # Used for button debouncing - \ No newline at end of file + time.sleep(0.1) # Used for button debouncing diff --git a/examples/led_animation_resume_animation.py b/examples/led_animation_resume_animation.py index 5c5f24d..b7121da 100644 --- a/examples/led_animation_resume_animation.py +++ b/examples/led_animation_resume_animation.py @@ -30,7 +30,7 @@ # Create the animation and freeze it afterwards pulse_animation = Pulse(pixels, speed=0.1, period=1, color=RED) -pulse_animation.freeze() +pulse_animation.freeze() while True: pulse_animation.animate() From 0fe08ed65fa0ee53c39bc6081f04af96f668fe44 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 1 Feb 2022 22:00:46 -0500 Subject: [PATCH 13/88] Swap import order for cycle example --- examples/led_animation_cycle_animations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/led_animation_cycle_animations.py b/examples/led_animation_cycle_animations.py index 800762c..49cd9b5 100644 --- a/examples/led_animation_cycle_animations.py +++ b/examples/led_animation_cycle_animations.py @@ -8,8 +8,8 @@ For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using a different form of NeoPixels. """ -import board import time +import board import neopixel from digitalio import DigitalInOut, Direction, Pull From c203abdd7f9c4a443528d88d61ec83f872643114 Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Thu, 10 Feb 2022 12:25:29 -0500 Subject: [PATCH 14/88] Post-patch cleanup Added link for info on building library documentation --- README.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.rst b/README.rst index 830f70e..ee9154c 100644 --- a/README.rst +++ b/README.rst @@ -77,6 +77,8 @@ Documentation API documentation for this library can be found on `Read the Docs `_. +For information on building library documentation, please check out `this guide `_. + Contributing ============ From a50aea40295935cdf0e33f4bffb61bbdb4c91df9 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Fri, 11 Feb 2022 10:35:11 -0500 Subject: [PATCH 15/88] Invert button logic Per review, not all boards have pull down capability, so swapping the logic! --- examples/led_animation_cycle_animations.py | 4 ++-- examples/led_animation_freeze_animation.py | 4 ++-- examples/led_animation_resume_animation.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/led_animation_cycle_animations.py b/examples/led_animation_cycle_animations.py index 49cd9b5..d609b38 100644 --- a/examples/led_animation_cycle_animations.py +++ b/examples/led_animation_cycle_animations.py @@ -28,7 +28,7 @@ pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False) button = DigitalInOut(button_pin) button.direction = Direction.INPUT -button.pull = Pull.DOWN +button.pull = Pull.UP solid_blue = Solid(pixels, color=BLUE) solid_red = Solid(pixels, color=RED) @@ -38,7 +38,7 @@ animation_sequence.animate() # Pressing the button pauses the animation permanently - if button.value: + if not button.value: animation_sequence.next() while button.value: time.sleep(0.1) # Used for button debouncing diff --git a/examples/led_animation_freeze_animation.py b/examples/led_animation_freeze_animation.py index ddc0f46..cd8bc18 100644 --- a/examples/led_animation_freeze_animation.py +++ b/examples/led_animation_freeze_animation.py @@ -26,7 +26,7 @@ pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False) button = DigitalInOut(button_pin) button.direction = Direction.INPUT -button.pull = Pull.DOWN +button.pull = Pull.UP pulse_animation = Pulse(pixels, speed=0.1, period=1, color=RED) @@ -34,5 +34,5 @@ pulse_animation.animate() # Pressing the button pauses the animation permanently - if button.value: + if not button.value: pulse_animation.freeze() diff --git a/examples/led_animation_resume_animation.py b/examples/led_animation_resume_animation.py index b7121da..b8c79ad 100644 --- a/examples/led_animation_resume_animation.py +++ b/examples/led_animation_resume_animation.py @@ -26,7 +26,7 @@ pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False) button = DigitalInOut(button_pin) button.direction = Direction.INPUT -button.pull = Pull.DOWN +button.pull = Pull.UP # Create the animation and freeze it afterwards pulse_animation = Pulse(pixels, speed=0.1, period=1, color=RED) @@ -36,5 +36,5 @@ pulse_animation.animate() # Pressing the button resumes (or in this case starts) the animation permanently - if button.value: + if not button.value: pulse_animation.resume() From 59b02752f01725d07932cf92bbd9fbb5f83e3acf Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 14 Feb 2022 15:35:02 -0500 Subject: [PATCH 16/88] Fixed readthedocs build Signed-off-by: dherrada --- .readthedocs.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index f8b2891..33c2a61 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,8 +8,12 @@ # Required version: 2 +build: + os: ubuntu-20.04 + tools: + python: "3" + python: - version: "3.x" install: - requirements: docs/requirements.txt - requirements: requirements.txt From a84eb12d017c4664d0c3b0fd2658e8fa1d9b625f Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Mon, 28 Mar 2022 15:52:04 -0400 Subject: [PATCH 17/88] Update Black to latest. Signed-off-by: Kattni Rembor --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 43d1385..29230db 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: - repo: https://github.com/python/black - rev: 20.8b1 + rev: 22.3.0 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool From 444c0841d7147813cba5fe6020716b8c9691ab92 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 29 Mar 2022 18:15:55 -0400 Subject: [PATCH 18/88] "Reformatted per new black version" --- adafruit_led_animation/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_led_animation/__init__.py b/adafruit_led_animation/__init__.py index 1442e90..ff60e91 100644 --- a/adafruit_led_animation/__init__.py +++ b/adafruit_led_animation/__init__.py @@ -27,7 +27,6 @@ def monotonic_ms(): """ return monotonic_ns() // NANOS_PER_MS - except (ImportError, NotImplementedError): import time From 44d69b19b4bf4dd79e996764ca52ee0eb71ab05b Mon Sep 17 00:00:00 2001 From: Eva Herrada <33632497+evaherrada@users.noreply.github.com> Date: Thu, 21 Apr 2022 18:52:46 -0400 Subject: [PATCH 19/88] Update .gitignore --- .gitignore | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 9bfdd9d..544ec4a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,47 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2022 Kattni Rembor, written for Adafruit Industries # -# SPDX-License-Identifier: Unlicense +# SPDX-License-Identifier: MIT +# Do not include files and directories created by your personal work environment, such as the IDE +# you use, except for those already listed here. Pull requests including changes to this file will +# not be accepted. + +# This .gitignore file contains rules for files generated by working with CircuitPython libraries, +# including building Sphinx, testing with pip, and creating a virual environment, as well as the +# MacOS and IDE-specific files generated by using MacOS in general, or the PyCharm or VSCode IDEs. + +# If you find that there are files being generated on your machine that should not be included in +# your git commit, you should create a .gitignore_global file on your computer to include the +# files created by your personal setup. To do so, follow the two steps below. + +# First, create a file called .gitignore_global somewhere convenient for you, and add rules for +# the files you want to exclude from git commits. + +# Second, configure Git to use the exclude file for all Git repositories by running the +# following via commandline, replacing "path/to/your/" with the actual path to your newly created +# .gitignore_global file: +# git config --global core.excludesfile path/to/your/.gitignore_global + +# CircuitPython-specific files +*.mpy + +# Python-specific files __pycache__ -_build *.pyc + +# Sphinx build-specific files +_build + +# This file results from running `pip -e install .` in a local repository +*.egg-info + +# Virtual environment-specific files .env -bundles + +# MacOS-specific files +*.DS_Store + +# IDE-specific files .idea +.vscode +*~ From 03f6fbe3de53775a344d459369bb20206aa0cb5f Mon Sep 17 00:00:00 2001 From: evaherrada Date: Fri, 22 Apr 2022 15:58:50 -0400 Subject: [PATCH 20/88] Patch: Replaced discord badge image --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index ee9154c..6503360 100644 --- a/README.rst +++ b/README.rst @@ -5,7 +5,7 @@ Introduction :target: https://docs.circuitpython.org/projects/led-animation/en/latest/ :alt: Documentation Status -.. image:: https://img.shields.io/discord/327254708534116352.svg +.. image:: https://github.com/adafruit/Adafruit_CircuitPython_Bundle/blob/main/badges/adafruit_discord.svg :target: https://adafru.it/discord :alt: Discord From 2455652c978bf595eff711f60b405836f33e177c Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 24 Apr 2022 14:04:24 -0500 Subject: [PATCH 21/88] change discord badge --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 6503360..96fbcc2 100644 --- a/README.rst +++ b/README.rst @@ -5,7 +5,7 @@ Introduction :target: https://docs.circuitpython.org/projects/led-animation/en/latest/ :alt: Documentation Status -.. image:: https://github.com/adafruit/Adafruit_CircuitPython_Bundle/blob/main/badges/adafruit_discord.svg +.. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg :target: https://adafru.it/discord :alt: Discord From 6e2e4aad210a1edc142146346c83283eae8de503 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 15 May 2022 12:48:52 -0400 Subject: [PATCH 22/88] Patch .pre-commit-config.yaml --- .pre-commit-config.yaml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 29230db..0a91a11 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,40 +3,40 @@ # SPDX-License-Identifier: Unlicense repos: -- repo: https://github.com/python/black + - repo: https://github.com/python/black rev: 22.3.0 hooks: - - id: black -- repo: https://github.com/fsfe/reuse-tool - rev: v0.12.1 + - id: black + - repo: https://github.com/fsfe/reuse-tool + rev: v0.14.0 hooks: - - id: reuse -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.3.0 + - id: reuse + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.2.0 hooks: - - id: check-yaml - - id: end-of-file-fixer - - id: trailing-whitespace -- repo: https://github.com/pycqa/pylint + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/pycqa/pylint rev: v2.11.1 hooks: - - id: pylint + - id: pylint name: pylint (library code) types: [python] args: - --disable=consider-using-f-string,duplicate-code exclude: "^(docs/|examples/|tests/|setup.py$)" - - id: pylint + - id: pylint name: pylint (example code) description: Run pylint rules on "examples/*.py" files types: [python] files: "^examples/" args: - - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code - - id: pylint + - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code + - id: pylint name: pylint (test code) description: Run pylint rules on "tests/*.py" files types: [python] files: "^tests/" args: - - --disable=missing-docstring,consider-using-f-string,duplicate-code + - --disable=missing-docstring,consider-using-f-string,duplicate-code From 47b37c9e515feaf5564831b96a4ba1f927de0fe5 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 22 May 2022 00:18:55 -0400 Subject: [PATCH 23/88] Increase min lines similarity Signed-off-by: Alec Delaney --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index cfd1c41..f006a4a 100644 --- a/.pylintrc +++ b/.pylintrc @@ -252,7 +252,7 @@ ignore-docstrings=yes ignore-imports=yes # Minimum lines number of a similarity. -min-similarity-lines=4 +min-similarity-lines=12 [BASIC] From 88475e1b538296936ea47975c8fe21e68a6d8c8d Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 22 May 2022 00:18:23 -0400 Subject: [PATCH 24/88] Switch to inclusive terminology Signed-off-by: Alec Delaney --- .pylintrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index f006a4a..f772971 100644 --- a/.pylintrc +++ b/.pylintrc @@ -9,11 +9,11 @@ # run arbitrary code extension-pkg-whitelist= -# Add files or directories to the blacklist. They should be base names, not +# Add files or directories to the ignore-list. They should be base names, not # paths. ignore=CVS -# Add files or directories matching the regex patterns to the blacklist. The +# Add files or directories matching the regex patterns to the ignore-list. The # regex matches against base names, not paths. ignore-patterns= From c2ded5bd832e2701f6fbc6b2bc543cc2ac0e65f8 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 30 May 2022 14:25:04 -0400 Subject: [PATCH 25/88] Set language to "en" for documentation Signed-off-by: Alec Delaney --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 83db1bc..330b787 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -60,7 +60,7 @@ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = "en" # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. From 77e6ec8ff7e769b6d37067d13cfc7e4d5cf007ce Mon Sep 17 00:00:00 2001 From: evaherrada Date: Tue, 7 Jun 2022 15:34:31 -0400 Subject: [PATCH 26/88] Added cp.org link to index.rst --- docs/index.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index 1d10e2c..5012312 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -36,7 +36,8 @@ Table of Contents .. toctree:: :caption: Other Links - Download + Download from GitHub + Download Library Bundle CircuitPython Reference Documentation CircuitPython Support Forum Discord Chat From 80ac0d063b90a3860ed2ee35fba38f53f9364599 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Tue, 21 Jun 2022 17:00:37 -0400 Subject: [PATCH 27/88] Removed duplicate-code from library pylint disable Signed-off-by: evaherrada --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0a91a11..3343606 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: name: pylint (library code) types: [python] args: - - --disable=consider-using-f-string,duplicate-code + - --disable=consider-using-f-string exclude: "^(docs/|examples/|tests/|setup.py$)" - id: pylint name: pylint (example code) From fc62a1ea8dad2f35623a6dab6bfb8d5995a5b7ec Mon Sep 17 00:00:00 2001 From: evaherrada Date: Fri, 22 Jul 2022 13:58:54 -0400 Subject: [PATCH 28/88] Changed .env to .venv in README.rst --- README.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 96fbcc2..765e542 100644 --- a/README.rst +++ b/README.rst @@ -46,8 +46,8 @@ To install in a virtual environment in your current project: .. code-block:: shell mkdir project-name && cd project-name - python3 -m venv .env - source .env/bin/activate + python3 -m venv .venv + source .venv/bin/activate pip3 install adafruit-circuitpython-led-animation Usage Example @@ -97,15 +97,15 @@ To build this library locally you'll need to install the .. code-block:: shell - python3 -m venv .env - source .env/bin/activate + python3 -m venv .venv + source .venv/bin/activate pip install circuitpython-build-tools Once installed, make sure you are in the virtual environment: .. code-block:: shell - source .env/bin/activate + source .venv/bin/activate Then run the build: @@ -121,8 +121,8 @@ install dependencies (feel free to reuse the virtual environment from above): .. code-block:: shell - python3 -m venv .env - source .env/bin/activate + python3 -m venv .venv + source .venv/bin/activate pip install Sphinx sphinx-rtd-theme Now, once you have the virtual environment activated: From 6a91ce7cd00adf387018302fc0e6eefd53222984 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Tue, 2 Aug 2022 17:00:43 -0400 Subject: [PATCH 29/88] Added Black formatting badge --- README.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.rst b/README.rst index 765e542..582e386 100644 --- a/README.rst +++ b/README.rst @@ -13,6 +13,10 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation/actions :alt: Build Status +.. image:: https://img.shields.io/badge/code%20style-black-000000.svg + :target: https://github.com/psf/black + :alt: Code Style: Black + Perform a variety of LED animation tasks Dependencies From fc16661ac87f1b40b06becd319366d6a2409b287 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 8 Aug 2022 22:05:54 -0400 Subject: [PATCH 30/88] Switched to pyproject.toml --- .github/workflows/build.yml | 18 ++++++----- .github/workflows/release.yml | 17 ++++++----- optional_requirements.txt | 3 ++ pyproject.toml | 47 +++++++++++++++++++++++++++++ requirements.txt | 2 +- setup.py | 57 ----------------------------------- 6 files changed, 71 insertions(+), 73 deletions(-) create mode 100644 optional_requirements.txt create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 474520d..22f6582 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,6 +47,8 @@ jobs: pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags + - name: Setup problem matchers + uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 - name: Pre-commit hooks run: | pre-commit run --all-files @@ -60,16 +62,16 @@ jobs: - name: Build docs working-directory: docs run: sphinx-build -E -W -b html . _build/html - - name: Check For setup.py + - name: Check For pyproject.toml id: need-pypi run: | - echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - name: Build Python package - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') run: | - pip install --upgrade setuptools wheel twine readme_renderer testresources - python setup.py sdist - python setup.py bdist_wheel --universal + pip install --upgrade build twine + for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do + sed -i -e "s/0.0.0-auto.0/1.2.3/" $file; + done; + python -m build twine check dist/* - - name: Setup problem matchers - uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a65e5de..d1b4f8d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -61,25 +61,28 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - name: Check For setup.py + - name: Check For pyproject.toml id: need-pypi run: | - echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - name: Set up Python - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') uses: actions/setup-python@v2 with: python-version: '3.x' - name: Install dependencies - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') run: | python -m pip install --upgrade pip - pip install setuptools wheel twine + pip install --upgrade build twine - name: Build and publish - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') env: TWINE_USERNAME: ${{ secrets.pypi_username }} TWINE_PASSWORD: ${{ secrets.pypi_password }} run: | - python setup.py sdist + for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do + sed -i -e "s/0.0.0-auto.0/${{github.event.release.tag_name}}/" $file; + done; + python -m build twine upload dist/* diff --git a/optional_requirements.txt b/optional_requirements.txt new file mode 100644 index 0000000..d4e27c4 --- /dev/null +++ b/optional_requirements.txt @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d54ff39 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,47 @@ +# SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +[build-system] +requires = [ + "setuptools", + "wheel", +] + +[project] +name = "adafruit-circuitpython-led-animation" +description = "CircuitPython helper for LED colors and animations." +version = "0.0.0-auto.0" +readme = "README.rst" +authors = [ + {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} +] +urls = {Homepage = "https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation"} +keywords = [ + "adafruit", + "blinka", + "circuitpython", + "micropython", + "led", + "animation", + "led", + "colors", + "animations", +] +license = {text = "MIT"} +classifiers = [ + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Embedded Systems", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", +] +dynamic = ["dependencies", "optional-dependencies"] + +[tool.setuptools] +packages = ["adafruit_led_animation"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} +optional-dependencies = {optional = {file = ["optional_requirements.txt"]}} diff --git a/requirements.txt b/requirements.txt index 17a850d..7a984a4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries # # SPDX-License-Identifier: Unlicense diff --git a/setup.py b/setup.py deleted file mode 100644 index 9693e76..0000000 --- a/setup.py +++ /dev/null @@ -1,57 +0,0 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -"""A setuptools based setup module. - -See: -https://packaging.python.org/en/latest/distributing.html -https://github.com/pypa/sampleproject -""" - -from setuptools import setup, find_packages - -# To use a consistent encoding -from codecs import open -from os import path - -here = path.abspath(path.dirname(__file__)) - -# Get the long description from the README file -with open(path.join(here, "README.rst"), encoding="utf-8") as f: - long_description = f.read() - -setup( - name="adafruit-circuitpython-led-animation", - use_scm_version=True, - setup_requires=["setuptools_scm"], - description="CircuitPython helper for LED colors and animations.", - long_description=long_description, - long_description_content_type="text/x-rst", - # The project's main homepage. - url="https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation", - # Author details - author="Adafruit Industries", - author_email="circuitpython@adafruit.com", - install_requires=[ - "Adafruit-Blinka", - ], - # Choose your license - license="MIT", - # See https://pypi.python.org/pypi?%3Aaction=list_classifiers - classifiers=[ - "Development Status :: 3 - Alpha", - "Intended Audience :: Developers", - "Topic :: Software Development :: Libraries", - "Topic :: System :: Hardware", - "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3", - ], - # What does your project relate to? - keywords="adafruit blinka circuitpython micropython led animation led colors animations", - # You can just specify the packages manually here if your project is - # simple. Or you can use find_packages(). - # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, - # CHANGE `py_modules=['...']` TO `packages=['...']` - packages=["adafruit_led_animation", "adafruit_led_animation.animation"], -) From ba57e7a6e1e6f1133637e0b25eac065e7287abb6 Mon Sep 17 00:00:00 2001 From: Vin Minichino Date: Tue, 9 Aug 2022 13:04:58 -0400 Subject: [PATCH 31/88] broke out animate() logic to guarantee each item calls animate without short circuit --- adafruit_led_animation/group.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/adafruit_led_animation/group.py b/adafruit_led_animation/group.py index ba1111f..6bf6a4b 100644 --- a/adafruit_led_animation/group.py +++ b/adafruit_led_animation/group.py @@ -152,7 +152,12 @@ def animate(self, show=True): member.show() return result - return any(item.animate(show) for item in self._members) + ret=False + for item in self._members: + if item.animate(show): + ret=True + return ret + #return any(item.animate(show) for item in self._members) @property def color(self): From d02dde7622cee52dbffbd638a9a3f521de817e72 Mon Sep 17 00:00:00 2001 From: Vin Minichino Date: Tue, 9 Aug 2022 13:38:12 -0400 Subject: [PATCH 32/88] cleanup comments --- adafruit_led_animation/group.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_led_animation/group.py b/adafruit_led_animation/group.py index 6bf6a4b..3a27d50 100644 --- a/adafruit_led_animation/group.py +++ b/adafruit_led_animation/group.py @@ -157,7 +157,6 @@ def animate(self, show=True): if item.animate(show): ret=True return ret - #return any(item.animate(show) for item in self._members) @property def color(self): From 9feca42f6e9376f981686f6419281b2e9a3d6726 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 9 Aug 2022 12:03:54 -0400 Subject: [PATCH 33/88] Add setuptools-scm to build system requirements Signed-off-by: Alec Delaney --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index d54ff39..d015510 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,7 @@ requires = [ "setuptools", "wheel", + "setuptools-scm", ] [project] From d9b877d8bac4e06f6a4ac405d67078482777781f Mon Sep 17 00:00:00 2001 From: Vin Minichino Date: Tue, 9 Aug 2022 15:33:56 -0400 Subject: [PATCH 34/88] blacked --- adafruit_led_animation/group.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_led_animation/group.py b/adafruit_led_animation/group.py index 3a27d50..97cdb1a 100644 --- a/adafruit_led_animation/group.py +++ b/adafruit_led_animation/group.py @@ -152,10 +152,10 @@ def animate(self, show=True): member.show() return result - ret=False + ret = False for item in self._members: if item.animate(show): - ret=True + ret = True return ret @property From 4326d9e9ddc8e67e0714c31afc0471999e48cf81 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 16 Aug 2022 18:09:15 -0400 Subject: [PATCH 35/88] Update version string --- adafruit_led_animation/animation/__init__.py | 2 +- adafruit_led_animation/animation/grid_rain.py | 2 +- adafruit_led_animation/animation/rainbow.py | 2 +- adafruit_led_animation/animation/sparkle.py | 2 +- adafruit_led_animation/group.py | 2 +- adafruit_led_animation/sequence.py | 2 +- pyproject.toml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/adafruit_led_animation/animation/__init__.py b/adafruit_led_animation/animation/__init__.py index e870b5f..87e1bf2 100644 --- a/adafruit_led_animation/animation/__init__.py +++ b/adafruit_led_animation/animation/__init__.py @@ -25,7 +25,7 @@ """ -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation.git" from adafruit_led_animation import MS_PER_SECOND, monotonic_ms diff --git a/adafruit_led_animation/animation/grid_rain.py b/adafruit_led_animation/animation/grid_rain.py index c08196d..17365b2 100644 --- a/adafruit_led_animation/animation/grid_rain.py +++ b/adafruit_led_animation/animation/grid_rain.py @@ -28,7 +28,7 @@ import random from adafruit_led_animation.animation import Animation -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation.git" from adafruit_led_animation.color import BLACK, colorwheel, calculate_intensity, GREEN diff --git a/adafruit_led_animation/animation/rainbow.py b/adafruit_led_animation/animation/rainbow.py index aaa87c0..c5ad620 100644 --- a/adafruit_led_animation/animation/rainbow.py +++ b/adafruit_led_animation/animation/rainbow.py @@ -29,7 +29,7 @@ from adafruit_led_animation.color import BLACK, colorwheel from adafruit_led_animation import MS_PER_SECOND, monotonic_ms -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation.git" diff --git a/adafruit_led_animation/animation/sparkle.py b/adafruit_led_animation/animation/sparkle.py index cbe8a80..978b975 100644 --- a/adafruit_led_animation/animation/sparkle.py +++ b/adafruit_led_animation/animation/sparkle.py @@ -28,7 +28,7 @@ import random from adafruit_led_animation.animation import Animation -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation.git" diff --git a/adafruit_led_animation/group.py b/adafruit_led_animation/group.py index ba1111f..52826ad 100644 --- a/adafruit_led_animation/group.py +++ b/adafruit_led_animation/group.py @@ -26,7 +26,7 @@ """ -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation.git" from adafruit_led_animation.animation import Animation diff --git a/adafruit_led_animation/sequence.py b/adafruit_led_animation/sequence.py index 1765bf2..2ec690c 100644 --- a/adafruit_led_animation/sequence.py +++ b/adafruit_led_animation/sequence.py @@ -30,7 +30,7 @@ from adafruit_led_animation.color import BLACK from . import MS_PER_SECOND, monotonic_ms -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation.git" diff --git a/pyproject.toml b/pyproject.toml index d015510..6dd3e29 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ requires = [ [project] name = "adafruit-circuitpython-led-animation" description = "CircuitPython helper for LED colors and animations." -version = "0.0.0-auto.0" +version = "0.0.0+auto.0" readme = "README.rst" authors = [ {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} From b328c7f7516362933ff1bdd8aeb35510117562e8 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 16 Aug 2022 21:09:15 -0400 Subject: [PATCH 36/88] Fix version strings in workflow files --- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 22f6582..cb2f60e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,7 +71,7 @@ jobs: run: | pip install --upgrade build twine for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0-auto.0/1.2.3/" $file; + sed -i -e "s/0.0.0+auto.0/1.2.3/" $file; done; python -m build twine check dist/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d1b4f8d..f3a0325 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -82,7 +82,7 @@ jobs: TWINE_PASSWORD: ${{ secrets.pypi_password }} run: | for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0-auto.0/${{github.event.release.tag_name}}/" $file; + sed -i -e "s/0.0.0+auto.0/${{github.event.release.tag_name}}/" $file; done; python -m build twine upload dist/* From 829cd1d7af7f67a989c2dbf6bf73ffd9971b5d22 Mon Sep 17 00:00:00 2001 From: arturo182 Date: Mon, 22 Aug 2022 15:35:27 +0200 Subject: [PATCH 37/88] sequence: Add a function to play the previous animation --- adafruit_led_animation/sequence.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/adafruit_led_animation/sequence.py b/adafruit_led_animation/sequence.py index 2ec690c..fe522e9 100644 --- a/adafruit_led_animation/sequence.py +++ b/adafruit_led_animation/sequence.py @@ -179,6 +179,13 @@ def next(self): self.on_cycle_complete() self.activate(current % len(self._members)) + def previous(self): + """ + Jump to the previous animation. + """ + current = self._current - 1 + self.activate(current % len(self._members)) + def random(self): """ Jump to a random animation. From dbd925e734a366abc556c531b6cc6e6e7608fdc5 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 22 Aug 2022 21:36:32 -0400 Subject: [PATCH 38/88] Keep copyright up to date in documentation --- docs/conf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 330b787..1c5c2a7 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -6,6 +6,7 @@ import os import sys +import datetime sys.path.insert(0, os.path.abspath("..")) @@ -43,7 +44,8 @@ # General information about the project. project = "LED_Animation Library" -copyright = "2020 Kattni Rembor" +current_year = str(datetime.datetime.now().year) +copyright = current_year + " Kattni Rembor" author = "Kattni Rembor" # The version info for the project you're documenting, acts as replacement for From 2e97f14805e3a32e7dab25980da70843cf589630 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 23 Aug 2022 17:26:22 -0400 Subject: [PATCH 39/88] Use year duration range for copyright attribution --- docs/conf.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 1c5c2a7..048bad5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -44,8 +44,14 @@ # General information about the project. project = "LED_Animation Library" +creation_year = "2020" current_year = str(datetime.datetime.now().year) -copyright = current_year + " Kattni Rembor" +year_duration = ( + current_year + if current_year == creation_year + else creation_year + " - " + current_year +) +copyright = year_duration + " Kattni Rembor" author = "Kattni Rembor" # The version info for the project you're documenting, acts as replacement for From a9525ef5b198a44e3f8bba4ba1ba4e4b7df568c7 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 00:02:50 -0400 Subject: [PATCH 40/88] Switching to composite actions --- .github/workflows/build.yml | 67 +---------------------- .github/workflows/release.yml | 88 ------------------------------ .github/workflows/release_gh.yml | 14 +++++ .github/workflows/release_pypi.yml | 14 +++++ 4 files changed, 30 insertions(+), 153 deletions(-) delete mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/release_gh.yml create mode 100644 .github/workflows/release_pypi.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cb2f60e..041a337 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,68 +10,5 @@ jobs: test: runs-on: ubuntu-latest steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" - - name: Translate Repo Name For Build Tools filename_prefix - id: repo-name - run: | - echo ::set-output name=repo-name::$( - echo ${{ github.repository }} | - awk -F '\/' '{ print tolower($2) }' | - tr '_' '-' - ) - - name: Set up Python 3.x - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - name: Versions - run: | - python3 --version - - name: Checkout Current Repo - uses: actions/checkout@v1 - with: - submodules: true - - name: Checkout tools repo - uses: actions/checkout@v2 - with: - repository: adafruit/actions-ci-circuitpython-libs - path: actions-ci - - name: Install dependencies - # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) - run: | - source actions-ci/install.sh - - name: Pip install Sphinx, pre-commit - run: | - pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - - name: Library version - run: git describe --dirty --always --tags - - name: Setup problem matchers - uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 - - name: Pre-commit hooks - run: | - pre-commit run --all-files - - name: Build assets - run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - - name: Archive bundles - uses: actions/upload-artifact@v2 - with: - name: bundles - path: ${{ github.workspace }}/bundles/ - - name: Build docs - working-directory: docs - run: sphinx-build -E -W -b html . _build/html - - name: Check For pyproject.toml - id: need-pypi - run: | - echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - - name: Build Python package - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - run: | - pip install --upgrade build twine - for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0+auto.0/1.2.3/" $file; - done; - python -m build - twine check dist/* + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index f3a0325..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,88 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -name: Release Actions - -on: - release: - types: [published] - -jobs: - upload-release-assets: - runs-on: ubuntu-latest - steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" - - name: Translate Repo Name For Build Tools filename_prefix - id: repo-name - run: | - echo ::set-output name=repo-name::$( - echo ${{ github.repository }} | - awk -F '\/' '{ print tolower($2) }' | - tr '_' '-' - ) - - name: Set up Python 3.x - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - name: Versions - run: | - python3 --version - - name: Checkout Current Repo - uses: actions/checkout@v1 - with: - submodules: true - - name: Checkout tools repo - uses: actions/checkout@v2 - with: - repository: adafruit/actions-ci-circuitpython-libs - path: actions-ci - - name: Install deps - run: | - source actions-ci/install.sh - - name: Build assets - run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - - name: Upload Release Assets - # the 'official' actions version does not yet support dynamically - # supplying asset names to upload. @csexton's version chosen based on - # discussion in the issue below, as its the simplest to implement and - # allows for selecting files with a pattern. - # https://github.com/actions/upload-release-asset/issues/4 - #uses: actions/upload-release-asset@v1.0.1 - uses: csexton/release-asset-action@master - with: - pattern: "bundles/*" - github-token: ${{ secrets.GITHUB_TOKEN }} - - upload-pypi: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Check For pyproject.toml - id: need-pypi - run: | - echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - - name: Set up Python - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - name: Install dependencies - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - run: | - python -m pip install --upgrade pip - pip install --upgrade build twine - - name: Build and publish - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - env: - TWINE_USERNAME: ${{ secrets.pypi_username }} - TWINE_PASSWORD: ${{ secrets.pypi_password }} - run: | - for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0+auto.0/${{github.event.release.tag_name}}/" $file; - done; - python -m build - twine upload dist/* diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml new file mode 100644 index 0000000..041a337 --- /dev/null +++ b/.github/workflows/release_gh.yml @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml new file mode 100644 index 0000000..041a337 --- /dev/null +++ b/.github/workflows/release_pypi.yml @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main From 5f27fa68c1b5ded2d90eb4caea892c28fa014674 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 00:47:00 -0400 Subject: [PATCH 41/88] Updated pylint version to 2.13.0 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3343606..4c43710 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.11.1 + rev: v2.13.0 hooks: - id: pylint name: pylint (library code) From caf39ebe64233717c1b069b06ee377e48a6a29da Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 08:15:21 -0400 Subject: [PATCH 42/88] Update pylint to 2.15.5 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4c43710..0e5fccc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.13.0 + rev: v2.15.5 hooks: - id: pylint name: pylint (library code) From c19e802c6598195e30acaa3d2b30bf39b5e6d2a2 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 09:12:45 -0400 Subject: [PATCH 43/88] Fix release CI files --- .github/workflows/release_gh.yml | 14 +++++++++----- .github/workflows/release_pypi.yml | 15 ++++++++++----- adafruit_led_animation/animation/chase.py | 2 +- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml index 041a337..b8aa8d6 100644 --- a/.github/workflows/release_gh.yml +++ b/.github/workflows/release_gh.yml @@ -2,13 +2,17 @@ # # SPDX-License-Identifier: MIT -name: Build CI +name: GitHub Release Actions -on: [pull_request, push] +on: + release: + types: [published] jobs: - test: + upload-release-assets: runs-on: ubuntu-latest steps: - - name: Run Build CI workflow - uses: adafruit/workflows-circuitpython-libs/build@main + - name: Run GitHub Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-gh@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml index 041a337..65775b7 100644 --- a/.github/workflows/release_pypi.yml +++ b/.github/workflows/release_pypi.yml @@ -2,13 +2,18 @@ # # SPDX-License-Identifier: MIT -name: Build CI +name: PyPI Release Actions -on: [pull_request, push] +on: + release: + types: [published] jobs: - test: + upload-release-assets: runs-on: ubuntu-latest steps: - - name: Run Build CI workflow - uses: adafruit/workflows-circuitpython-libs/build@main + - name: Run PyPI Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-pypi@main + with: + pypi-username: ${{ secrets.pypi_username }} + pypi-password: ${{ secrets.pypi_password }} diff --git a/adafruit_led_animation/animation/chase.py b/adafruit_led_animation/animation/chase.py index dbcedd3..39dd1d2 100644 --- a/adafruit_led_animation/animation/chase.py +++ b/adafruit_led_animation/animation/chase.py @@ -111,7 +111,7 @@ def bar_color(self, n, pixel_no=0): # pylint: disable=unused-argument """ return self.color - def space_color(self, n, pixel_no=0): # pylint: disable=unused-argument,no-self-use + def space_color(self, n, pixel_no=0): # pylint: disable=unused-argument """ Generate the spacing color for the n'th bar_color in the Chase From eaecdc3b1dab3ee40b4396fe5c25a6774c54f728 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 18:34:33 -0400 Subject: [PATCH 44/88] Update .pylintrc for v2.15.5 --- .pylintrc | 45 ++++----------------------------------------- 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/.pylintrc b/.pylintrc index f772971..40208c3 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries # # SPDX-License-Identifier: Unlicense @@ -26,7 +26,7 @@ jobs=1 # List of plugins (as comma separated values of python modules names) to load, # usually to register additional checkers. -load-plugins= +load-plugins=pylint.extensions.no_self_use # Pickle collected data for later comparisons. persistent=yes @@ -54,8 +54,8 @@ confidence= # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call -disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,unspecified-encoding +# disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call +disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option @@ -225,12 +225,6 @@ max-line-length=100 # Maximum number of lines in a module max-module-lines=1000 -# List of optional constructs for which whitespace checking is disabled. `dict- -# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. -# `trailing-comma` allows a space between comma and closing bracket: (a, ). -# `empty-line` allows space-only lines. -no-space-check=trailing-comma,dict-separator - # Allow the body of a class to be on the same line as the declaration if body # contains single statement. single-line-class-stmt=no @@ -257,38 +251,22 @@ min-similarity-lines=12 [BASIC] -# Naming hint for argument names -argument-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct argument names argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ -# Naming hint for attribute names -attr-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct attribute names attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ # Bad variable names which should always be refused, separated by a comma bad-names=foo,bar,baz,toto,tutu,tata -# Naming hint for class attribute names -class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - # Regular expression matching correct class attribute names class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ -# Naming hint for class names -# class-name-hint=[A-Z_][a-zA-Z0-9]+$ -class-name-hint=[A-Z_][a-zA-Z0-9_]+$ - # Regular expression matching correct class names # class-rgx=[A-Z_][a-zA-Z0-9]+$ class-rgx=[A-Z_][a-zA-Z0-9_]+$ -# Naming hint for constant names -const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - # Regular expression matching correct constant names const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ @@ -296,9 +274,6 @@ const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ # ones are exempt. docstring-min-length=-1 -# Naming hint for function names -function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct function names function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ @@ -309,21 +284,12 @@ good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ # Include a hint for the correct naming format with invalid-name include-naming-hint=no -# Naming hint for inline iteration names -inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$ - # Regular expression matching correct inline iteration names inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ -# Naming hint for method names -method-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct method names method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ -# Naming hint for module names -module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - # Regular expression matching correct module names module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ @@ -339,9 +305,6 @@ no-docstring-rgx=^_ # to this list to register other decorators that produce valid properties. property-classes=abc.abstractproperty -# Naming hint for variable names -variable-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct variable names variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ From 24319aac5d5cc1437229c6cef66dc19cc945acf5 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Mon, 7 Nov 2022 20:34:04 -0500 Subject: [PATCH 45/88] Fix pylint errors --- adafruit_led_animation/animation/chase.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_led_animation/animation/chase.py b/adafruit_led_animation/animation/chase.py index 39dd1d2..f5168d7 100644 --- a/adafruit_led_animation/animation/chase.py +++ b/adafruit_led_animation/animation/chase.py @@ -111,7 +111,8 @@ def bar_color(self, n, pixel_no=0): # pylint: disable=unused-argument """ return self.color - def space_color(self, n, pixel_no=0): # pylint: disable=unused-argument + @staticmethod + def space_color(n, pixel_no=0): # pylint: disable=unused-argument """ Generate the spacing color for the n'th bar_color in the Chase From 914bb8060b7f2ae91fe22adcd73d9258f69e0ce1 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 10 Nov 2022 14:53:25 -0600 Subject: [PATCH 46/88] speed bar generation by not querying pixels In a test this improved speed substantially, nearly doubling the speed of the following test program ```python pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=1, auto_write=False, pixel_order="RGB") evens = helper.PixelMap(pixels, [(i,) for i in range(0, pixel_num, 2)], individual_pixels=True) animation = RainbowChase(evens, 0, spacing=8) t0 = adafruit_ticks.ticks_ms() while True: for i in range(10): animation.animate(show=False) t1 = adafruit_ticks.ticks_ms() print(f"{10000/(t1-t0):.0f}fps") t0 = t1 ``` Performance on Raspberry Pi Pico W: Before: ~85fps After: ~140fps This also happens to make it compatible with an in-process PR that adds a fast PixelMap-like class to the core, but which doesn't support getitem. --- adafruit_led_animation/animation/chase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_led_animation/animation/chase.py b/adafruit_led_animation/animation/chase.py index f5168d7..a46a16a 100644 --- a/adafruit_led_animation/animation/chase.py +++ b/adafruit_led_animation/animation/chase.py @@ -96,7 +96,7 @@ def bar_colors(): bar_no += 1 colorgen = bar_colors() - self.pixel_object[:] = [next(colorgen) for _ in self.pixel_object] + self.pixel_object[:] = [next(colorgen) for _ in range(len(self.pixel_object))] if self.draw_count % len(self.pixel_object) == 0: self.cycle_complete = True From 73d5f61c6e059a289e7ff548fb90197559683f86 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 10 Nov 2022 15:50:26 -0600 Subject: [PATCH 47/88] Optimize comet draw The big pay-off is avoiding enumerate(). Removing redundant comparisons of _ring() and avoiding modulo operations help too. --- adafruit_led_animation/animation/comet.py | 26 ++++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/adafruit_led_animation/animation/comet.py b/adafruit_led_animation/animation/comet.py index 7252c98..e562e49 100644 --- a/adafruit_led_animation/animation/comet.py +++ b/adafruit_led_animation/animation/comet.py @@ -120,14 +120,24 @@ def draw(self): colors = self._comet_colors if self.reverse: colors = reversed(colors) - for pixel_no, color in enumerate(colors): - draw_at = self._tail_start + pixel_no - if draw_at < 0 or draw_at >= self._num_pixels: - if not self._ring: - continue - draw_at = draw_at % self._num_pixels - - self.pixel_object[draw_at] = color + + pixels = self.pixel_object + start = self._tail_start + npixels = len(pixels) + if self._ring: + start %= npixels + for color in colors: + pixels[start] = color + start += 1 + if start == npixels: + start = 0 + else: + for color in colors: + if start >= npixels: + break + if start >= 0: + pixels[start] = color + start += 1 self._tail_start += self._direction From 5e3a68c7932cc03c58125fe2c59c375302c38b0e Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Thu, 1 Sep 2022 20:16:31 -0400 Subject: [PATCH 48/88] Add .venv to .gitignore Signed-off-by: Alec Delaney <89490472+tekktrik@users.noreply.github.com> --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 544ec4a..db3d538 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ _build # Virtual environment-specific files .env +.venv # MacOS-specific files *.DS_Store From 9179e7c25a74c12d9ccb119b16bb38361462d9ee Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 17 Dec 2022 11:49:12 -0600 Subject: [PATCH 49/88] adding multicolor comet animation --- .../animation/multicolor_comet.py | 111 ++++++++++++++++++ examples/led_animation_multicolor_comet.py | 63 ++++++++++ 2 files changed, 174 insertions(+) create mode 100644 adafruit_led_animation/animation/multicolor_comet.py create mode 100644 examples/led_animation_multicolor_comet.py diff --git a/adafruit_led_animation/animation/multicolor_comet.py b/adafruit_led_animation/animation/multicolor_comet.py new file mode 100644 index 0000000..e127048 --- /dev/null +++ b/adafruit_led_animation/animation/multicolor_comet.py @@ -0,0 +1,111 @@ +# SPDX-FileCopyrightText: 2022 Tim Cocks +# +# SPDX-License-Identifier: MIT + +""" +`adafruit_led_animation.animation.multicolor_comet` +================================================================================ + +Multi-color Comet animation for CircuitPython helper library for LED animations. + +* Author(s): Kattni Rembor, Tim Cocks + +Implementation Notes +-------------------- + +**Hardware:** + +* `Adafruit NeoPixels `_ +* `Adafruit DotStars `_ + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://circuitpython.org/downloads + + +""" +from adafruit_led_animation.animation.comet import Comet +from adafruit_led_animation.color import BLACK + + +class MulticolorComet(Comet): + """ + A multi-color comet animation. + + :param pixel_object: The initialised LED object. + :param float speed: Animation speed in seconds, e.g. ``0.1``. + :param colors: Animation colors in a list or tuple of entries in + ``(r, g, b)`` tuple, or ``0x000000`` hex format. + :param int tail_length: The length of the comet. Defaults to 25% of the length of the + ``pixel_object``. Automatically compensates for a minimum of 2 and a + maximum of the length of the ``pixel_object``. + :param bool reverse: Animates the comet in the reverse order. Defaults to ``False``. + :param bool bounce: Comet will bounce back and forth. Defaults to ``True``. + :param bool ring: Ring mode. Defaults to ``False``. + :param bool off_pixels: Turn pixels off after the animation passes them. Defaults to ``True``. + Setting to False will result in all pixels not currently in the comet + to remain on and set to a color after the comet passes. + """ + + # pylint: disable=too-many-arguments,too-many-instance-attributes + def __init__( + self, + pixel_object, + speed, + colors, + tail_length=0, + reverse=False, + bounce=False, + name=None, + ring=False, + off_pixels=True, + ): + if tail_length == 0: + tail_length = len(pixel_object) // 4 + if bounce and ring: + raise ValueError("Cannot combine bounce and ring mode") + self.bounce = bounce + self._reverse = reverse + self._initial_reverse = reverse + self._tail_length = tail_length + + self._comet_colors = None + + self._num_pixels = len(pixel_object) + self._direction = -1 if reverse else 1 + self._left_side = -self._tail_length + self._right_side = self._num_pixels + self._tail_start = 0 + self._ring = ring + self._colors = colors + if colors is None or len(colors) < 2: + raise ValueError("Must pass at least two colors.") + + self._off_pixels = off_pixels + if ring: + self._left_side = 0 + self.reset() + super().__init__( + pixel_object, + speed, + 0x0, + name=name, + tail_length=tail_length, + bounce=bounce, + ring=ring, + reverse=reverse, + ) + + on_cycle_complete_supported = True + + def _set_color(self, color): + if self._off_pixels: + self._comet_colors = [BLACK] + else: + self._comet_colors = [] + + for n in range(self._tail_length): + _float_index = ((len(self._colors)) / self._tail_length) * n + _color_index = int(_float_index) + self._comet_colors.append(self._colors[_color_index]) diff --git a/examples/led_animation_multicolor_comet.py b/examples/led_animation_multicolor_comet.py new file mode 100644 index 0000000..502d604 --- /dev/null +++ b/examples/led_animation_multicolor_comet.py @@ -0,0 +1,63 @@ +# SPDX-FileCopyrightText: 2022 Tim Cocks +# +# SPDX-License-Identifier: MIT +""" +This example animates a red, yellow, and green gradient comet that bounces +from end to end of the strip. + +For QT Py Haxpress and a NeoPixel strip. Update pixel_pin and pixel_num to match your wiring if +using a different board or form of NeoPixels. + +This example will run on SAMD21 (M0) Express boards (such as Circuit Playground Express or QT Py +Haxpress), but not on SAMD21 non-Express boards (such as QT Py or Trinket). +""" +import board +import neopixel +from adafruit_led_animation.animation.multicolor_comet import MulticolorComet + +# Update to match the pin connected to your NeoPixels +pixel_pin = board.D9 +# Update to match the number of NeoPixels you have connected +pixel_num = 96 +brightness = 0.02 + +pixels = neopixel.NeoPixel( + pixel_pin, + pixel_num, + brightness=brightness, + auto_write=True, + pixel_order=neopixel.RGB, +) + +comet_colors = [ + 0xFF0000, + 0xFD2000, + 0xF93E00, + 0xF45B00, + 0xEC7500, + 0xE28D00, + 0xD5A200, + 0xC6B500, + 0xB5C600, + 0xA2D500, + 0x8DE200, + 0x75EC00, + 0x5BF400, + 0x3EF900, + 0x20FD00, + 0x00FF00, +] + + +comet = MulticolorComet( + pixels, + colors=comet_colors, + speed=0.01, + tail_length=20, + bounce=True, + ring=False, + reverse=False, +) + +while True: + comet.animate() From bc0298b35a24c22745683adeb93cdda8b305433a Mon Sep 17 00:00:00 2001 From: priestbh <105124854+priestbh@users.noreply.github.com> Date: Fri, 30 Dec 2022 14:43:00 -0500 Subject: [PATCH 50/88] Update comet.py to include a background color Update comet.py to include a background color other than BLACK --- adafruit_led_animation/animation/comet.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adafruit_led_animation/animation/comet.py b/adafruit_led_animation/animation/comet.py index e562e49..6742c1a 100644 --- a/adafruit_led_animation/animation/comet.py +++ b/adafruit_led_animation/animation/comet.py @@ -51,6 +51,7 @@ def __init__( pixel_object, speed, color, + background_color=BLACK tail_length=0, reverse=False, bounce=False, @@ -68,6 +69,7 @@ def __init__( self._color_step = 0.95 / tail_length self._comet_colors = None self._computed_color = color + self._background_color = background_color self._num_pixels = len(pixel_object) self._direction = -1 if reverse else 1 self._left_side = -self._tail_length @@ -82,7 +84,7 @@ def __init__( on_cycle_complete_supported = True def _set_color(self, color): - self._comet_colors = [BLACK] + self._comet_colors = [self._background_color] for n in range(self._tail_length): self._comet_colors.append( calculate_intensity(color, n * self._color_step + 0.05) From 85e4d6ee1b85126c052ad61a04c2b17da9062602 Mon Sep 17 00:00:00 2001 From: priestbh <105124854+priestbh@users.noreply.github.com> Date: Fri, 30 Dec 2022 14:52:01 -0500 Subject: [PATCH 51/88] Update comet.py --- adafruit_led_animation/animation/comet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_led_animation/animation/comet.py b/adafruit_led_animation/animation/comet.py index 6742c1a..72b681a 100644 --- a/adafruit_led_animation/animation/comet.py +++ b/adafruit_led_animation/animation/comet.py @@ -51,7 +51,7 @@ def __init__( pixel_object, speed, color, - background_color=BLACK + background_color=BLACK, tail_length=0, reverse=False, bounce=False, From 56728e32909c28df374c825170ccbb6b7722f58f Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Thu, 19 Jan 2023 23:39:55 -0500 Subject: [PATCH 52/88] Add upload url to release action Signed-off-by: Alec Delaney <89490472+tekktrik@users.noreply.github.com> --- .github/workflows/release_gh.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml index b8aa8d6..9acec60 100644 --- a/.github/workflows/release_gh.yml +++ b/.github/workflows/release_gh.yml @@ -16,3 +16,4 @@ jobs: uses: adafruit/workflows-circuitpython-libs/release-gh@main with: github-token: ${{ secrets.GITHUB_TOKEN }} + upload-url: ${{ github.event.release.upload_url }} From 58bc776678f81fed5cbb6684ca06ea511ccc8245 Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Sun, 22 Jan 2023 14:32:32 -0600 Subject: [PATCH 53/88] rainbowcomet: add missing arg initing base class In RainbowComet, the call to `super().__init__()` was missing the `background_color` argument. This caused strange effects when non-default arguments were passed. For example, setting `reverse=True` resulted a red comet with a tail length of 1, and setting `bounce=True` resulted in a reversed rainbow comet. Signed-off-by: Taylor Yu --- adafruit_led_animation/animation/rainbowcomet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_led_animation/animation/rainbowcomet.py b/adafruit_led_animation/animation/rainbowcomet.py index 1099307..e42d4be 100644 --- a/adafruit_led_animation/animation/rainbowcomet.py +++ b/adafruit_led_animation/animation/rainbowcomet.py @@ -65,7 +65,7 @@ def __init__( self._colorwheel_step = step self._colorwheel_offset = colorwheel_offset super().__init__( - pixel_object, speed, 0, tail_length, reverse, bounce, name, ring + pixel_object, speed, 0, 0, tail_length, reverse, bounce, name, ring ) def _set_color(self, color): From a2c36c659a1e7c4dd50beee5ddd514336a578885 Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Sun, 22 Jan 2023 14:50:21 -0600 Subject: [PATCH 54/88] fix doc of `bounce` Fix documentation of the default `bounce` value for `Comet` and `RainbowComet`. Signed-off-by: Taylor Yu --- adafruit_led_animation/animation/comet.py | 2 +- adafruit_led_animation/animation/rainbowcomet.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_led_animation/animation/comet.py b/adafruit_led_animation/animation/comet.py index 72b681a..ab32e70 100644 --- a/adafruit_led_animation/animation/comet.py +++ b/adafruit_led_animation/animation/comet.py @@ -41,7 +41,7 @@ class Comet(Animation): ``pixel_object``. Automatically compensates for a minimum of 2 and a maximum of the length of the ``pixel_object``. :param bool reverse: Animates the comet in the reverse order. Defaults to ``False``. - :param bool bounce: Comet will bounce back and forth. Defaults to ``True``. + :param bool bounce: Comet will bounce back and forth. Defaults to ``False``. :param bool ring: Ring mode. Defaults to ``False``. """ diff --git a/adafruit_led_animation/animation/rainbowcomet.py b/adafruit_led_animation/animation/rainbowcomet.py index 1099307..903fc7c 100644 --- a/adafruit_led_animation/animation/rainbowcomet.py +++ b/adafruit_led_animation/animation/rainbowcomet.py @@ -40,7 +40,7 @@ class RainbowComet(Comet): pixels present in the pixel object, e.g. if the strip is 30 pixels long, the ``tail_length`` cannot exceed 30 pixels. :param bool reverse: Animates the comet in the reverse order. Defaults to ``False``. - :param bool bounce: Comet will bounce back and forth. Defaults to ``True``. + :param bool bounce: Comet will bounce back and forth. Defaults to ``False``. :param int colorwheel_offset: Offset from start of colorwheel (0-255). :param int step: Colorwheel step (defaults to automatic). :param bool ring: Ring mode. Defaults to ``False``. From 38af7a0c39b78e703bd9f5116e3eb054b1d483b7 Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Tue, 24 Jan 2023 22:39:55 -0600 Subject: [PATCH 55/88] comet: add doc for `background_color` Add missing documentation for the recently-added `background_color` parameter to `Comet`. Signed-off-by: Taylor Yu --- adafruit_led_animation/animation/comet.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adafruit_led_animation/animation/comet.py b/adafruit_led_animation/animation/comet.py index ab32e70..83fb79a 100644 --- a/adafruit_led_animation/animation/comet.py +++ b/adafruit_led_animation/animation/comet.py @@ -37,6 +37,8 @@ class Comet(Animation): :param pixel_object: The initialised LED object. :param float speed: Animation speed in seconds, e.g. ``0.1``. :param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format. + :param background_color: Background color in ``(r, g, b)`` tuple, or ``0x000000`` hex format. + Defaults to BLACK. :param int tail_length: The length of the comet. Defaults to 25% of the length of the ``pixel_object``. Automatically compensates for a minimum of 2 and a maximum of the length of the ``pixel_object``. From 3aaa75efbf9aedf7754135bf024773264571746a Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 24 Feb 2023 17:24:48 -0600 Subject: [PATCH 56/88] add star arg and docstring for name --- adafruit_led_animation/animation/comet.py | 2 ++ adafruit_led_animation/animation/multicolor_comet.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/adafruit_led_animation/animation/comet.py b/adafruit_led_animation/animation/comet.py index e562e49..2455a65 100644 --- a/adafruit_led_animation/animation/comet.py +++ b/adafruit_led_animation/animation/comet.py @@ -42,6 +42,8 @@ class Comet(Animation): maximum of the length of the ``pixel_object``. :param bool reverse: Animates the comet in the reverse order. Defaults to ``False``. :param bool bounce: Comet will bounce back and forth. Defaults to ``True``. + :param Optional[string] name: A human-readable name for the Animation. + Used by the to string function. :param bool ring: Ring mode. Defaults to ``False``. """ diff --git a/adafruit_led_animation/animation/multicolor_comet.py b/adafruit_led_animation/animation/multicolor_comet.py index e127048..a71a2d4 100644 --- a/adafruit_led_animation/animation/multicolor_comet.py +++ b/adafruit_led_animation/animation/multicolor_comet.py @@ -42,6 +42,8 @@ class MulticolorComet(Comet): maximum of the length of the ``pixel_object``. :param bool reverse: Animates the comet in the reverse order. Defaults to ``False``. :param bool bounce: Comet will bounce back and forth. Defaults to ``True``. + :param Optional[string] name: A human-readable name for the Animation. + Used by the to string function. :param bool ring: Ring mode. Defaults to ``False``. :param bool off_pixels: Turn pixels off after the animation passes them. Defaults to ``True``. Setting to False will result in all pixels not currently in the comet @@ -54,6 +56,7 @@ def __init__( pixel_object, speed, colors, + *, tail_length=0, reverse=False, bounce=False, From df79acd1a2754d1a5a28c70deda6bab693641a67 Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Tue, 9 May 2023 20:26:25 -0400 Subject: [PATCH 57/88] Update pre-commit hooks Signed-off-by: Tekktrik --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0e5fccc..70ade69 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,21 +4,21 @@ repos: - repo: https://github.com/python/black - rev: 22.3.0 + rev: 23.3.0 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool - rev: v0.14.0 + rev: v1.1.2 hooks: - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.2.0 + rev: v4.4.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.15.5 + rev: v2.17.4 hooks: - id: pylint name: pylint (library code) From 46f1be6bce4f16bcb23877d464c42fad30d10bfb Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Wed, 10 May 2023 22:36:01 -0400 Subject: [PATCH 58/88] Run pre-commit --- adafruit_led_animation/animation/grid_rain.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_led_animation/animation/grid_rain.py b/adafruit_led_animation/animation/grid_rain.py index 17365b2..7beef00 100644 --- a/adafruit_led_animation/animation/grid_rain.py +++ b/adafruit_led_animation/animation/grid_rain.py @@ -57,7 +57,6 @@ def __init__( super().__init__(grid_object, speed, color, name=name) def draw(self): - # Move raindrops down keep = [] for raindrop in self._raindrops: From 66898580acc1be5c2761d1e9431206c287d78945 Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Sun, 14 May 2023 13:00:32 -0400 Subject: [PATCH 59/88] Update .pylintrc, fix jQuery for docs Signed-off-by: Tekktrik --- .pylintrc | 2 +- docs/conf.py | 1 + docs/requirements.txt | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 40208c3..f945e92 100644 --- a/.pylintrc +++ b/.pylintrc @@ -396,4 +396,4 @@ min-public-methods=1 # Exceptions that will emit a warning when being caught. Defaults to # "Exception" -overgeneral-exceptions=Exception +overgeneral-exceptions=builtins.Exception diff --git a/docs/conf.py b/docs/conf.py index 048bad5..23034e8 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -17,6 +17,7 @@ # ones. extensions = [ "sphinx.ext.autodoc", + "sphinxcontrib.jquery", "sphinx.ext.intersphinx", "sphinx.ext.napoleon", "sphinx.ext.todo", diff --git a/docs/requirements.txt b/docs/requirements.txt index 88e6733..797aa04 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,3 +3,4 @@ # SPDX-License-Identifier: Unlicense sphinx>=4.0.0 +sphinxcontrib-jquery From e23e57b421901d66b7fe0b60cc42d2f54c679b7b Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 29 Jun 2023 19:36:32 -0500 Subject: [PATCH 60/88] reuse formatting. add examples for new functionality --- adafruit_led_animation/animation/volume.py | 20 ++----------- adafruit_led_animation/timedsequence.py | 20 ++----------- examples/led_animation_timedsequence.py | 21 +++++++++++++ examples/led_animation_volume.py | 34 ++++++++++++++++++++++ 4 files changed, 59 insertions(+), 36 deletions(-) create mode 100644 examples/led_animation_timedsequence.py create mode 100644 examples/led_animation_volume.py diff --git a/adafruit_led_animation/animation/volume.py b/adafruit_led_animation/animation/volume.py index 5827ba1..cbfb8d1 100644 --- a/adafruit_led_animation/animation/volume.py +++ b/adafruit_led_animation/animation/volume.py @@ -1,22 +1,6 @@ -# The MIT License (MIT) +# SPDX-FileCopyrightText: 2020 Gamblor21 # -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# SPDX-License-Identifier: MIT """ `adafruit_led_animation.animation.volume` ================================================================================ diff --git a/adafruit_led_animation/timedsequence.py b/adafruit_led_animation/timedsequence.py index 42773c6..a08c5e1 100644 --- a/adafruit_led_animation/timedsequence.py +++ b/adafruit_led_animation/timedsequence.py @@ -1,22 +1,6 @@ -# The MIT License (MIT) +# SPDX-FileCopyrightText: 2020 Gamblor21 # -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# SPDX-License-Identifier: MIT """ `adafruit_led_animation.timedsequence` ================================================================================ diff --git a/examples/led_animation_timedsequence.py b/examples/led_animation_timedsequence.py new file mode 100644 index 0000000..b6e05bf --- /dev/null +++ b/examples/led_animation_timedsequence.py @@ -0,0 +1,21 @@ +# SPDX-FileCopyrightText: 2020 Gamblor21 +# +# SPDX-License-Identifier: MIT +""" +Example for TimedSequence +""" +import board +import neopixel +from adafruit_led_animation.timedsequence import TimedAnimationSequence +import adafruit_led_animation.animation.comet as comet_animation +import adafruit_led_animation.animation.sparkle as sparkle_animation +import adafruit_led_animation.animation.blink as blink_animation +from adafruit_led_animation import color + +strip_pixels = neopixel.NeoPixel(board.D6, 32, brightness=0.1, auto_write=False) +blink = blink_animation.Blink(strip_pixels, 0.3, color.RED) +comet = comet_animation.Comet(strip_pixels, 0.1, color.BLUE) +sparkle = sparkle_animation.Sparkle(strip_pixels, 0.05, color.GREEN) +animations = TimedAnimationSequence(blink, 2, comet, 4, sparkle, 5) +while True: + animations.animate() diff --git a/examples/led_animation_volume.py b/examples/led_animation_volume.py new file mode 100644 index 0000000..2448636 --- /dev/null +++ b/examples/led_animation_volume.py @@ -0,0 +1,34 @@ +# SPDX-FileCopyrightText: 2023 Tim Cocks +# +# SPDX-License-Identifier: MIT + +"""Volume Animation Example""" +import board +from audiomp3 import MP3Decoder +import neopixel +from adafruit_led_animation.animation import volume + +try: + from audioio import AudioOut +except ImportError: + try: + from audiopwmio import PWMAudioOut as AudioOut + except ImportError: + pass # not always supported by every board! + +# Fill in your own MP3 file or use the one from the learn guide: +# https://learn.adafruit.com/circuitpython-essentials/circuitpython-mp3-audio#installing-project-code-3067700 +mp3file = "happy.mp3" +with open(mp3file, "rb") as mp3: + decoder = MP3Decoder(mp3) + audio = AudioOut(board.SPEAKER) + + strip_pixels = neopixel.NeoPixel(board.D4, 30, brightness=0.1, auto_write=False) + volume_anim = volume.Volume(strip_pixels, 0.3, (0, 255, 0), decoder, 400) + + while True: + audio.play(decoder) + print("playing", mp3file) + + while audio.playing: + volume_anim.animate() From 5cd37ed2f52423898a17a09cadcf9aeea700e635 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 18 Sep 2023 16:24:07 -0500 Subject: [PATCH 61/88] "fix rtd theme " --- docs/conf.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 23034e8..fd9b7a6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -101,19 +101,10 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get("READTHEDOCS", None) == "True" - -if not on_rtd: # only import and set the theme if we're building docs locally - try: - import sphinx_rtd_theme - - html_theme = "sphinx_rtd_theme" - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] - except: - html_theme = "default" - html_theme_path = ["."] -else: - html_theme_path = ["."] +import sphinx_rtd_theme + +html_theme = "sphinx_rtd_theme" +html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, From 0f24be5dadae4e3c54a75b105a27c08ba41d26c1 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Oct 2023 14:30:31 -0500 Subject: [PATCH 62/88] unpin sphinx and add sphinx-rtd-theme to docs reqs Signed-off-by: foamyguy --- docs/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 797aa04..979f568 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,5 +2,6 @@ # # SPDX-License-Identifier: Unlicense -sphinx>=4.0.0 +sphinx sphinxcontrib-jquery +sphinx-rtd-theme From cce709470f1ddbf07fd9ade2d27ab2892c2e12fb Mon Sep 17 00:00:00 2001 From: tneish <30879076+tneish@users.noreply.github.com> Date: Sat, 16 Dec 2023 11:15:27 +0100 Subject: [PATCH 63/88] ColorCycle accepts start color --- adafruit_led_animation/animation/colorcycle.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/adafruit_led_animation/animation/colorcycle.py b/adafruit_led_animation/animation/colorcycle.py index 5f27954..7251167 100644 --- a/adafruit_led_animation/animation/colorcycle.py +++ b/adafruit_led_animation/animation/colorcycle.py @@ -38,12 +38,13 @@ class ColorCycle(Animation): :param float speed: Animation speed in seconds, e.g. ``0.1``. :param colors: A list of colors to cycle through in ``(r, g, b)`` tuple, or ``0x000000`` hex format. Defaults to a rainbow color cycle. + :param start_color: An index (from 0) for which color to start from. Default 0 (first color given). """ - def __init__(self, pixel_object, speed, colors=RAINBOW, name=None): + def __init__(self, pixel_object, speed, colors=RAINBOW, start_color=0, name=None): self.colors = colors - super().__init__(pixel_object, speed, colors[0], name=name) - self._generator = self._color_generator() + super().__init__(pixel_object, speed, colors[start_color], name=name) + self._generator = self._color_generator(start_color) next(self._generator) on_cycle_complete_supported = True @@ -52,8 +53,8 @@ def draw(self): self.pixel_object.fill(self.color) next(self._generator) - def _color_generator(self): - index = 0 + def _color_generator(self, start_color): + index = start_color while True: self._color = self.colors[index] yield From da467ce9b7eeddfe64ee0a6783b02430729235f7 Mon Sep 17 00:00:00 2001 From: tneish <30879076+tneish@users.noreply.github.com> Date: Sat, 16 Dec 2023 11:23:17 +0100 Subject: [PATCH 64/88] Fix pylint errors --- adafruit_led_animation/animation/colorcycle.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/adafruit_led_animation/animation/colorcycle.py b/adafruit_led_animation/animation/colorcycle.py index 7251167..c945351 100644 --- a/adafruit_led_animation/animation/colorcycle.py +++ b/adafruit_led_animation/animation/colorcycle.py @@ -38,11 +38,13 @@ class ColorCycle(Animation): :param float speed: Animation speed in seconds, e.g. ``0.1``. :param colors: A list of colors to cycle through in ``(r, g, b)`` tuple, or ``0x000000`` hex format. Defaults to a rainbow color cycle. - :param start_color: An index (from 0) for which color to start from. Default 0 (first color given). + :param start_color: An index (from 0) for which color to start from. Default 0 (first color). """ - + + # pylint: disable=too-many-arguments def __init__(self, pixel_object, speed, colors=RAINBOW, start_color=0, name=None): self.colors = colors + self.start_color = start_color super().__init__(pixel_object, speed, colors[start_color], name=name) self._generator = self._color_generator(start_color) next(self._generator) @@ -66,4 +68,4 @@ def reset(self): """ Resets to the first color. """ - self._generator = self._color_generator() + self._generator = self._color_generator(self.start_color) From fc1aefafcadd6d0cfd03c217b49734f3b6706b84 Mon Sep 17 00:00:00 2001 From: Tyler Winfield Date: Tue, 19 Dec 2023 22:01:30 -0600 Subject: [PATCH 65/88] Adds min_intensity and max_intensity support back to Pulse animation. Introduces a 'breath' value (default 0) to give a duration to hold the minimum and maximum intensity during the animation for smoother changes in direction. --- adafruit_led_animation/animation/pulse.py | 8 +++++++- adafruit_led_animation/animation/sparklepulse.py | 3 +++ adafruit_led_animation/helper.py | 9 +++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/adafruit_led_animation/animation/pulse.py b/adafruit_led_animation/animation/pulse.py index fdd4a7c..849b457 100644 --- a/adafruit_led_animation/animation/pulse.py +++ b/adafruit_led_animation/animation/pulse.py @@ -37,12 +37,18 @@ class Pulse(Animation): :param float speed: Animation refresh rate in seconds, e.g. ``0.1``. :param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format. :param period: Period to pulse the LEDs over. Default 5. + :param breath: Duration to hold minimum and maximum intensity levels. Default 0. + :param min_intensity: Lowest brightness level of the pulse. Default 0. + :param max_intensity: Highest brightness elvel of the pulse. Default 1. """ # pylint: disable=too-many-arguments - def __init__(self, pixel_object, speed, color, period=5, name=None): + def __init__(self, pixel_object, speed, color, period=5, breath=0, min_intensity=0, max_intensity=1, name=None): super().__init__(pixel_object, speed, color, name=name) self._period = period + self._breath = breath + self._min_intensity = min_intensity + self._max_intensity = max_intensity self._generator = None self.reset() diff --git a/adafruit_led_animation/animation/sparklepulse.py b/adafruit_led_animation/animation/sparklepulse.py index efb0d1d..2132005 100644 --- a/adafruit_led_animation/animation/sparklepulse.py +++ b/adafruit_led_animation/animation/sparklepulse.py @@ -38,6 +38,7 @@ class SparklePulse(Sparkle): :param int speed: Animation refresh rate in seconds, e.g. ``0.1``. :param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format. :param period: Period to pulse the LEDs over. Default 5. + :param breath: Duration to hold minimum and maximum intensity. Default 0. :param max_intensity: The maximum intensity to pulse, between 0 and 1.0. Default 1. :param min_intensity: The minimum intensity to pulse, between 0 and 1.0. Default 0. """ @@ -49,6 +50,7 @@ def __init__( speed, color, period=5, + breath=0, max_intensity=1, min_intensity=0, name=None, @@ -56,6 +58,7 @@ def __init__( self._max_intensity = max_intensity self._min_intensity = min_intensity self._period = period + self._breath = breath dotstar = len(pixel_object) == 4 and isinstance(pixel_object[0][-1], float) super().__init__( pixel_object, speed=speed, color=color, num_sparkles=1, name=name diff --git a/adafruit_led_animation/helper.py b/adafruit_led_animation/helper.py index 126ea74..822a74c 100644 --- a/adafruit_led_animation/helper.py +++ b/adafruit_led_animation/helper.py @@ -322,7 +322,8 @@ def pulse_generator(period: float, animation_object, dotstar_pwm=False): :param animation_object: An animation object to interact with. :param dotstar_pwm: Whether to use the dostar per pixel PWM value for brightness control. """ - period = int(period * MS_PER_SECOND) + period = int((period + (animation_object._breath * 2)) * MS_PER_SECOND) + breath = int(animation_object._breath * MS_PER_SECOND) half_period = period // 2 last_update = monotonic_ms() @@ -338,7 +339,11 @@ def pulse_generator(period: float, animation_object, dotstar_pwm=False): last_pos = pos if pos > half_period: pos = period - pos - intensity = pos / half_period + intensity = animation_object._min_intensity + ((pos / (half_period - breath)) * (animation_object._max_intensity - animation_object._min_intensity)) + if pos < half_period and pos > (half_period - breath): + intensity = animation_object._max_intensity + if pos > (period - breath): + intensity = animation_object._min_intensity if dotstar_pwm: fill_color = ( animation_object.color[0], From f16e51999154f72075a788a392b91ad4b2ce68be Mon Sep 17 00:00:00 2001 From: Tyler Winfield Date: Tue, 19 Dec 2023 23:04:12 -0600 Subject: [PATCH 66/88] Corrected variable scoping --- adafruit_led_animation/animation/pulse.py | 6 +++--- adafruit_led_animation/animation/sparklepulse.py | 6 +++--- adafruit_led_animation/helper.py | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/adafruit_led_animation/animation/pulse.py b/adafruit_led_animation/animation/pulse.py index 849b457..b5ff3d7 100644 --- a/adafruit_led_animation/animation/pulse.py +++ b/adafruit_led_animation/animation/pulse.py @@ -46,9 +46,9 @@ class Pulse(Animation): def __init__(self, pixel_object, speed, color, period=5, breath=0, min_intensity=0, max_intensity=1, name=None): super().__init__(pixel_object, speed, color, name=name) self._period = period - self._breath = breath - self._min_intensity = min_intensity - self._max_intensity = max_intensity + self.breath = breath + self.min_intensity = min_intensity + self.max_intensity = max_intensity self._generator = None self.reset() diff --git a/adafruit_led_animation/animation/sparklepulse.py b/adafruit_led_animation/animation/sparklepulse.py index 2132005..0976f9e 100644 --- a/adafruit_led_animation/animation/sparklepulse.py +++ b/adafruit_led_animation/animation/sparklepulse.py @@ -55,10 +55,10 @@ def __init__( min_intensity=0, name=None, ): - self._max_intensity = max_intensity - self._min_intensity = min_intensity self._period = period - self._breath = breath + self.breath = breath + self.min_intensity = min_intensity + self.max_intensity = max_intensity dotstar = len(pixel_object) == 4 and isinstance(pixel_object[0][-1], float) super().__init__( pixel_object, speed=speed, color=color, num_sparkles=1, name=name diff --git a/adafruit_led_animation/helper.py b/adafruit_led_animation/helper.py index 822a74c..466ef63 100644 --- a/adafruit_led_animation/helper.py +++ b/adafruit_led_animation/helper.py @@ -322,8 +322,8 @@ def pulse_generator(period: float, animation_object, dotstar_pwm=False): :param animation_object: An animation object to interact with. :param dotstar_pwm: Whether to use the dostar per pixel PWM value for brightness control. """ - period = int((period + (animation_object._breath * 2)) * MS_PER_SECOND) - breath = int(animation_object._breath * MS_PER_SECOND) + period = int((period + (animation_object.breath * 2)) * MS_PER_SECOND) + breath = int(animation_object.breath * MS_PER_SECOND) half_period = period // 2 last_update = monotonic_ms() @@ -339,11 +339,11 @@ def pulse_generator(period: float, animation_object, dotstar_pwm=False): last_pos = pos if pos > half_period: pos = period - pos - intensity = animation_object._min_intensity + ((pos / (half_period - breath)) * (animation_object._max_intensity - animation_object._min_intensity)) + intensity = animation_object.min_intensity + ((pos / (half_period - breath)) * (animation_object.max_intensity - animation_object.min_intensity)) if pos < half_period and pos > (half_period - breath): - intensity = animation_object._max_intensity + intensity = animation_object.max_intensity if pos > (period - breath): - intensity = animation_object._min_intensity + intensity = animation_object.min_intensity if dotstar_pwm: fill_color = ( animation_object.color[0], From a855c3b99eb1f5551259fdfd02805cf7e1ec35f1 Mon Sep 17 00:00:00 2001 From: Tyler Winfield Date: Tue, 19 Dec 2023 23:16:10 -0600 Subject: [PATCH 67/88] Simplified comparison chain --- adafruit_led_animation/helper.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/adafruit_led_animation/helper.py b/adafruit_led_animation/helper.py index 466ef63..496ee18 100644 --- a/adafruit_led_animation/helper.py +++ b/adafruit_led_animation/helper.py @@ -339,11 +339,12 @@ def pulse_generator(period: float, animation_object, dotstar_pwm=False): last_pos = pos if pos > half_period: pos = period - pos - intensity = animation_object.min_intensity + ((pos / (half_period - breath)) * (animation_object.max_intensity - animation_object.min_intensity)) - if pos < half_period and pos > (half_period - breath): + if pos < half_period and pox > (half_period - breath): intensity = animation_object.max_intensity - if pos > (period - breath): + elif pos > (period - breath): intensity = animation_object.min_intensity + else: + intensity = animation_object.min_intensity + ((pos / (half_period - breath)) * (animation_object.max_intensity - animation_object.min_intensity)) if dotstar_pwm: fill_color = ( animation_object.color[0], From 72c6c684517288343a836d9da62198d2c0af8b34 Mon Sep 17 00:00:00 2001 From: Tyler Winfield Date: Tue, 19 Dec 2023 23:20:06 -0600 Subject: [PATCH 68/88] Variable type-o --- adafruit_led_animation/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_led_animation/helper.py b/adafruit_led_animation/helper.py index 496ee18..e1ad24f 100644 --- a/adafruit_led_animation/helper.py +++ b/adafruit_led_animation/helper.py @@ -339,7 +339,7 @@ def pulse_generator(period: float, animation_object, dotstar_pwm=False): last_pos = pos if pos > half_period: pos = period - pos - if pos < half_period and pox > (half_period - breath): + if pos < half_period and pos > (half_period - breath): intensity = animation_object.max_intensity elif pos > (period - breath): intensity = animation_object.min_intensity From 1293a471ebf9a0ba970671011dbfa2438c091802 Mon Sep 17 00:00:00 2001 From: Tyler Winfield Date: Wed, 20 Dec 2023 11:47:39 -0600 Subject: [PATCH 69/88] Corrected position calculation after introducing breath pauses --- adafruit_led_animation/helper.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/adafruit_led_animation/helper.py b/adafruit_led_animation/helper.py index e1ad24f..73ec102 100644 --- a/adafruit_led_animation/helper.py +++ b/adafruit_led_animation/helper.py @@ -323,7 +323,7 @@ def pulse_generator(period: float, animation_object, dotstar_pwm=False): :param dotstar_pwm: Whether to use the dostar per pixel PWM value for brightness control. """ period = int((period + (animation_object.breath * 2)) * MS_PER_SECOND) - breath = int(animation_object.breath * MS_PER_SECOND) + half_breath = int(animation_object.breath * MS_PER_SECOND // 2) half_period = period // 2 last_update = monotonic_ms() @@ -339,12 +339,12 @@ def pulse_generator(period: float, animation_object, dotstar_pwm=False): last_pos = pos if pos > half_period: pos = period - pos - if pos < half_period and pos > (half_period - breath): - intensity = animation_object.max_intensity - elif pos > (period - breath): + if pos < half_breath: intensity = animation_object.min_intensity + elif pos > (half_period - half_breath): + intensity = animation_object.max_intensity else: - intensity = animation_object.min_intensity + ((pos / (half_period - breath)) * (animation_object.max_intensity - animation_object.min_intensity)) + intensity = animation_object.min_intensity + (((pos - half_breath) / (half_period - (half_breath * 2))) * (animation_object.max_intensity - animation_object.min_intensity)) if dotstar_pwm: fill_color = ( animation_object.color[0], From 43aa654b4d7c115ec523f802633230feff9f58e4 Mon Sep 17 00:00:00 2001 From: tneish <30879076+tneish@users.noreply.github.com> Date: Wed, 27 Dec 2023 22:33:33 +0100 Subject: [PATCH 70/88] cycle complete at start_color --- adafruit_led_animation/animation/colorcycle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_led_animation/animation/colorcycle.py b/adafruit_led_animation/animation/colorcycle.py index c945351..5f3b244 100644 --- a/adafruit_led_animation/animation/colorcycle.py +++ b/adafruit_led_animation/animation/colorcycle.py @@ -40,7 +40,7 @@ class ColorCycle(Animation): format. Defaults to a rainbow color cycle. :param start_color: An index (from 0) for which color to start from. Default 0 (first color). """ - + # pylint: disable=too-many-arguments def __init__(self, pixel_object, speed, colors=RAINBOW, start_color=0, name=None): self.colors = colors @@ -61,7 +61,7 @@ def _color_generator(self, start_color): self._color = self.colors[index] yield index = (index + 1) % len(self.colors) - if index == 0: + if index == start_color: self.cycle_complete = True def reset(self): From cba51fb34b2c1b49ffc5d9ae694ba29d8f6a7be3 Mon Sep 17 00:00:00 2001 From: tneish <30879076+tneish@users.noreply.github.com> Date: Wed, 27 Dec 2023 22:40:48 +0100 Subject: [PATCH 71/88] Update adafruit_led_animation/animation/colorcycle.py Adding the new arg to the end will make any calls upward.compatible Co-authored-by: Dan Halbert --- adafruit_led_animation/animation/colorcycle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_led_animation/animation/colorcycle.py b/adafruit_led_animation/animation/colorcycle.py index 5f3b244..41bff44 100644 --- a/adafruit_led_animation/animation/colorcycle.py +++ b/adafruit_led_animation/animation/colorcycle.py @@ -42,7 +42,7 @@ class ColorCycle(Animation): """ # pylint: disable=too-many-arguments - def __init__(self, pixel_object, speed, colors=RAINBOW, start_color=0, name=None): + def __init__(self, pixel_object, speed, colors=RAINBOW, name=None, start_color=0): self.colors = colors self.start_color = start_color super().__init__(pixel_object, speed, colors[start_color], name=name) From 786cd806fc8e5da5a8df0a5faa6b423742063d73 Mon Sep 17 00:00:00 2001 From: Tyler Winfield Date: Thu, 28 Dec 2023 09:01:11 -0600 Subject: [PATCH 72/88] Resolving build CI errors --- adafruit_led_animation/animation/pulse.py | 12 +++++++++++- adafruit_led_animation/helper.py | 5 ++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/adafruit_led_animation/animation/pulse.py b/adafruit_led_animation/animation/pulse.py index b5ff3d7..ee10ca7 100644 --- a/adafruit_led_animation/animation/pulse.py +++ b/adafruit_led_animation/animation/pulse.py @@ -43,7 +43,17 @@ class Pulse(Animation): """ # pylint: disable=too-many-arguments - def __init__(self, pixel_object, speed, color, period=5, breath=0, min_intensity=0, max_intensity=1, name=None): + def __init__( + self, + pixel_object, + speed, + color, + period=5, + breath=0, + min_intensity=0, + max_intensity=1, + name=None, + ): super().__init__(pixel_object, speed, color, name=name) self._period = period self.breath = breath diff --git a/adafruit_led_animation/helper.py b/adafruit_led_animation/helper.py index 73ec102..6d876e1 100644 --- a/adafruit_led_animation/helper.py +++ b/adafruit_led_animation/helper.py @@ -344,7 +344,10 @@ def pulse_generator(period: float, animation_object, dotstar_pwm=False): elif pos > (half_period - half_breath): intensity = animation_object.max_intensity else: - intensity = animation_object.min_intensity + (((pos - half_breath) / (half_period - (half_breath * 2))) * (animation_object.max_intensity - animation_object.min_intensity)) + intensity = animation_object.min_intensity + ( + ((pos - half_breath) / (half_period - (half_breath * 2))) + * (animation_object.max_intensity - animation_object.min_intensity) + ) if dotstar_pwm: fill_color = ( animation_object.color[0], From ef3ab8ae2da7b5e3caa3ae3bfa33229be2e01235 Mon Sep 17 00:00:00 2001 From: Samed Ozdemir Date: Sat, 6 Jul 2024 11:41:48 -0400 Subject: [PATCH 73/88] fix: move pulse generator from helper to own file to reduce memory footprint when imported --- adafruit_led_animation/animation/pulse.py | 2 +- .../animation/sparklepulse.py | 2 +- adafruit_led_animation/helper.py | 48 ------------ adafruit_led_animation/pulse_generator.py | 74 +++++++++++++++++++ 4 files changed, 76 insertions(+), 50 deletions(-) create mode 100644 adafruit_led_animation/pulse_generator.py diff --git a/adafruit_led_animation/animation/pulse.py b/adafruit_led_animation/animation/pulse.py index ee10ca7..7038ce2 100644 --- a/adafruit_led_animation/animation/pulse.py +++ b/adafruit_led_animation/animation/pulse.py @@ -75,7 +75,7 @@ def reset(self): dotstar = len(self.pixel_object[0]) == 4 and isinstance( self.pixel_object[0][-1], float ) - from adafruit_led_animation.helper import ( # pylint: disable=import-outside-toplevel + from adafruit_led_animation.pulse_generator import ( # pylint: disable=import-outside-toplevel pulse_generator, ) diff --git a/adafruit_led_animation/animation/sparklepulse.py b/adafruit_led_animation/animation/sparklepulse.py index 0976f9e..b85f644 100644 --- a/adafruit_led_animation/animation/sparklepulse.py +++ b/adafruit_led_animation/animation/sparklepulse.py @@ -27,7 +27,7 @@ """ from adafruit_led_animation.animation.sparkle import Sparkle -from adafruit_led_animation.helper import pulse_generator +from adafruit_led_animation.pulse_generator import pulse_generator class SparklePulse(Sparkle): diff --git a/adafruit_led_animation/helper.py b/adafruit_led_animation/helper.py index 6d876e1..b033b58 100644 --- a/adafruit_led_animation/helper.py +++ b/adafruit_led_animation/helper.py @@ -27,9 +27,6 @@ import math -from . import MS_PER_SECOND, monotonic_ms -from .color import calculate_intensity - class PixelMap: """ @@ -313,48 +310,3 @@ def __init__(self, pixel_object, start, end): pixel_ranges=[[n] for n in range(start, end)], individual_pixels=True, ) - - -def pulse_generator(period: float, animation_object, dotstar_pwm=False): - """ - Generates a sequence of colors for a pulse, based on the time period specified. - :param period: Pulse duration in seconds. - :param animation_object: An animation object to interact with. - :param dotstar_pwm: Whether to use the dostar per pixel PWM value for brightness control. - """ - period = int((period + (animation_object.breath * 2)) * MS_PER_SECOND) - half_breath = int(animation_object.breath * MS_PER_SECOND // 2) - half_period = period // 2 - - last_update = monotonic_ms() - cycle_position = 0 - last_pos = 0 - while True: - now = monotonic_ms() - time_since_last_draw = now - last_update - last_update = now - pos = cycle_position = (cycle_position + time_since_last_draw) % period - if pos < last_pos: - animation_object.cycle_complete = True - last_pos = pos - if pos > half_period: - pos = period - pos - if pos < half_breath: - intensity = animation_object.min_intensity - elif pos > (half_period - half_breath): - intensity = animation_object.max_intensity - else: - intensity = animation_object.min_intensity + ( - ((pos - half_breath) / (half_period - (half_breath * 2))) - * (animation_object.max_intensity - animation_object.min_intensity) - ) - if dotstar_pwm: - fill_color = ( - animation_object.color[0], - animation_object.color[1], - animation_object.color[2], - intensity, - ) - yield fill_color - continue - yield calculate_intensity(animation_object.color, intensity) diff --git a/adafruit_led_animation/pulse_generator.py b/adafruit_led_animation/pulse_generator.py new file mode 100644 index 0000000..e29b04f --- /dev/null +++ b/adafruit_led_animation/pulse_generator.py @@ -0,0 +1,74 @@ +# SPDX-FileCopyrightText: 2019 Kattni Rembor for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +""" +`adafruit_led_animation.pulse_generator` +================================================================================ + +Helper method for pulse generation + +* Author(s): Kattni Rembor + +Implementation Notes +-------------------- + +**Hardware:** + +* `Adafruit NeoPixels `_ +* `Adafruit DotStars `_ + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://circuitpython.org/downloads + +""" + +from . import MS_PER_SECOND, monotonic_ms +from .color import calculate_intensity + + +def pulse_generator(period: float, animation_object, dotstar_pwm=False): + """ + Generates a sequence of colors for a pulse, based on the time period specified. + :param period: Pulse duration in seconds. + :param animation_object: An animation object to interact with. + :param dotstar_pwm: Whether to use the dostar per pixel PWM value for brightness control. + """ + period = int((period + (animation_object.breath * 2)) * MS_PER_SECOND) + half_breath = int(animation_object.breath * MS_PER_SECOND // 2) + half_period = period // 2 + + last_update = monotonic_ms() + cycle_position = 0 + last_pos = 0 + while True: + now = monotonic_ms() + time_since_last_draw = now - last_update + last_update = now + pos = cycle_position = (cycle_position + time_since_last_draw) % period + if pos < last_pos: + animation_object.cycle_complete = True + last_pos = pos + if pos > half_period: + pos = period - pos + if pos < half_breath: + intensity = animation_object.min_intensity + elif pos > (half_period - half_breath): + intensity = animation_object.max_intensity + else: + intensity = animation_object.min_intensity + ( + ((pos - half_breath) / (half_period - (half_breath * 2))) + * (animation_object.max_intensity - animation_object.min_intensity) + ) + if dotstar_pwm: + fill_color = ( + animation_object.color[0], + animation_object.color[1], + animation_object.color[2], + intensity, + ) + yield fill_color + continue + yield calculate_intensity(animation_object.color, intensity) From 3d91a7862148bf9dde12d00db6aa518536a02702 Mon Sep 17 00:00:00 2001 From: indomitableSwan <5496520+indomitableSwan@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:14:52 -0400 Subject: [PATCH 74/88] Move misplaced computation of `wheel_index` into the case for `precompute_rainbow=True` --- adafruit_led_animation/animation/rainbow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_led_animation/animation/rainbow.py b/adafruit_led_animation/animation/rainbow.py index c5ad620..5c2b35b 100644 --- a/adafruit_led_animation/animation/rainbow.py +++ b/adafruit_led_animation/animation/rainbow.py @@ -85,9 +85,9 @@ def _color_wheel_generator(self): if pos < last_pos: cycle_completed = True last_pos = pos - wheel_index = int((pos / period) * len(self.colors)) if self.colors: + wheel_index = int((pos / period) * len(self.colors)) self._draw_precomputed(num_pixels, wheel_index) else: wheel_index = int((pos / period) * 256) From 389e40119d964966ab30e72324d3b6e8841ceb7d Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 7 Oct 2024 09:24:05 -0500 Subject: [PATCH 75/88] remove deprecated get_html_theme_path() call Signed-off-by: foamyguy --- docs/conf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index fd9b7a6..7fc34d9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -104,7 +104,6 @@ import sphinx_rtd_theme html_theme = "sphinx_rtd_theme" -html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, From 5badc804f7ec6d35fa00430cfe3628e3ef039fa9 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 13 Dec 2024 10:36:07 -0600 Subject: [PATCH 76/88] public property for rainbow.period --- adafruit_led_animation/animation/rainbow.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/adafruit_led_animation/animation/rainbow.py b/adafruit_led_animation/animation/rainbow.py index 5c2b35b..356c7d6 100644 --- a/adafruit_led_animation/animation/rainbow.py +++ b/adafruit_led_animation/animation/rainbow.py @@ -123,3 +123,12 @@ def reset(self): Resets the animation. """ self._generator = self._color_wheel_generator() + + @property + def period(self) -> float: + return self._period + + @period.setter + def period(self, new_value: float) -> None: + self._period = new_value + self.reset() From 7dc67c5c70b690470e45affcfa453b863f856882 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 13 Dec 2024 10:45:59 -0600 Subject: [PATCH 77/88] add docstring --- adafruit_led_animation/animation/rainbow.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/adafruit_led_animation/animation/rainbow.py b/adafruit_led_animation/animation/rainbow.py index 356c7d6..2f7039a 100644 --- a/adafruit_led_animation/animation/rainbow.py +++ b/adafruit_led_animation/animation/rainbow.py @@ -126,6 +126,9 @@ def reset(self): @property def period(self) -> float: + """ + Period to cycle the rainbow over in seconds. + """ return self._period @period.setter From ee5301b9380df41c7bd0bf7e0e98a4e8a97c4ec2 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 13 Dec 2024 10:56:56 -0600 Subject: [PATCH 78/88] format --- adafruit_led_animation/animation/rainbow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_led_animation/animation/rainbow.py b/adafruit_led_animation/animation/rainbow.py index 2f7039a..2825fb0 100644 --- a/adafruit_led_animation/animation/rainbow.py +++ b/adafruit_led_animation/animation/rainbow.py @@ -127,7 +127,7 @@ def reset(self): @property def period(self) -> float: """ - Period to cycle the rainbow over in seconds. + Period to cycle the rainbow over in seconds. """ return self._period From bac273b46d31082f886351420664dbe48c9445e2 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 13 Dec 2024 11:52:07 -0600 Subject: [PATCH 79/88] rainbow commet fix for tail_length > 256 --- adafruit_led_animation/animation/rainbowcomet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_led_animation/animation/rainbowcomet.py b/adafruit_led_animation/animation/rainbowcomet.py index beae255..c22a71f 100644 --- a/adafruit_led_animation/animation/rainbowcomet.py +++ b/adafruit_led_animation/animation/rainbowcomet.py @@ -60,7 +60,7 @@ def __init__( ring=False, ): if step == 0: - self._colorwheel_step = int(256 / tail_length) + self._colorwheel_step = max(int(256 / tail_length), 1) else: self._colorwheel_step = step self._colorwheel_offset = colorwheel_offset From 6ef0715b77c3b286f646db943eb1a30454044883 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Dec 2024 14:47:32 -0600 Subject: [PATCH 80/88] integer division --- adafruit_led_animation/animation/rainbowcomet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_led_animation/animation/rainbowcomet.py b/adafruit_led_animation/animation/rainbowcomet.py index c22a71f..6d4ce19 100644 --- a/adafruit_led_animation/animation/rainbowcomet.py +++ b/adafruit_led_animation/animation/rainbowcomet.py @@ -60,7 +60,7 @@ def __init__( ring=False, ): if step == 0: - self._colorwheel_step = max(int(256 / tail_length), 1) + self._colorwheel_step = max(256 // tail_length, 1) else: self._colorwheel_step = step self._colorwheel_offset = colorwheel_offset From 0b66cc1c113d8cef0ad4218cb41de5848c38251d Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 20 Dec 2024 17:56:28 -0600 Subject: [PATCH 81/88] add period property to pulse and sparklepulse, fix typo --- adafruit_led_animation/animation/pulse.py | 14 +++++++++++++- .../animation/sparklepulse.py | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/adafruit_led_animation/animation/pulse.py b/adafruit_led_animation/animation/pulse.py index 7038ce2..ec1373d 100644 --- a/adafruit_led_animation/animation/pulse.py +++ b/adafruit_led_animation/animation/pulse.py @@ -39,7 +39,7 @@ class Pulse(Animation): :param period: Period to pulse the LEDs over. Default 5. :param breath: Duration to hold minimum and maximum intensity levels. Default 0. :param min_intensity: Lowest brightness level of the pulse. Default 0. - :param max_intensity: Highest brightness elvel of the pulse. Default 1. + :param max_intensity: Highest brightness level of the pulse. Default 1. """ # pylint: disable=too-many-arguments @@ -80,3 +80,15 @@ def reset(self): ) self._generator = pulse_generator(self._period, self, dotstar_pwm=dotstar) + + @property + def period(self): + """ + Period to pulse the LEDs over in seconds + """ + return self._period + + @period.setter + def period(self, new_value): + self._period = new_value + self.reset() diff --git a/adafruit_led_animation/animation/sparklepulse.py b/adafruit_led_animation/animation/sparklepulse.py index b85f644..00133a7 100644 --- a/adafruit_led_animation/animation/sparklepulse.py +++ b/adafruit_led_animation/animation/sparklepulse.py @@ -74,3 +74,21 @@ def draw(self): def after_draw(self): self.show() + + @property + def period(self): + """ + Period to pulse the LEDs over in seconds + """ + return self._period + + @period.setter + def period(self, new_value): + self._period = new_value + self.reset() + + def reset(self): + dotstar = len(self.pixel_object) == 4 and isinstance( + self.pixel_object[0][-1], float + ) + self._generator = pulse_generator(self._period, self, dotstar_pwm=dotstar) From 83b87ef8673c8b33bf7e57b0c2ab49ff9e310df6 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 14 Jan 2025 11:32:34 -0600 Subject: [PATCH 82/88] add sphinx configuration to rtd.yaml Signed-off-by: foamyguy --- .readthedocs.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 33c2a61..88bca9f 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,6 +8,9 @@ # Required version: 2 +sphinx: + configuration: docs/conf.py + build: os: ubuntu-20.04 tools: From c7dc90179165658f2369b923d0934391f7675879 Mon Sep 17 00:00:00 2001 From: jposada2020 Date: Wed, 5 Feb 2025 17:02:54 -0500 Subject: [PATCH 83/88] Blink animation with a user selected background color --- adafruit_led_animation/animation/blink.py | 13 ++++++-- docs/examples.rst | 8 +++++ .../led_animation_blink_with_background.py | 31 +++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 examples/led_animation_blink_with_background.py diff --git a/adafruit_led_animation/animation/blink.py b/adafruit_led_animation/animation/blink.py index 34de026..3b8d62b 100644 --- a/adafruit_led_animation/animation/blink.py +++ b/adafruit_led_animation/animation/blink.py @@ -37,10 +37,17 @@ class Blink(ColorCycle): :param pixel_object: The initialised LED object. :param float speed: Animation speed in seconds, e.g. ``0.1``. :param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format. + :param background_color: Background color in ``(r, g, b)`` tuple, or ``0x000000`` hex format. Defaults to BLACK. + :param name: A human-readable name for the Animation. Used by the string function. """ - def __init__(self, pixel_object, speed, color, name=None): - super().__init__(pixel_object, speed, [color, BLACK], name=name) + def __init__( + self, pixel_object, speed, color, background_color=BLACK, name=None + ): + self._background_color = background_color + super().__init__( + pixel_object, speed, [color, background_color], name=name + ) def _set_color(self, color): - self.colors = [color, BLACK] + self.colors = [color, self._background_color] diff --git a/docs/examples.rst b/docs/examples.rst index f45d96d..d974958 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -61,6 +61,14 @@ Demonstrates the blink animation. :caption: examples/led_animation_blink.py :linenos: +Blink with a selcted background color +---------------------------------------- +Demonstrates the blink animation with an user defined background color. + +.. literalinclude:: ../examples/led_animation_blink_with_background.py + :caption: examples/led_animation_blink_with_background.py + :linenos: + Comet ----- diff --git a/examples/led_animation_blink_with_background.py b/examples/led_animation_blink_with_background.py new file mode 100644 index 0000000..c9c4910 --- /dev/null +++ b/examples/led_animation_blink_with_background.py @@ -0,0 +1,31 @@ +# SPDX-FileCopyrightText: 2025 Jose D. Montoya +# SPDX-License-Identifier: MIT + +""" +This example blinks the LEDs purple with a yellow background at a 0.5 second interval. + +For QT Py Haxpress and a NeoPixel strip. Update pixel_pin and pixel_num to match your wiring if +using a different board or form of NeoPixels. + +This example will run on SAMD21 (M0) Express boards (such as Circuit Playground Express or QT Py +Haxpress), but not on SAMD21 non-Express boards (such as QT Py or Trinket). +""" +import board +import neopixel + +from adafruit_led_animation.animation.blink import Blink +from adafruit_led_animation.color import PURPLE, YELLOW + +# Update to match the pin connected to your NeoPixels +pixel_pin = board.A3 +# Update to match the number of NeoPixels you have connected +pixel_num = 30 + +pixels = neopixel.NeoPixel( + pixel_pin, pixel_num, brightness=0.5, auto_write=False +) + +blink = Blink(pixels, speed=0.5, color=PURPLE, background_color=YELLOW) + +while True: + blink.animate() From 34bcf3c5355f579364aab52febb2f7ea95ffc869 Mon Sep 17 00:00:00 2001 From: jposada2020 Date: Wed, 5 Feb 2025 17:10:48 -0500 Subject: [PATCH 84/88] formating --- adafruit_led_animation/animation/blink.py | 12 +++++------- adafruit_led_animation/animation/volume.py | 17 +++++++++++++++-- adafruit_led_animation/sequence.py | 2 +- examples/led_animation_blink_with_background.py | 4 +--- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/adafruit_led_animation/animation/blink.py b/adafruit_led_animation/animation/blink.py index 3b8d62b..0582332 100644 --- a/adafruit_led_animation/animation/blink.py +++ b/adafruit_led_animation/animation/blink.py @@ -37,17 +37,15 @@ class Blink(ColorCycle): :param pixel_object: The initialised LED object. :param float speed: Animation speed in seconds, e.g. ``0.1``. :param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format. - :param background_color: Background color in ``(r, g, b)`` tuple, or ``0x000000`` hex format. Defaults to BLACK. + :param background_color: Background color in ``(r, g, b)`` tuple, or ``0x000000`` + hex format. Defaults to BLACK. :param name: A human-readable name for the Animation. Used by the string function. """ - def __init__( - self, pixel_object, speed, color, background_color=BLACK, name=None - ): + # pylint: disable=too-many-arguments + def __init__(self, pixel_object, speed, color, background_color=BLACK, name=None): self._background_color = background_color - super().__init__( - pixel_object, speed, [color, background_color], name=name - ) + super().__init__(pixel_object, speed, [color, background_color], name=name) def _set_color(self, color): self.colors = [color, self._background_color] diff --git a/adafruit_led_animation/animation/volume.py b/adafruit_led_animation/animation/volume.py index cbfb8d1..d3ffc6e 100644 --- a/adafruit_led_animation/animation/volume.py +++ b/adafruit_led_animation/animation/volume.py @@ -44,7 +44,13 @@ class Volume(Animation): # pylint: disable=too-many-arguments def __init__( - self, pixel_object, speed, brightest_color, decoder, max_volume=500, name=None + self, + pixel_object, + speed, + brightest_color, + decoder, + max_volume=500, + name=None, ): self._decoder = decoder self._num_pixels = len(pixel_object) @@ -89,8 +95,15 @@ def draw(self): ) lit_pixels = int( - map_range(self._decoder.rms_level, 0, self._max_volume, 0, self._num_pixels) + map_range( + self._decoder.rms_level, + 0, + self._max_volume, + 0, + self._num_pixels, + ) ) + # pylint: disable=consider-using-min-builtin if lit_pixels > self._num_pixels: lit_pixels = self._num_pixels diff --git a/adafruit_led_animation/sequence.py b/adafruit_led_animation/sequence.py index fe522e9..bf5728f 100644 --- a/adafruit_led_animation/sequence.py +++ b/adafruit_led_animation/sequence.py @@ -73,7 +73,7 @@ class AnimationSequence: animations.animate() """ - # pylint: disable=too-many-instance-attributes + # pylint: disable=too-many-instance-attributes, too-many-arguments def __init__( self, *members, diff --git a/examples/led_animation_blink_with_background.py b/examples/led_animation_blink_with_background.py index c9c4910..4a94e10 100644 --- a/examples/led_animation_blink_with_background.py +++ b/examples/led_animation_blink_with_background.py @@ -21,9 +21,7 @@ # Update to match the number of NeoPixels you have connected pixel_num = 30 -pixels = neopixel.NeoPixel( - pixel_pin, pixel_num, brightness=0.5, auto_write=False -) +pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False) blink = Blink(pixels, speed=0.5, color=PURPLE, background_color=YELLOW) From bfdbe0078ce43882324fed0e5fe19eb6e8333b93 Mon Sep 17 00:00:00 2001 From: jposada2020 Date: Sun, 9 Feb 2025 22:47:22 -0500 Subject: [PATCH 85/88] adding Pacman Animation --- adafruit_led_animation/animation/pacman.py | 129 +++++++++++++++++++++ docs/examples.rst | 9 ++ examples/led_animation_pacman.py | 32 +++++ 3 files changed, 170 insertions(+) create mode 100644 adafruit_led_animation/animation/pacman.py create mode 100644 examples/led_animation_pacman.py diff --git a/adafruit_led_animation/animation/pacman.py b/adafruit_led_animation/animation/pacman.py new file mode 100644 index 0000000..045f2ea --- /dev/null +++ b/adafruit_led_animation/animation/pacman.py @@ -0,0 +1,129 @@ +# SPDX-FileCopyrightText: 2025 Bob Loeffler +# SPDX-FileCopyrightText: 2025 Jose D. Montoya +# +# SPDX-License-Identifier: MIT + +""" +`adafruit_led_animation.animation.pacman` +================================================================================ + +PacMan Animation for CircuitPython helper library for LED animations. +PACMAN ANIMATION Adapted from https://github.com/wled-dev/WLED/pull/4536 # by BobLoeffler68 + +* Author(s): Bob Loeffler, Jose D. Montoya + +Implementation Notes +-------------------- + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://circuitpython.org/downloads + + +""" + +import time +from adafruit_led_animation.animation import Animation +from adafruit_led_animation.color import ( + BLACK, + YELLOW, + RED, + PURPLE, + CYAN, + ORANGE, + BLUE, + WHITE, +) + +ORANGEYELLOW = (255, 136, 0) + + +class Pacman(Animation): + """ + Simulate the Pacman game in a single led strip. + + :param pixel_object: The initialised LED object. + :param float speed: Animation speed rate in seconds, e.g. ``0.1``. + """ + + # pylint: disable=too-many-arguments, too-many-branches + def __init__( + self, + pixel_object, + speed, + color=WHITE, + name=None, + ): + self.num_leds = len(pixel_object) + self.pacman = [YELLOW, 10] + self.ghosts_original = [[RED, 6], [PURPLE, 4], [CYAN, 2], [ORANGE, 0]] + self.ghosts = [[RED, 6], [PURPLE, 4], [CYAN, 2], [ORANGE, 0]] + self.direction = 1 + self.black_dir = -1 + self.flag = "beep" + self.power_pellet = [ORANGEYELLOW, self.num_leds] + self.ghost_timer = time.monotonic() + if self.num_leds > 150: + self.start_blinking_ghosts = self.num_leds // 4 + else: + self.start_blinking_ghosts = self.num_leds // 3 + + super().__init__(pixel_object, speed, color, name=name) + + on_cycle_complete_supported = True + + def draw(self): + """ + Draw the Pacman animation. + :param led_object: led object + :param neopixel_list: list of neopixel colors + :param int num_leds: number of leds. + :param int duration: duration in seconds. Default is 15 seconds + """ + pixel_list = self.pixel_object + pixel_list[-1] = self.power_pellet[0] + + delta = time.monotonic() - self.ghost_timer + if delta > 1: + if self.power_pellet[0] == ORANGEYELLOW: + self.power_pellet[0] = BLACK + else: + self.power_pellet[0] = ORANGEYELLOW + pixel_list[self.power_pellet[1] - 1] = self.power_pellet[0] + + self.ghost_timer = time.monotonic() + + if self.pacman[1] >= self.num_leds - 2: + self.direction = self.direction * -1 + self.black_dir = self.black_dir * -1 + for ghost in self.ghosts: + ghost[0] = BLUE + + pixel_list[self.pacman[1]] = self.pacman[0] + pixel_list[self.pacman[1] + self.black_dir] = BLACK + self.pacman[1] += self.direction + + if ( + self.ghosts[3][1] <= self.start_blinking_ghosts + and self.direction == -1 + ): + if self.flag == "beep": + for i, ghost in enumerate(self.ghosts): + ghost[0] = BLACK + self.flag = "bop" + else: + for i, ghost in enumerate(self.ghosts): + ghost[0] = self.ghosts_original[i][0] + self.flag = "beep" + + for i, ghost in enumerate(self.ghosts): + pixel_list[ghost[1]] = ghost[0] + pixel_list[ghost[1] + self.black_dir] = BLACK + ghost[1] += self.direction + + if self.ghosts[3][1] <= 0: + self.direction = self.direction * -1 + self.black_dir = self.black_dir * -1 + for i, ghost in enumerate(self.ghosts): + ghost[0] = self.ghosts_original[i][0] diff --git a/docs/examples.rst b/docs/examples.rst index d974958..7bb45dd 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -104,3 +104,12 @@ Demonstrates the sparkle animations. .. literalinclude:: ../examples/led_animation_sparkle_animations.py :caption: examples/led_animation_sparkle_animations.py :linenos: + +Pacman +------ + +Demonstrates the pacman animation. + +.. literalinclude:: ../examples/led_animation_pacman.py + :caption: examples/led_animation_pacman.py + :linenos: diff --git a/examples/led_animation_pacman.py b/examples/led_animation_pacman.py new file mode 100644 index 0000000..ff2b4ee --- /dev/null +++ b/examples/led_animation_pacman.py @@ -0,0 +1,32 @@ +# SPDX-FileCopyrightText: 2025 Jose D. Montoya +# SPDX-License-Identifier: MIT + +""" +This example animates a Pacman on a NeoPixel strip. +""" +import board +import neopixel +from adafruit_led_animation.animation.pacman import Pacman +from adafruit_led_animation.color import WHITE + +# Update to match the pin connected to your NeoPixels +pixel_pin = board.D6 +# Update to match the number of NeoPixels you have connected +num_pixels = 50 + +# Create the NeoPixel object +ORDER = neopixel.GRB +pixels = neopixel.NeoPixel( + pixel_pin, + num_pixels, + brightness=1.0, + auto_write=False, + pixel_order=ORDER, +) + +# Create the Pacman animation object +pacman = Pacman(pixels, speed=0.1, color=WHITE) + +# Main loop +while True: + pacman.animate() From a8e057cf93e9239a8c7e97a73972bc92ccff7215 Mon Sep 17 00:00:00 2001 From: jposada2020 Date: Sun, 9 Feb 2025 22:48:07 -0500 Subject: [PATCH 86/88] adding pacman animation --- adafruit_led_animation/animation/pacman.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/adafruit_led_animation/animation/pacman.py b/adafruit_led_animation/animation/pacman.py index 045f2ea..c41eea5 100644 --- a/adafruit_led_animation/animation/pacman.py +++ b/adafruit_led_animation/animation/pacman.py @@ -104,10 +104,7 @@ def draw(self): pixel_list[self.pacman[1] + self.black_dir] = BLACK self.pacman[1] += self.direction - if ( - self.ghosts[3][1] <= self.start_blinking_ghosts - and self.direction == -1 - ): + if self.ghosts[3][1] <= self.start_blinking_ghosts and self.direction == -1: if self.flag == "beep": for i, ghost in enumerate(self.ghosts): ghost[0] = BLACK From 78a74180d05be02fada08aa1a3be0661683216e8 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 24 Apr 2025 15:50:08 -0500 Subject: [PATCH 87/88] lower brightness in pacman example --- examples/led_animation_pacman.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/led_animation_pacman.py b/examples/led_animation_pacman.py index ff2b4ee..c325fd5 100644 --- a/examples/led_animation_pacman.py +++ b/examples/led_animation_pacman.py @@ -19,7 +19,7 @@ pixels = neopixel.NeoPixel( pixel_pin, num_pixels, - brightness=1.0, + brightness=0.5, auto_write=False, pixel_order=ORDER, ) From d06c5ca9df30ccd04a765a85db1d96ae85b6e021 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 16 May 2025 16:29:36 +0000 Subject: [PATCH 88/88] change to ruff --- .gitattributes | 11 + .pre-commit-config.yaml | 43 +- .pylintrc | 399 ------------------ README.rst | 6 +- adafruit_led_animation/__init__.py | 2 +- adafruit_led_animation/animation/__init__.py | 5 +- adafruit_led_animation/animation/blink.py | 1 - adafruit_led_animation/animation/chase.py | 9 +- .../animation/colorcycle.py | 1 - adafruit_led_animation/animation/comet.py | 5 +- .../animation/customcolorchase.py | 1 - adafruit_led_animation/animation/grid_rain.py | 16 +- .../animation/multicolor_comet.py | 2 +- adafruit_led_animation/animation/pacman.py | 10 +- adafruit_led_animation/animation/pulse.py | 7 +- adafruit_led_animation/animation/rainbow.py | 15 +- .../animation/rainbowchase.py | 3 +- .../animation/rainbowcomet.py | 10 +- .../animation/rainbowsparkle.py | 7 +- adafruit_led_animation/animation/sparkle.py | 10 +- .../animation/sparklepulse.py | 9 +- adafruit_led_animation/animation/volume.py | 2 - adafruit_led_animation/color.py | 3 +- adafruit_led_animation/grid.py | 5 +- adafruit_led_animation/group.py | 4 +- adafruit_led_animation/helper.py | 1 - adafruit_led_animation/sequence.py | 17 +- adafruit_led_animation/timedsequence.py | 6 +- docs/api.rst | 3 + docs/conf.py | 8 +- examples/led_animation_all_animations.py | 17 +- examples/led_animation_basic_animations.py | 17 +- examples/led_animation_blink.py | 1 + .../led_animation_blink_with_background.py | 1 + examples/led_animation_chase.py | 1 + examples/led_animation_comet.py | 1 + examples/led_animation_customcolorchase.py | 15 +- examples/led_animation_cycle_animations.py | 4 +- examples/led_animation_freeze_animation.py | 1 + examples/led_animation_group.py | 7 +- examples/led_animation_multicolor_comet.py | 2 + examples/led_animation_pacman.py | 2 + examples/led_animation_pixel_map.py | 23 +- examples/led_animation_rainbow_animations.py | 1 + examples/led_animation_resume_animation.py | 1 + .../led_animation_samd21_reset_interval.py | 6 +- examples/led_animation_sequence.py | 5 +- examples/led_animation_simpletest.py | 2 + examples/led_animation_sparkle_animations.py | 3 +- examples/led_animation_sparkle_mask.py | 3 +- examples/led_animation_timedsequence.py | 6 +- examples/led_animation_volume.py | 4 +- ruff.toml | 108 +++++ 53 files changed, 258 insertions(+), 594 deletions(-) create mode 100644 .gitattributes delete mode 100644 .pylintrc create mode 100644 ruff.toml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..21c125c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +.py text eol=lf +.rst text eol=lf +.txt text eol=lf +.yaml text eol=lf +.toml text eol=lf +.license text eol=lf +.md text eol=lf diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 70ade69..ff19dde 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,42 +1,21 @@ -# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries # # SPDX-License-Identifier: Unlicense repos: - - repo: https://github.com/python/black - rev: 23.3.0 - hooks: - - id: black - - repo: https://github.com/fsfe/reuse-tool - rev: v1.1.2 - hooks: - - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/pycqa/pylint - rev: v2.17.4 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.4 hooks: - - id: pylint - name: pylint (library code) - types: [python] - args: - - --disable=consider-using-f-string - exclude: "^(docs/|examples/|tests/|setup.py$)" - - id: pylint - name: pylint (example code) - description: Run pylint rules on "examples/*.py" files - types: [python] - files: "^examples/" - args: - - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code - - id: pylint - name: pylint (test code) - description: Run pylint rules on "tests/*.py" files - types: [python] - files: "^tests/" - args: - - --disable=missing-docstring,consider-using-f-string,duplicate-code + - id: ruff-format + - id: ruff + args: ["--fix"] + - repo: https://github.com/fsfe/reuse-tool + rev: v3.0.1 + hooks: + - id: reuse diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index f945e92..0000000 --- a/.pylintrc +++ /dev/null @@ -1,399 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# -# SPDX-License-Identifier: Unlicense - -[MASTER] - -# A comma-separated list of package or module names from where C extensions may -# be loaded. Extensions are loading into the active Python interpreter and may -# run arbitrary code -extension-pkg-whitelist= - -# Add files or directories to the ignore-list. They should be base names, not -# paths. -ignore=CVS - -# Add files or directories matching the regex patterns to the ignore-list. The -# regex matches against base names, not paths. -ignore-patterns= - -# Python code to execute, usually for sys.path manipulation such as -# pygtk.require(). -#init-hook= - -# Use multiple processes to speed up Pylint. -jobs=1 - -# List of plugins (as comma separated values of python modules names) to load, -# usually to register additional checkers. -load-plugins=pylint.extensions.no_self_use - -# Pickle collected data for later comparisons. -persistent=yes - -# Specify a configuration file. -#rcfile= - -# Allow loading of arbitrary C extensions. Extensions are imported into the -# active Python interpreter and may run arbitrary code. -unsafe-load-any-extension=no - - -[MESSAGES CONTROL] - -# Only show warnings with the listed confidence levels. Leave empty to show -# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED -confidence= - -# Disable the message, report, category or checker with the given id(s). You -# can either give multiple identifiers separated by comma (,) or put this -# option multiple times (only on the command line, not in the configuration -# file where it should appear only once).You can also use "--disable=all" to -# disable everything first and then reenable specific checks. For example, if -# you want to run only the similarities checker, you can use "--disable=all -# --enable=similarities". If you want to run only the classes checker, but have -# no Warning level messages displayed, use"--disable=all --enable=classes -# --disable=W" -# disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call -disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding - -# Enable the message, report, category or checker with the given id(s). You can -# either give multiple identifier separated by comma (,) or put this option -# multiple time (only on the command line, not in the configuration file where -# it should appear only once). See also the "--disable" option for examples. -enable= - - -[REPORTS] - -# Python expression which should return a note less than 10 (10 is the highest -# note). You have access to the variables errors warning, statement which -# respectively contain the number of errors / warnings messages and the total -# number of statements analyzed. This is used by the global evaluation report -# (RP0004). -evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) - -# Template used to display messages. This is a python new-style format string -# used to format the message information. See doc for all details -#msg-template= - -# Set the output format. Available formats are text, parseable, colorized, json -# and msvs (visual studio).You can also give a reporter class, eg -# mypackage.mymodule.MyReporterClass. -output-format=text - -# Tells whether to display a full report or only the messages -reports=no - -# Activate the evaluation score. -score=yes - - -[REFACTORING] - -# Maximum number of nested blocks for function / method body -max-nested-blocks=5 - - -[LOGGING] - -# Logging modules to check that the string format arguments are in logging -# function parameter format -logging-modules=logging - - -[SPELLING] - -# Spelling dictionary name. Available dictionaries: none. To make it working -# install python-enchant package. -spelling-dict= - -# List of comma separated words that should not be checked. -spelling-ignore-words= - -# A path to a file that contains private dictionary; one word per line. -spelling-private-dict-file= - -# Tells whether to store unknown words to indicated private dictionary in -# --spelling-private-dict-file option instead of raising a message. -spelling-store-unknown-words=no - - -[MISCELLANEOUS] - -# List of note tags to take in consideration, separated by a comma. -# notes=FIXME,XXX,TODO -notes=FIXME,XXX - - -[TYPECHECK] - -# List of decorators that produce context managers, such as -# contextlib.contextmanager. Add to this list to register other decorators that -# produce valid context managers. -contextmanager-decorators=contextlib.contextmanager - -# List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E1101 when accessed. Python regular -# expressions are accepted. -generated-members= - -# Tells whether missing members accessed in mixin class should be ignored. A -# mixin class is detected if its name ends with "mixin" (case insensitive). -ignore-mixin-members=yes - -# This flag controls whether pylint should warn about no-member and similar -# checks whenever an opaque object is returned when inferring. The inference -# can return multiple potential results while evaluating a Python object, but -# some branches might not be evaluated, which results in partial inference. In -# that case, it might be useful to still emit no-member and other checks for -# the rest of the inferred objects. -ignore-on-opaque-inference=yes - -# List of class names for which member attributes should not be checked (useful -# for classes with dynamically set attributes). This supports the use of -# qualified names. -ignored-classes=optparse.Values,thread._local,_thread._local - -# List of module names for which member attributes should not be checked -# (useful for modules/projects where namespaces are manipulated during runtime -# and thus existing member attributes cannot be deduced by static analysis. It -# supports qualified module names, as well as Unix pattern matching. -ignored-modules=board - -# Show a hint with possible names when a member name was not found. The aspect -# of finding the hint is based on edit distance. -missing-member-hint=yes - -# The minimum edit distance a name should have in order to be considered a -# similar match for a missing member name. -missing-member-hint-distance=1 - -# The total number of similar names that should be taken in consideration when -# showing a hint for a missing member. -missing-member-max-choices=1 - - -[VARIABLES] - -# List of additional names supposed to be defined in builtins. Remember that -# you should avoid to define new builtins when possible. -additional-builtins= - -# Tells whether unused global variables should be treated as a violation. -allow-global-unused-variables=yes - -# List of strings which can identify a callback function by name. A callback -# name must start or end with one of those strings. -callbacks=cb_,_cb - -# A regular expression matching the name of dummy variables (i.e. expectedly -# not used). -dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ - -# Argument names that match this expression will be ignored. Default to name -# with leading underscore -ignored-argument-names=_.*|^ignored_|^unused_ - -# Tells whether we should check for unused import in __init__ files. -init-import=no - -# List of qualified module names which can have objects that can redefine -# builtins. -redefining-builtins-modules=six.moves,future.builtins - - -[FORMAT] - -# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. -# expected-line-ending-format= -expected-line-ending-format=LF - -# Regexp for a line that is allowed to be longer than the limit. -ignore-long-lines=^\s*(# )??$ - -# Number of spaces of indent required inside a hanging or continued line. -indent-after-paren=4 - -# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 -# tab). -indent-string=' ' - -# Maximum number of characters on a single line. -max-line-length=100 - -# Maximum number of lines in a module -max-module-lines=1000 - -# Allow the body of a class to be on the same line as the declaration if body -# contains single statement. -single-line-class-stmt=no - -# Allow the body of an if to be on the same line as the test if there is no -# else. -single-line-if-stmt=no - - -[SIMILARITIES] - -# Ignore comments when computing similarities. -ignore-comments=yes - -# Ignore docstrings when computing similarities. -ignore-docstrings=yes - -# Ignore imports when computing similarities. -ignore-imports=yes - -# Minimum lines number of a similarity. -min-similarity-lines=12 - - -[BASIC] - -# Regular expression matching correct argument names -argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct attribute names -attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Bad variable names which should always be refused, separated by a comma -bad-names=foo,bar,baz,toto,tutu,tata - -# Regular expression matching correct class attribute names -class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - -# Regular expression matching correct class names -# class-rgx=[A-Z_][a-zA-Z0-9]+$ -class-rgx=[A-Z_][a-zA-Z0-9_]+$ - -# Regular expression matching correct constant names -const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - -# Minimum line length for functions/classes that require docstrings, shorter -# ones are exempt. -docstring-min-length=-1 - -# Regular expression matching correct function names -function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Good variable names which should always be accepted, separated by a comma -# good-names=i,j,k,ex,Run,_ -good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ - -# Include a hint for the correct naming format with invalid-name -include-naming-hint=no - -# Regular expression matching correct inline iteration names -inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ - -# Regular expression matching correct method names -method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct module names -module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - -# Colon-delimited sets of names that determine each other's naming style when -# the name regexes allow several styles. -name-group= - -# Regular expression which should only match function or class names that do -# not require a docstring. -no-docstring-rgx=^_ - -# List of decorators that produce properties, such as abc.abstractproperty. Add -# to this list to register other decorators that produce valid properties. -property-classes=abc.abstractproperty - -# Regular expression matching correct variable names -variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - - -[IMPORTS] - -# Allow wildcard imports from modules that define __all__. -allow-wildcard-with-all=no - -# Analyse import fallback blocks. This can be used to support both Python 2 and -# 3 compatible code, which means that the block might have code that exists -# only in one or another interpreter, leading to false positives when analysed. -analyse-fallback-blocks=no - -# Deprecated modules which should not be used, separated by a comma -deprecated-modules=optparse,tkinter.tix - -# Create a graph of external dependencies in the given file (report RP0402 must -# not be disabled) -ext-import-graph= - -# Create a graph of every (i.e. internal and external) dependencies in the -# given file (report RP0402 must not be disabled) -import-graph= - -# Create a graph of internal dependencies in the given file (report RP0402 must -# not be disabled) -int-import-graph= - -# Force import order to recognize a module as part of the standard -# compatibility libraries. -known-standard-library= - -# Force import order to recognize a module as part of a third party library. -known-third-party=enchant - - -[CLASSES] - -# List of method names used to declare (i.e. assign) instance attributes. -defining-attr-methods=__init__,__new__,setUp - -# List of member names, which should be excluded from the protected access -# warning. -exclude-protected=_asdict,_fields,_replace,_source,_make - -# List of valid names for the first argument in a class method. -valid-classmethod-first-arg=cls - -# List of valid names for the first argument in a metaclass class method. -valid-metaclass-classmethod-first-arg=mcs - - -[DESIGN] - -# Maximum number of arguments for function / method -max-args=5 - -# Maximum number of attributes for a class (see R0902). -# max-attributes=7 -max-attributes=11 - -# Maximum number of boolean expressions in a if statement -max-bool-expr=5 - -# Maximum number of branch for function / method body -max-branches=12 - -# Maximum number of locals for function / method body -max-locals=15 - -# Maximum number of parents for a class (see R0901). -max-parents=7 - -# Maximum number of public methods for a class (see R0904). -max-public-methods=20 - -# Maximum number of return / yield for function / method body -max-returns=6 - -# Maximum number of statements in function / method body -max-statements=50 - -# Minimum number of public methods for a class (see R0903). -min-public-methods=1 - - -[EXCEPTIONS] - -# Exceptions that will emit a warning when being caught. Defaults to -# "Exception" -overgeneral-exceptions=builtins.Exception diff --git a/README.rst b/README.rst index 582e386..680cea2 100644 --- a/README.rst +++ b/README.rst @@ -13,9 +13,9 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation/actions :alt: Build Status -.. image:: https://img.shields.io/badge/code%20style-black-000000.svg - :target: https://github.com/psf/black - :alt: Code Style: Black +.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json + :target: https://github.com/astral-sh/ruff + :alt: Code Style: Ruff Perform a variety of LED animation tasks diff --git a/adafruit_led_animation/__init__.py b/adafruit_led_animation/__init__.py index ff60e91..a9d8a8c 100644 --- a/adafruit_led_animation/__init__.py +++ b/adafruit_led_animation/__init__.py @@ -12,7 +12,7 @@ from micropython import const except ImportError: - def const(value): # pylint: disable=missing-docstring + def const(value): return value diff --git a/adafruit_led_animation/animation/__init__.py b/adafruit_led_animation/animation/__init__.py index 87e1bf2..76d0af3 100644 --- a/adafruit_led_animation/animation/__init__.py +++ b/adafruit_led_animation/animation/__init__.py @@ -32,13 +32,12 @@ class Animation: - # pylint: disable=too-many-instance-attributes """ Base class for animations. """ + on_cycle_complete_supported = False - # pylint: disable=too-many-arguments def __init__(self, pixel_object, speed, color, peers=None, paused=False, name=None): self.pixel_object = pixel_object self.pixel_object.auto_write = False @@ -61,7 +60,7 @@ def __init__(self, pixel_object, speed, color, peers=None, paused=False, name=No """Number of animation cycles completed.""" def __str__(self): - return "<%s: %s>" % (self.__class__.__name__, self.name) + return f"<{self.__class__.__name__}: {self.name}>" def animate(self, show=True): """ diff --git a/adafruit_led_animation/animation/blink.py b/adafruit_led_animation/animation/blink.py index 0582332..0cba0a5 100644 --- a/adafruit_led_animation/animation/blink.py +++ b/adafruit_led_animation/animation/blink.py @@ -42,7 +42,6 @@ class Blink(ColorCycle): :param name: A human-readable name for the Animation. Used by the string function. """ - # pylint: disable=too-many-arguments def __init__(self, pixel_object, speed, color, background_color=BLACK, name=None): self._background_color = background_color super().__init__(pixel_object, speed, [color, background_color], name=name) diff --git a/adafruit_led_animation/animation/chase.py b/adafruit_led_animation/animation/chase.py index a46a16a..5437ad5 100644 --- a/adafruit_led_animation/animation/chase.py +++ b/adafruit_led_animation/animation/chase.py @@ -43,10 +43,7 @@ class Chase(Animation): :param reverse: Reverse direction of movement. """ - # pylint: disable=too-many-arguments - def __init__( - self, pixel_object, speed, color, size=2, spacing=3, reverse=False, name=None - ): + def __init__(self, pixel_object, speed, color, size=2, spacing=3, reverse=False, name=None): self._size = size self._spacing = spacing self._repeat_width = size + spacing @@ -102,7 +99,7 @@ def bar_colors(): self.cycle_complete = True self._offset = (self._offset + self._direction) % self._repeat_width - def bar_color(self, n, pixel_no=0): # pylint: disable=unused-argument + def bar_color(self, n, pixel_no=0): """ Generate the color for the n'th bar_color in the Chase @@ -112,7 +109,7 @@ def bar_color(self, n, pixel_no=0): # pylint: disable=unused-argument return self.color @staticmethod - def space_color(n, pixel_no=0): # pylint: disable=unused-argument + def space_color(n, pixel_no=0): """ Generate the spacing color for the n'th bar_color in the Chase diff --git a/adafruit_led_animation/animation/colorcycle.py b/adafruit_led_animation/animation/colorcycle.py index 41bff44..1f5908e 100644 --- a/adafruit_led_animation/animation/colorcycle.py +++ b/adafruit_led_animation/animation/colorcycle.py @@ -41,7 +41,6 @@ class ColorCycle(Animation): :param start_color: An index (from 0) for which color to start from. Default 0 (first color). """ - # pylint: disable=too-many-arguments def __init__(self, pixel_object, speed, colors=RAINBOW, name=None, start_color=0): self.colors = colors self.start_color = start_color diff --git a/adafruit_led_animation/animation/comet.py b/adafruit_led_animation/animation/comet.py index 8b393dc..8f80391 100644 --- a/adafruit_led_animation/animation/comet.py +++ b/adafruit_led_animation/animation/comet.py @@ -49,7 +49,6 @@ class Comet(Animation): :param bool ring: Ring mode. Defaults to ``False``. """ - # pylint: disable=too-many-arguments,too-many-instance-attributes def __init__( self, pixel_object, @@ -90,9 +89,7 @@ def __init__( def _set_color(self, color): self._comet_colors = [self._background_color] for n in range(self._tail_length): - self._comet_colors.append( - calculate_intensity(color, n * self._color_step + 0.05) - ) + self._comet_colors.append(calculate_intensity(color, n * self._color_step + 0.05)) self._computed_color = color @property diff --git a/adafruit_led_animation/animation/customcolorchase.py b/adafruit_led_animation/animation/customcolorchase.py index 3fd0ee6..d1fc15d 100644 --- a/adafruit_led_animation/animation/customcolorchase.py +++ b/adafruit_led_animation/animation/customcolorchase.py @@ -43,7 +43,6 @@ class CustomColorChase(Chase): :param reverse: Reverse direction of movement. """ - # pylint: disable=too-many-arguments def __init__( self, pixel_object, diff --git a/adafruit_led_animation/animation/grid_rain.py b/adafruit_led_animation/animation/grid_rain.py index 7beef00..1b3b64d 100644 --- a/adafruit_led_animation/animation/grid_rain.py +++ b/adafruit_led_animation/animation/grid_rain.py @@ -26,12 +26,13 @@ """ import random + from adafruit_led_animation.animation import Animation __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation.git" -from adafruit_led_animation.color import BLACK, colorwheel, calculate_intensity, GREEN +from adafruit_led_animation.color import BLACK, GREEN, calculate_intensity, colorwheel class Rain(Animation): @@ -46,10 +47,7 @@ class Rain(Animation): :param background: Background color (Default BLACK). """ - # pylint: disable=too-many-arguments - def __init__( - self, grid_object, speed, color, count=1, length=3, background=BLACK, name=None - ): + def __init__(self, grid_object, speed, color, count=1, length=3, background=BLACK, name=None): self._count = count self._length = length self._background = background @@ -82,7 +80,7 @@ def draw(self): if y >= 0: self.pixel_object[x, y] = color - def _generate_droplet(self, x, length): # pylint: disable=unused-argument + def _generate_droplet(self, x, length): return [[n, self.color] for n in range(-length, 0)] @@ -91,9 +89,7 @@ class RainbowRain(Rain): Rainbow Rain animation. """ - def __init__( # pylint: disable=too-many-arguments - self, grid_object, speed, count=1, length=3, background=BLACK, name=None - ): + def __init__(self, grid_object, speed, count=1, length=3, background=BLACK, name=None): super().__init__(grid_object, speed, BLACK, count, length, background, name) def _generate_droplet(self, x, length): @@ -109,7 +105,7 @@ class MatrixRain(Rain): The Matrix style animation. """ - def __init__( # pylint: disable=too-many-arguments + def __init__( self, grid_object, speed, diff --git a/adafruit_led_animation/animation/multicolor_comet.py b/adafruit_led_animation/animation/multicolor_comet.py index a71a2d4..784ce52 100644 --- a/adafruit_led_animation/animation/multicolor_comet.py +++ b/adafruit_led_animation/animation/multicolor_comet.py @@ -25,6 +25,7 @@ """ + from adafruit_led_animation.animation.comet import Comet from adafruit_led_animation.color import BLACK @@ -50,7 +51,6 @@ class MulticolorComet(Comet): to remain on and set to a color after the comet passes. """ - # pylint: disable=too-many-arguments,too-many-instance-attributes def __init__( self, pixel_object, diff --git a/adafruit_led_animation/animation/pacman.py b/adafruit_led_animation/animation/pacman.py index c41eea5..ebf6e1d 100644 --- a/adafruit_led_animation/animation/pacman.py +++ b/adafruit_led_animation/animation/pacman.py @@ -24,16 +24,17 @@ """ import time + from adafruit_led_animation.animation import Animation from adafruit_led_animation.color import ( BLACK, - YELLOW, - RED, - PURPLE, + BLUE, CYAN, ORANGE, - BLUE, + PURPLE, + RED, WHITE, + YELLOW, ) ORANGEYELLOW = (255, 136, 0) @@ -47,7 +48,6 @@ class Pacman(Animation): :param float speed: Animation speed rate in seconds, e.g. ``0.1``. """ - # pylint: disable=too-many-arguments, too-many-branches def __init__( self, pixel_object, diff --git a/adafruit_led_animation/animation/pulse.py b/adafruit_led_animation/animation/pulse.py index ec1373d..0f7c7d9 100644 --- a/adafruit_led_animation/animation/pulse.py +++ b/adafruit_led_animation/animation/pulse.py @@ -42,7 +42,6 @@ class Pulse(Animation): :param max_intensity: Highest brightness level of the pulse. Default 1. """ - # pylint: disable=too-many-arguments def __init__( self, pixel_object, @@ -72,10 +71,8 @@ def reset(self): """ Resets the animation. """ - dotstar = len(self.pixel_object[0]) == 4 and isinstance( - self.pixel_object[0][-1], float - ) - from adafruit_led_animation.pulse_generator import ( # pylint: disable=import-outside-toplevel + dotstar = len(self.pixel_object[0]) == 4 and isinstance(self.pixel_object[0][-1], float) + from adafruit_led_animation.pulse_generator import ( pulse_generator, ) diff --git a/adafruit_led_animation/animation/rainbow.py b/adafruit_led_animation/animation/rainbow.py index 2825fb0..fdf53a5 100644 --- a/adafruit_led_animation/animation/rainbow.py +++ b/adafruit_led_animation/animation/rainbow.py @@ -25,9 +25,9 @@ """ +from adafruit_led_animation import MS_PER_SECOND, monotonic_ms from adafruit_led_animation.animation import Animation from adafruit_led_animation.color import BLACK, colorwheel -from adafruit_led_animation import MS_PER_SECOND, monotonic_ms __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation.git" @@ -46,10 +46,7 @@ class Rainbow(Animation): (default True). """ - # pylint: disable=too-many-arguments - def __init__( - self, pixel_object, speed, period=5, step=1, name=None, precompute_rainbow=True - ): + def __init__(self, pixel_object, speed, period=5, step=1, name=None, precompute_rainbow=True): super().__init__(pixel_object, speed, BLACK, name=name) self._period = period self._step = step @@ -107,13 +104,9 @@ def _draw_precomputed(self, num_pixels, wheel_index): if wheel_index + num > len(self.colors): colors_left = len(self.colors) - wheel_index self.pixel_object[i : i + colors_left] = self.colors[wheel_index:] - self.pixel_object[i + colors_left : i + num] = self.colors[ - : num - colors_left - ] + self.pixel_object[i + colors_left : i + num] = self.colors[: num - colors_left] else: - self.pixel_object[i : i + num] = self.colors[ - wheel_index : wheel_index + num - ] + self.pixel_object[i : i + num] = self.colors[wheel_index : wheel_index + num] def draw(self): next(self._generator) diff --git a/adafruit_led_animation/animation/rainbowchase.py b/adafruit_led_animation/animation/rainbowchase.py index 3f84828..6c5956d 100644 --- a/adafruit_led_animation/animation/rainbowchase.py +++ b/adafruit_led_animation/animation/rainbowchase.py @@ -26,8 +26,8 @@ """ -from adafruit_led_animation.color import colorwheel from adafruit_led_animation.animation.chase import Chase +from adafruit_led_animation.color import colorwheel class RainbowChase(Chase): @@ -43,7 +43,6 @@ class RainbowChase(Chase): :param step: How many colors to skip in ``colorwheel`` per bar (default 8) """ - # pylint: disable=too-many-arguments def __init__( self, pixel_object, diff --git a/adafruit_led_animation/animation/rainbowcomet.py b/adafruit_led_animation/animation/rainbowcomet.py index 6d4ce19..cc5c5b2 100644 --- a/adafruit_led_animation/animation/rainbowcomet.py +++ b/adafruit_led_animation/animation/rainbowcomet.py @@ -27,7 +27,7 @@ """ from adafruit_led_animation.animation.comet import Comet -from adafruit_led_animation.color import colorwheel, BLACK, calculate_intensity +from adafruit_led_animation.color import BLACK, calculate_intensity, colorwheel class RainbowComet(Comet): @@ -46,7 +46,6 @@ class RainbowComet(Comet): :param bool ring: Ring mode. Defaults to ``False``. """ - # pylint: disable=too-many-arguments def __init__( self, pixel_object, @@ -64,9 +63,7 @@ def __init__( else: self._colorwheel_step = step self._colorwheel_offset = colorwheel_offset - super().__init__( - pixel_object, speed, 0, 0, tail_length, reverse, bounce, name, ring - ) + super().__init__(pixel_object, speed, 0, 0, tail_length, reverse, bounce, name, ring) def _set_color(self, color): self._comet_colors = [BLACK] @@ -75,8 +72,7 @@ def _set_color(self, color): self._comet_colors.append( calculate_intensity( colorwheel( - int((invert * self._colorwheel_step) + self._colorwheel_offset) - % 256 + int((invert * self._colorwheel_step) + self._colorwheel_offset) % 256 ), n * self._color_step + 0.05, ) diff --git a/adafruit_led_animation/animation/rainbowsparkle.py b/adafruit_led_animation/animation/rainbowsparkle.py index 0be7a71..a87c8f5 100644 --- a/adafruit_led_animation/animation/rainbowsparkle.py +++ b/adafruit_led_animation/animation/rainbowsparkle.py @@ -26,6 +26,7 @@ """ import random + from adafruit_led_animation.animation.rainbow import Rainbow @@ -45,7 +46,6 @@ class RainbowSparkle(Rainbow): (default True). """ - # pylint: disable=too-many-arguments def __init__( self, pixel_object, @@ -91,10 +91,7 @@ def generate_rainbow(self): def after_draw(self): self.show() - pixels = [ - random.randint(0, len(self.pixel_object) - 1) - for n in range(self._num_sparkles) - ] + pixels = [random.randint(0, len(self.pixel_object) - 1) for n in range(self._num_sparkles)] for pixel in pixels: self.pixel_object[pixel] = self._bright_colors[ (self._wheel_index + pixel) % len(self._bright_colors) diff --git a/adafruit_led_animation/animation/sparkle.py b/adafruit_led_animation/animation/sparkle.py index 978b975..d067220 100644 --- a/adafruit_led_animation/animation/sparkle.py +++ b/adafruit_led_animation/animation/sparkle.py @@ -26,6 +26,7 @@ """ import random + from adafruit_led_animation.animation import Animation __version__ = "0.0.0+auto.0" @@ -43,10 +44,7 @@ class Sparkle(Animation): :param mask: array to limit sparkles within range of the mask """ - # pylint: disable=too-many-arguments - def __init__( - self, pixel_object, speed, color, num_sparkles=1, name=None, mask=None - ): + def __init__(self, pixel_object, speed, color, num_sparkles=1, name=None, mask=None): if len(pixel_object) < 2: raise ValueError("Sparkle needs at least 2 pixels") if mask: @@ -66,9 +64,7 @@ def __init__( def _set_color(self, color): half_color = tuple(color[rgb] // 4 for rgb in range(len(color))) dim_color = tuple(color[rgb] // 10 for rgb in range(len(color))) - for pixel in range( # pylint: disable=consider-using-enumerate - len(self.pixel_object) - ): + for pixel in range(len(self.pixel_object)): if self.pixel_object[pixel] == self._half_color: self.pixel_object[pixel] = half_color elif self.pixel_object[pixel] == self._dim_color: diff --git a/adafruit_led_animation/animation/sparklepulse.py b/adafruit_led_animation/animation/sparklepulse.py index 00133a7..8f915a3 100644 --- a/adafruit_led_animation/animation/sparklepulse.py +++ b/adafruit_led_animation/animation/sparklepulse.py @@ -43,7 +43,6 @@ class SparklePulse(Sparkle): :param min_intensity: The minimum intensity to pulse, between 0 and 1.0. Default 0. """ - # pylint: disable=too-many-arguments def __init__( self, pixel_object, @@ -60,9 +59,7 @@ def __init__( self.min_intensity = min_intensity self.max_intensity = max_intensity dotstar = len(pixel_object) == 4 and isinstance(pixel_object[0][-1], float) - super().__init__( - pixel_object, speed=speed, color=color, num_sparkles=1, name=name - ) + super().__init__(pixel_object, speed=speed, color=color, num_sparkles=1, name=name) self._generator = pulse_generator(self._period, self, dotstar_pwm=dotstar) def _set_color(self, color): @@ -88,7 +85,5 @@ def period(self, new_value): self.reset() def reset(self): - dotstar = len(self.pixel_object) == 4 and isinstance( - self.pixel_object[0][-1], float - ) + dotstar = len(self.pixel_object) == 4 and isinstance(self.pixel_object[0][-1], float) self._generator = pulse_generator(self._period, self, dotstar_pwm=dotstar) diff --git a/adafruit_led_animation/animation/volume.py b/adafruit_led_animation/animation/volume.py index d3ffc6e..e4b8ded 100644 --- a/adafruit_led_animation/animation/volume.py +++ b/adafruit_led_animation/animation/volume.py @@ -42,7 +42,6 @@ class Volume(Animation): :param float max_volume: what volume is considered maximum where everything is lit up """ - # pylint: disable=too-many-arguments def __init__( self, pixel_object, @@ -103,7 +102,6 @@ def draw(self): self._num_pixels, ) ) - # pylint: disable=consider-using-min-builtin if lit_pixels > self._num_pixels: lit_pixels = self._num_pixels diff --git a/adafruit_led_animation/color.py b/adafruit_led_animation/color.py index 9f8b17a..25aa950 100644 --- a/adafruit_led_animation/color.py +++ b/adafruit_led_animation/color.py @@ -23,8 +23,9 @@ * Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads """ + # Makes colorwheel() available. -from rainbowio import colorwheel # pylint: disable=unused-import +from rainbowio import colorwheel RED = (255, 0, 0) """Red.""" diff --git a/adafruit_led_animation/grid.py b/adafruit_led_animation/grid.py index b15254c..736ebe9 100644 --- a/adafruit_led_animation/grid.py +++ b/adafruit_led_animation/grid.py @@ -24,11 +24,11 @@ https://circuitpython.org/downloads """ + from micropython import const from .helper import PixelMap, horizontal_strip_gridmap, vertical_strip_gridmap - HORIZONTAL = const(1) VERTICAL = const(2) @@ -79,7 +79,7 @@ def __init__( reverse_y=False, top=0, bottom=0, - ): # pylint: disable=too-many-arguments,too-many-locals + ): self._pixels = strip self._x = [] self.height = height @@ -154,7 +154,6 @@ def brightness(self): @brightness.setter def brightness(self, brightness): - # pylint: disable=attribute-defined-outside-init self._pixels.brightness = min(max(brightness, 0.0), 1.0) def fill(self, color): diff --git a/adafruit_led_animation/group.py b/adafruit_led_animation/group.py index 2377d1d..fe4cd7f 100644 --- a/adafruit_led_animation/group.py +++ b/adafruit_led_animation/group.py @@ -107,9 +107,9 @@ def __init__(self, *members, sync=False, name=None): self.on_cycle_complete_supported = self._members[-1].on_cycle_complete_supported def __str__(self): - return "" % (self.__class__.__name__, self.name) + return f"" - def _group_done(self, animation): # pylint: disable=unused-argument + def _group_done(self, animation): self.on_cycle_complete() def on_cycle_complete(self): diff --git a/adafruit_led_animation/helper.py b/adafruit_led_animation/helper.py index b033b58..e24609f 100644 --- a/adafruit_led_animation/helper.py +++ b/adafruit_led_animation/helper.py @@ -165,7 +165,6 @@ def brightness(self): @brightness.setter def brightness(self, brightness): - # pylint: disable=attribute-defined-outside-init self._pixels.brightness = min(max(brightness, 0.0), 1.0) def fill(self, color): diff --git a/adafruit_led_animation/sequence.py b/adafruit_led_animation/sequence.py index bf5728f..6d35e07 100644 --- a/adafruit_led_animation/sequence.py +++ b/adafruit_led_animation/sequence.py @@ -27,7 +27,9 @@ """ import random + from adafruit_led_animation.color import BLACK + from . import MS_PER_SECOND, monotonic_ms __version__ = "0.0.0+auto.0" @@ -73,7 +75,6 @@ class AnimationSequence: animations.animate() """ - # pylint: disable=too-many-instance-attributes, too-many-arguments def __init__( self, *members, @@ -82,16 +83,12 @@ def __init__( random_order=False, auto_reset=False, advance_on_cycle_complete=False, - name=None + name=None, ): if advance_interval and advance_on_cycle_complete: - raise ValueError( - "Cannot use both advance_interval and advance_on_cycle_complete." - ) + raise ValueError("Cannot use both advance_interval and advance_on_cycle_complete.") self._members = members - self._advance_interval = ( - advance_interval * MS_PER_SECOND if advance_interval else None - ) + self._advance_interval = advance_interval * MS_PER_SECOND if advance_interval else None self._last_advance = monotonic_ms() self._current = 0 self.auto_clear = auto_clear @@ -115,7 +112,7 @@ def __init__( on_cycle_complete_supported = True def __str__(self): - return "<%s: %s>" % (self.__class__.__name__, self.name) + return f"<{self.__class__.__name__}: {self.name}>" def on_cycle_complete(self): """ @@ -128,7 +125,7 @@ def on_cycle_complete(self): for callback in self._also_notify: callback(self) - def _sequence_complete(self, animation): # pylint: disable=unused-argument + def _sequence_complete(self, animation): if self.advance_on_cycle_complete: self._advance() diff --git a/adafruit_led_animation/timedsequence.py b/adafruit_led_animation/timedsequence.py index a08c5e1..19feaa4 100644 --- a/adafruit_led_animation/timedsequence.py +++ b/adafruit_led_animation/timedsequence.py @@ -26,6 +26,7 @@ """ from adafruit_led_animation.sequence import AnimationSequence + from . import MS_PER_SECOND @@ -57,10 +58,7 @@ class TimedAnimationSequence(AnimationSequence): animations.animate() """ - # pylint: disable=too-many-instance-attributes - def __init__( - self, *members, auto_clear=True, random_order=False, auto_reset=False, name=None - ): + def __init__(self, *members, auto_clear=True, random_order=False, auto_reset=False, name=None): self._animation_members = [] self._animation_timings = [] for x, item in enumerate(members): diff --git a/docs/api.rst b/docs/api.rst index b4aa897..875d317 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -4,6 +4,9 @@ .. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py) .. use this format as the module name: "adafruit_foo.foo" +API Reference +############# + .. automodule:: adafruit_led_animation.animation :members: diff --git a/docs/conf.py b/docs/conf.py index 7fc34d9..e330ab0 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,12 +1,10 @@ -# -*- coding: utf-8 -*- - # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # # SPDX-License-Identifier: MIT +import datetime import os import sys -import datetime sys.path.insert(0, os.path.abspath("..")) @@ -48,9 +46,7 @@ creation_year = "2020" current_year = str(datetime.datetime.now().year) year_duration = ( - current_year - if current_year == creation_year - else creation_year + " - " + current_year + current_year if current_year == creation_year else creation_year + " - " + current_year ) copyright = year_duration + " Kattni Rembor" author = "Kattni Rembor" diff --git a/examples/led_animation_all_animations.py b/examples/led_animation_all_animations.py index fdb9824..b6e4560 100644 --- a/examples/led_animation_all_animations.py +++ b/examples/led_animation_all_animations.py @@ -9,24 +9,25 @@ This example does not work on SAMD21 (M0) boards. """ + import board import neopixel from adafruit_led_animation.animation.blink import Blink -from adafruit_led_animation.animation.sparklepulse import SparklePulse -from adafruit_led_animation.animation.comet import Comet from adafruit_led_animation.animation.chase import Chase +from adafruit_led_animation.animation.colorcycle import ColorCycle +from adafruit_led_animation.animation.comet import Comet +from adafruit_led_animation.animation.customcolorchase import CustomColorChase from adafruit_led_animation.animation.pulse import Pulse -from adafruit_led_animation.animation.sparkle import Sparkle +from adafruit_led_animation.animation.rainbow import Rainbow from adafruit_led_animation.animation.rainbowchase import RainbowChase -from adafruit_led_animation.animation.rainbowsparkle import RainbowSparkle from adafruit_led_animation.animation.rainbowcomet import RainbowComet +from adafruit_led_animation.animation.rainbowsparkle import RainbowSparkle from adafruit_led_animation.animation.solid import Solid -from adafruit_led_animation.animation.colorcycle import ColorCycle -from adafruit_led_animation.animation.rainbow import Rainbow -from adafruit_led_animation.animation.customcolorchase import CustomColorChase +from adafruit_led_animation.animation.sparkle import Sparkle +from adafruit_led_animation.animation.sparklepulse import SparklePulse +from adafruit_led_animation.color import AMBER, JADE, MAGENTA, ORANGE, PURPLE, WHITE from adafruit_led_animation.sequence import AnimationSequence -from adafruit_led_animation.color import PURPLE, WHITE, AMBER, JADE, MAGENTA, ORANGE # Update to match the pin connected to your NeoPixels pixel_pin = board.D6 diff --git a/examples/led_animation_basic_animations.py b/examples/led_animation_basic_animations.py index cfacf25..d86c23d 100644 --- a/examples/led_animation_basic_animations.py +++ b/examples/led_animation_basic_animations.py @@ -9,26 +9,27 @@ This example may not work on SAMD21 (M0) boards. """ + import board import neopixel -from adafruit_led_animation.animation.solid import Solid -from adafruit_led_animation.animation.colorcycle import ColorCycle from adafruit_led_animation.animation.blink import Blink -from adafruit_led_animation.animation.comet import Comet from adafruit_led_animation.animation.chase import Chase +from adafruit_led_animation.animation.colorcycle import ColorCycle +from adafruit_led_animation.animation.comet import Comet from adafruit_led_animation.animation.pulse import Pulse -from adafruit_led_animation.sequence import AnimationSequence +from adafruit_led_animation.animation.solid import Solid from adafruit_led_animation.color import ( - PURPLE, - WHITE, AMBER, JADE, - TEAL, - PINK, MAGENTA, ORANGE, + PINK, + PURPLE, + TEAL, + WHITE, ) +from adafruit_led_animation.sequence import AnimationSequence # Update to match the pin connected to your NeoPixels pixel_pin = board.D6 diff --git a/examples/led_animation_blink.py b/examples/led_animation_blink.py index bc7033f..3419100 100755 --- a/examples/led_animation_blink.py +++ b/examples/led_animation_blink.py @@ -10,6 +10,7 @@ This example will run on SAMD21 (M0) Express boards (such as Circuit Playground Express or QT Py Haxpress), but not on SAMD21 non-Express boards (such as QT Py or Trinket). """ + import board import neopixel diff --git a/examples/led_animation_blink_with_background.py b/examples/led_animation_blink_with_background.py index 4a94e10..6483c28 100644 --- a/examples/led_animation_blink_with_background.py +++ b/examples/led_animation_blink_with_background.py @@ -10,6 +10,7 @@ This example will run on SAMD21 (M0) Express boards (such as Circuit Playground Express or QT Py Haxpress), but not on SAMD21 non-Express boards (such as QT Py or Trinket). """ + import board import neopixel diff --git a/examples/led_animation_chase.py b/examples/led_animation_chase.py index ec38234..c859ccf 100755 --- a/examples/led_animation_chase.py +++ b/examples/led_animation_chase.py @@ -11,6 +11,7 @@ This example will run on SAMD21 (M0) Express boards (such as Circuit Playground Express or QT Py Haxpress), but not on SAMD21 non-Express boards (such as QT Py or Trinket). """ + import board import neopixel diff --git a/examples/led_animation_comet.py b/examples/led_animation_comet.py index 5c4c0d1..167aa7e 100755 --- a/examples/led_animation_comet.py +++ b/examples/led_animation_comet.py @@ -10,6 +10,7 @@ This example will run on SAMD21 (M0) Express boards (such as Circuit Playground Express or QT Py Haxpress), but not on SAMD21 non-Express boards (such as QT Py or Trinket). """ + import board import neopixel diff --git a/examples/led_animation_customcolorchase.py b/examples/led_animation_customcolorchase.py index 9e0397e..1bfa674 100644 --- a/examples/led_animation_customcolorchase.py +++ b/examples/led_animation_customcolorchase.py @@ -9,17 +9,16 @@ This example may not work on SAMD21 (M0) boards. """ + import board import neopixel from adafruit_led_animation.animation.customcolorchase import CustomColorChase -from adafruit_led_animation.sequence import AnimationSequence # colorwheel only needed for rainbowchase example -from adafruit_led_animation.color import colorwheel - # Colors for customcolorchase examples -from adafruit_led_animation.color import PINK, GREEN, RED, BLUE +from adafruit_led_animation.color import BLUE, GREEN, PINK, RED, colorwheel +from adafruit_led_animation.sequence import AnimationSequence # Update to match the pin connected to your NeoPixels pixel_pin = board.D5 @@ -27,15 +26,11 @@ pixel_num = 30 brightness = 0.3 -pixels = neopixel.NeoPixel( - pixel_pin, pixel_num, brightness=brightness, auto_write=False -) +pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=brightness, auto_write=False) # colors default to RAINBOW as defined in color.py custom_color_chase_rainbow = CustomColorChase(pixels, speed=0.1, size=2, spacing=3) -custom_color_chase_rainbow_r = CustomColorChase( - pixels, speed=0.1, size=3, spacing=3, reverse=True -) +custom_color_chase_rainbow_r = CustomColorChase(pixels, speed=0.1, size=3, spacing=3, reverse=True) # Example with same colors as RainbowChase steps = 30 diff --git a/examples/led_animation_cycle_animations.py b/examples/led_animation_cycle_animations.py index d609b38..7dc98f8 100644 --- a/examples/led_animation_cycle_animations.py +++ b/examples/led_animation_cycle_animations.py @@ -8,14 +8,16 @@ For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using a different form of NeoPixels. """ + import time + import board import neopixel from digitalio import DigitalInOut, Direction, Pull from adafruit_led_animation.animation.solid import Solid +from adafruit_led_animation.color import BLUE, RED from adafruit_led_animation.sequence import AnimationSequence -from adafruit_led_animation.color import RED, BLUE # Update to match the pin connected to your NeoPixels pixel_pin = board.D6 diff --git a/examples/led_animation_freeze_animation.py b/examples/led_animation_freeze_animation.py index cd8bc18..531f55f 100644 --- a/examples/led_animation_freeze_animation.py +++ b/examples/led_animation_freeze_animation.py @@ -8,6 +8,7 @@ For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using a different form of NeoPixels. """ + import board import neopixel from digitalio import DigitalInOut, Direction, Pull diff --git a/examples/led_animation_group.py b/examples/led_animation_group.py index c9a4b5a..beb70ab 100644 --- a/examples/led_animation_group.py +++ b/examples/led_animation_group.py @@ -10,19 +10,18 @@ This example is written for Circuit Playground Bluefruit and a 30-pixel NeoPixel strip connected to pad A1. It does not work on Circuit Playground Express. """ + import board import neopixel from adafruit_circuitplayground import cp +from adafruit_led_animation import color from adafruit_led_animation.animation.blink import Blink -from adafruit_led_animation.animation.comet import Comet from adafruit_led_animation.animation.chase import Chase - +from adafruit_led_animation.animation.comet import Comet from adafruit_led_animation.group import AnimationGroup from adafruit_led_animation.sequence import AnimationSequence -from adafruit_led_animation import color - strip_pixels = neopixel.NeoPixel(board.A1, 30, brightness=0.5, auto_write=False) cp.pixels.brightness = 0.5 diff --git a/examples/led_animation_multicolor_comet.py b/examples/led_animation_multicolor_comet.py index 502d604..8354e9c 100644 --- a/examples/led_animation_multicolor_comet.py +++ b/examples/led_animation_multicolor_comet.py @@ -11,8 +11,10 @@ This example will run on SAMD21 (M0) Express boards (such as Circuit Playground Express or QT Py Haxpress), but not on SAMD21 non-Express boards (such as QT Py or Trinket). """ + import board import neopixel + from adafruit_led_animation.animation.multicolor_comet import MulticolorComet # Update to match the pin connected to your NeoPixels diff --git a/examples/led_animation_pacman.py b/examples/led_animation_pacman.py index c325fd5..797b134 100644 --- a/examples/led_animation_pacman.py +++ b/examples/led_animation_pacman.py @@ -4,8 +4,10 @@ """ This example animates a Pacman on a NeoPixel strip. """ + import board import neopixel + from adafruit_led_animation.animation.pacman import Pacman from adafruit_led_animation.color import WHITE diff --git a/examples/led_animation_pixel_map.py b/examples/led_animation_pixel_map.py index 692b11e..e7b6332 100644 --- a/examples/led_animation_pixel_map.py +++ b/examples/led_animation_pixel_map.py @@ -11,17 +11,18 @@ This example does not work on SAMD21 (M0) boards. """ + import board import neopixel -from adafruit_led_animation.animation.comet import Comet -from adafruit_led_animation.animation.rainbowcomet import RainbowComet -from adafruit_led_animation.animation.rainbowchase import RainbowChase +from adafruit_led_animation import helper from adafruit_led_animation.animation.chase import Chase +from adafruit_led_animation.animation.comet import Comet from adafruit_led_animation.animation.rainbow import Rainbow +from adafruit_led_animation.animation.rainbowchase import RainbowChase +from adafruit_led_animation.animation.rainbowcomet import RainbowComet +from adafruit_led_animation.color import AMBER, JADE, PURPLE from adafruit_led_animation.sequence import AnimationSequence -from adafruit_led_animation import helper -from adafruit_led_animation.color import PURPLE, JADE, AMBER # Update to match the pin connected to your NeoPixels pixel_pin = board.D6 @@ -37,17 +38,11 @@ pixels, 8, 4, helper.horizontal_strip_gridmap(8, alternating=False) ) -comet_h = Comet( - pixel_wing_horizontal, speed=0.1, color=PURPLE, tail_length=3, bounce=True -) +comet_h = Comet(pixel_wing_horizontal, speed=0.1, color=PURPLE, tail_length=3, bounce=True) comet_v = Comet(pixel_wing_vertical, speed=0.1, color=AMBER, tail_length=6, bounce=True) chase_h = Chase(pixel_wing_horizontal, speed=0.1, size=3, spacing=6, color=JADE) -rainbow_chase_v = RainbowChase( - pixel_wing_vertical, speed=0.1, size=3, spacing=2, step=8 -) -rainbow_comet_v = RainbowComet( - pixel_wing_vertical, speed=0.1, tail_length=7, bounce=True -) +rainbow_chase_v = RainbowChase(pixel_wing_vertical, speed=0.1, size=3, spacing=2, step=8) +rainbow_comet_v = RainbowComet(pixel_wing_vertical, speed=0.1, tail_length=7, bounce=True) rainbow_v = Rainbow(pixel_wing_vertical, speed=0.1, period=2) rainbow_chase_h = RainbowChase(pixel_wing_horizontal, speed=0.1, size=3, spacing=3) diff --git a/examples/led_animation_rainbow_animations.py b/examples/led_animation_rainbow_animations.py index c4c36b4..77facb0 100644 --- a/examples/led_animation_rainbow_animations.py +++ b/examples/led_animation_rainbow_animations.py @@ -10,6 +10,7 @@ This example does not work on SAMD21 (M0) boards. """ + import board import neopixel diff --git a/examples/led_animation_resume_animation.py b/examples/led_animation_resume_animation.py index b8c79ad..637dbb7 100644 --- a/examples/led_animation_resume_animation.py +++ b/examples/led_animation_resume_animation.py @@ -8,6 +8,7 @@ For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using a different form of NeoPixels. """ + import board import neopixel from digitalio import DigitalInOut, Direction, Pull diff --git a/examples/led_animation_samd21_reset_interval.py b/examples/led_animation_samd21_reset_interval.py index 50e4764..f842678 100755 --- a/examples/led_animation_samd21_reset_interval.py +++ b/examples/led_animation_samd21_reset_interval.py @@ -16,9 +16,11 @@ This example will run on SAMD21 (M0) Express boards (such as Circuit Playground Express or QT Py Haxpress), but not on SAMD21 non-Express boards (such as QT Py or Trinket). """ + import time -import microcontroller + import board +import microcontroller import neopixel from adafruit_led_animation.animation.comet import Comet @@ -37,4 +39,4 @@ comet.animate() if time.monotonic() > 3600: # After an hour passes, reset the board. - microcontroller.reset() # pylint: disable=no-member + microcontroller.reset() diff --git a/examples/led_animation_sequence.py b/examples/led_animation_sequence.py index a3070e9..a73e92e 100644 --- a/examples/led_animation_sequence.py +++ b/examples/led_animation_sequence.py @@ -8,14 +8,15 @@ For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using a different form of NeoPixels. """ + import board import neopixel from adafruit_led_animation.animation.blink import Blink -from adafruit_led_animation.animation.comet import Comet from adafruit_led_animation.animation.chase import Chase +from adafruit_led_animation.animation.comet import Comet +from adafruit_led_animation.color import AMBER, JADE, PURPLE from adafruit_led_animation.sequence import AnimationSequence -from adafruit_led_animation.color import PURPLE, AMBER, JADE # Update to match the pin connected to your NeoPixels pixel_pin = board.D6 diff --git a/examples/led_animation_simpletest.py b/examples/led_animation_simpletest.py index 86980a4..65cbe69 100644 --- a/examples/led_animation_simpletest.py +++ b/examples/led_animation_simpletest.py @@ -7,8 +7,10 @@ For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using a different form of NeoPixels. """ + import board import neopixel + from adafruit_led_animation.animation.blink import Blink from adafruit_led_animation.color import RED diff --git a/examples/led_animation_sparkle_animations.py b/examples/led_animation_sparkle_animations.py index 01dbb9e..2148ff3 100644 --- a/examples/led_animation_sparkle_animations.py +++ b/examples/led_animation_sparkle_animations.py @@ -8,13 +8,14 @@ For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using a different form of NeoPixels. """ + import board import neopixel from adafruit_led_animation.animation.sparkle import Sparkle from adafruit_led_animation.animation.sparklepulse import SparklePulse -from adafruit_led_animation.sequence import AnimationSequence from adafruit_led_animation.color import AMBER, JADE +from adafruit_led_animation.sequence import AnimationSequence # Update to match the pin connected to your NeoPixels pixel_pin = board.D6 diff --git a/examples/led_animation_sparkle_mask.py b/examples/led_animation_sparkle_mask.py index 27ac98a..ea4fc02 100644 --- a/examples/led_animation_sparkle_mask.py +++ b/examples/led_animation_sparkle_mask.py @@ -7,12 +7,13 @@ For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using a different form of NeoPixels. """ + import board import neopixel from adafruit_led_animation.animation.sparkle import Sparkle +from adafruit_led_animation.color import AQUA, JADE, PINK from adafruit_led_animation.sequence import AnimationSequence -from adafruit_led_animation.color import JADE, AQUA, PINK # Update to match the pin connected to your NeoPixels pixel_pin = board.A1 diff --git a/examples/led_animation_timedsequence.py b/examples/led_animation_timedsequence.py index b6e05bf..543a201 100644 --- a/examples/led_animation_timedsequence.py +++ b/examples/led_animation_timedsequence.py @@ -4,13 +4,15 @@ """ Example for TimedSequence """ + import board import neopixel -from adafruit_led_animation.timedsequence import TimedAnimationSequence + +import adafruit_led_animation.animation.blink as blink_animation import adafruit_led_animation.animation.comet as comet_animation import adafruit_led_animation.animation.sparkle as sparkle_animation -import adafruit_led_animation.animation.blink as blink_animation from adafruit_led_animation import color +from adafruit_led_animation.timedsequence import TimedAnimationSequence strip_pixels = neopixel.NeoPixel(board.D6, 32, brightness=0.1, auto_write=False) blink = blink_animation.Blink(strip_pixels, 0.3, color.RED) diff --git a/examples/led_animation_volume.py b/examples/led_animation_volume.py index 2448636..4fff2e8 100644 --- a/examples/led_animation_volume.py +++ b/examples/led_animation_volume.py @@ -3,9 +3,11 @@ # SPDX-License-Identifier: MIT """Volume Animation Example""" + import board -from audiomp3 import MP3Decoder import neopixel +from audiomp3 import MP3Decoder + from adafruit_led_animation.animation import volume try: diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..73e9efc --- /dev/null +++ b/ruff.toml @@ -0,0 +1,108 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +target-version = "py38" +line-length = 100 + +[lint] +preview = true +select = ["I", "PL", "UP"] + +extend-select = [ + "D419", # empty-docstring + "E501", # line-too-long + "W291", # trailing-whitespace + "PLC0414", # useless-import-alias + "PLC2401", # non-ascii-name + "PLC2801", # unnecessary-dunder-call + "PLC3002", # unnecessary-direct-lambda-call + "E999", # syntax-error + "PLE0101", # return-in-init + "F706", # return-outside-function + "F704", # yield-outside-function + "PLE0116", # continue-in-finally + "PLE0117", # nonlocal-without-binding + "PLE0241", # duplicate-bases + "PLE0302", # unexpected-special-method-signature + "PLE0604", # invalid-all-object + "PLE0605", # invalid-all-format + "PLE0643", # potential-index-error + "PLE0704", # misplaced-bare-raise + "PLE1141", # dict-iter-missing-items + "PLE1142", # await-outside-async + "PLE1205", # logging-too-many-args + "PLE1206", # logging-too-few-args + "PLE1307", # bad-string-format-type + "PLE1310", # bad-str-strip-call + "PLE1507", # invalid-envvar-value + "PLE2502", # bidirectional-unicode + "PLE2510", # invalid-character-backspace + "PLE2512", # invalid-character-sub + "PLE2513", # invalid-character-esc + "PLE2514", # invalid-character-nul + "PLE2515", # invalid-character-zero-width-space + "PLR0124", # comparison-with-itself + "PLR0202", # no-classmethod-decorator + "PLR0203", # no-staticmethod-decorator + "UP004", # useless-object-inheritance + "PLR0206", # property-with-parameters + "PLR0904", # too-many-public-methods + "PLR0911", # too-many-return-statements + "PLR0912", # too-many-branches + "PLR0913", # too-many-arguments + "PLR0914", # too-many-locals + "PLR0915", # too-many-statements + "PLR0916", # too-many-boolean-expressions + "PLR1702", # too-many-nested-blocks + "PLR1704", # redefined-argument-from-local + "PLR1711", # useless-return + "C416", # unnecessary-comprehension + "PLR1733", # unnecessary-dict-index-lookup + "PLR1736", # unnecessary-list-index-lookup + + # ruff reports this rule is unstable + #"PLR6301", # no-self-use + + "PLW0108", # unnecessary-lambda + "PLW0120", # useless-else-on-loop + "PLW0127", # self-assigning-variable + "PLW0129", # assert-on-string-literal + "B033", # duplicate-value + "PLW0131", # named-expr-without-context + "PLW0245", # super-without-brackets + "PLW0406", # import-self + "PLW0602", # global-variable-not-assigned + "PLW0603", # global-statement + "PLW0604", # global-at-module-level + + # fails on the try: import typing used by libraries + #"F401", # unused-import + + "F841", # unused-variable + "E722", # bare-except + "PLW0711", # binary-op-exception + "PLW1501", # bad-open-mode + "PLW1508", # invalid-envvar-default + "PLW1509", # subprocess-popen-preexec-fn + "PLW2101", # useless-with-lock + "PLW3301", # nested-min-max +] + +ignore = [ + "PLR2004", # magic-value-comparison + "UP030", # format literals + "PLW1514", # unspecified-encoding + "PLR0913", # too-many-arguments + "PLR0915", # too-many-statements + "PLR0917", # too-many-positional-arguments + "PLR0904", # too-many-public-methods + "PLR0912", # too-many-branches + "PLR0916", # too-many-boolean-expressions + "PLR6301", # could-be-static no-self-use + "PLC0415", # import outside toplevel + "PLC2701", # private import +] + +[format] +line-ending = "lf"