diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index a9b258d..7ca3a1d 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -40,8 +40,8 @@ Examples of unacceptable behavior by participants include: * Other conduct which could reasonably be considered inappropriate The goal of the standards and moderation guidelines outlined here is to build -and maintain a respectful community. We ask that you don’t just aim to be -"technically unimpeachable", but rather try to be your best self. +and maintain a respectful community. We ask that you don’t just aim to be +"technically unimpeachable", but rather try to be your best self. We value many things beyond technical expertise, including collaboration and supporting others within our community. Providing a positive experience for @@ -72,7 +72,7 @@ You may report in the following ways: In any situation, you may send an email to . On the Adafruit Discord, you may send an open message from any channel -to all Community Helpers by tagging @community helpers. You may also send an +to all Community Helpers by tagging @community moderators. You may also send an open message from any channel, or a direct message to @kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or @Andon#8175. @@ -83,7 +83,7 @@ In situations on Discord where the issue is particularly egregious, possibly illegal, requires immediate action, or violates the Discord terms of service, you should also report the message directly to Discord. -These are the steps for upholding our community’s standards of conduct. +These are the steps for upholding our community’s standards of conduct. 1. Any member of the community may report any situation that violates the Adafruit Community Code of Conduct. All reports will be reviewed and @@ -124,4 +124,4 @@ For other projects adopting the Adafruit Community Code of Conduct, please contact the maintainers of those projects for enforcement. If you wish to use this code of conduct for your own project, consider explicitly mentioning your moderation policy or making a copy with your -own moderation policy so as to avoid confusion. \ No newline at end of file +own moderation policy so as to avoid confusion. diff --git a/LICENSE b/LICENSE index f1ccab1..3367ac5 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ The MIT License (MIT) Copyright (c) 2017 Adam Patt +Copyright (c) 2019-2020 Roy Hooper, Kattni Rembor Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.rst b/README.rst index 13a9f67..c8000fa 100644 --- a/README.rst +++ b/README.rst @@ -1,8 +1,8 @@ Introduction ============ -.. image:: https://readthedocs.org/projects/adafruit_circuitpython_led_animation/badge/?version=latest - :target: https://adafruit_circuitpython_led_animation.readthedocs.io/ +.. image:: https://readthedocs.org/projects/adafruit-circuitpython-led_animation/badge/?version=latest + :target: https://circuitpython.readthedocs.io/projects/led_animation/en/latest/ :alt: Documentation Status .. image:: https://img.shields.io/discord/327254708534116352.svg @@ -13,7 +13,8 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation/actions :alt: Build Status -Perform a variety of LED animation tasks +A library to easily generate LED animations + Dependencies ============= @@ -23,76 +24,60 @@ This driver depends on: Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading -`the Adafruit library and driver bundle `_. +`the Adafruit library and driver bundle `_. + +Installing from PyPI +===================== +.. note:: This library is not available on PyPI yet. Install documentation is included + as a standard element. Stay tuned for PyPI availability! + +On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from +PyPI `_. To install for current user: + +.. code-block:: shell + + pip3 install adafruit-circuitpython-led-animation + +To install system-wide (this may be required in some cases): + +.. code-block:: shell + + sudo pip3 install adafruit-circuitpython-led-animation + +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 + pip3 install adafruit-circuitpython-led-animation Usage Example ============= .. code-block:: python - import adafruit_dotstar as dotstar + from adafruit_led_animation.animation import Comet, AnimationSequence, Chase + import neopixel import board - from led_animation import color - # setup the pixel - dot = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=.2) - # set the color by name - dot[0] = color.GOLD - # show the pixel - dot.show() + + pixels = neopixel.NeoPixel(board.D6, 32, brightness=0.2, auto_write=False) + comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True) + chase = Chase(pixels, speed=0.1, size=3, spacing=6, color=WHITE) + animations = AnimationSequence(comet, chase, advance_interval=15) + + while True: + animations.animate() Contributing ============ Contributions are welcome! Please read our `Code of Conduct -`_ +`_ before contributing to help this project stay welcoming. -Building locally -================ +Documentation +============= -Zip release files ------------------ - -To build this library locally you'll need to install the -`circuitpython-build-tools `_ package. - -.. code-block:: shell - - python3 -m venv .env - source .env/bin/activate - pip install circuitpython-build-tools - -Once installed, make sure you are in the virtual environment: - -.. code-block:: shell - - source .env/bin/activate - -Then run the build: - -.. code-block:: shell - - circuitpython-build-bundles --filename_prefix circuitpython-led_animation --library_location . - -Sphinx documentation ------------------------ - -Sphinx is used to build the documentation based on rST files and comments in the code. First, -install dependencies (feel free to reuse the virtual environment from above): - -.. code-block:: shell - - python3 -m venv .env - source .env/bin/activate - pip install Sphinx sphinx-rtd-theme - -Now, once you have the virtual environment activated: - -.. code-block:: shell - - cd docs - sphinx-build -E -W -b html . _build/html - -This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to -view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to -locally verify it will pass. +For information on building library documentation, please check out `this guide `_. diff --git a/adafruit_led_animation/animation.py b/adafruit_led_animation/animation.py index dc3522a..21afd1f 100644 --- a/adafruit_led_animation/animation.py +++ b/adafruit_led_animation/animation.py @@ -196,7 +196,7 @@ class ColorCycle(Animation): Animate a sequence of one or more colors, cycling at the specified speed. :param pixel_object: The initialised LED object. - :param int speed: Animation speed in seconds, e.g. ``0.1``. + :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. """ @@ -231,7 +231,7 @@ class Blink(ColorCycle): Blink a color on and off. :param pixel_object: The initialised LED object. - :param int speed: Animation speed in seconds, e.g. ``0.1``. + :param float speed: Animation speed in seconds, e.g. ``0.1``. :param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format. """ def __init__(self, pixel_object, speed, color, name=None): @@ -263,7 +263,7 @@ class Comet(Animation): A comet animation. :param pixel_object: The initialised LED object. - :param int speed: Animation speed in seconds, e.g. ``0.1``. + :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 int tail_length: The length of the comet. Defaults to 10. Cannot exceed the number of pixels present in the pixel object, e.g. if the strip is 30 pixels @@ -344,7 +344,7 @@ class Sparkle(Animation): Sparkle animation of a single color. :param pixel_object: The initialised LED object. - :param int speed: Animation speed in seconds, e.g. ``0.1``. + :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 num_sparkles: Number of sparkles to generate per animation cycle. """ @@ -385,22 +385,20 @@ class Pulse(Animation): Pulse all pixels a single color. :param pixel_object: The initialised LED object. - :param int speed: Animation refresh rate in seconds, e.g. ``0.1``. + :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 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. """ # pylint: disable=too-many-arguments def __init__(self, pixel_object, speed, color, period=5, name=None): super(Pulse, self).__init__(pixel_object, speed, color, name=name) self._period = period - self._generator = self._pulse_generator(period) + self._generator = self._pulse_generator() - def _pulse_generator(self, period): - period = int(period * NANOS_PER_SECOND) - white = len(self.pixel_object[0]) > 3 and type(self.pixel_object[0][-1]) is not float + def _pulse_generator(self): + period = int(self._period * NANOS_PER_SECOND) + white = len(self.pixel_object[0]) > 3 and isinstance(self.pixel_object[0][-1], float) half_period = period // 2 last_update = monotonic_ns() @@ -434,7 +432,7 @@ class Pulse(Animation): """ Resets the animation. """ - self._generator = self._pulse_generator(self._period) + self._generator = self._pulse_generator() class ColorWheel(Animation): @@ -442,17 +440,18 @@ class ColorWheel(Animation): The classic adafruit colorwheel. :param pixel_object: The initialised LED object. - :param int speed: Animation refresh rate in seconds, e.g. ``0.1``. + :param float speed: Animation refresh rate in seconds, e.g. ``0.1``. :param period: Period to cycle the colorwheel over. Default 5. """ # pylint: disable=too-many-arguments def __init__(self, pixel_object, speed, period=5, name=None): super(ColorWheel, self).__init__(pixel_object, speed, BLACK, name=name) - self._generator = self._wheel_generator(period) + self._period = period + self._generator = self._wheel_generator() - def _wheel_generator(self, period): - period = int(period * NANOS_PER_SECOND) + def _wheel_generator(self): + period = int(self._period * NANOS_PER_SECOND) last_update = monotonic_ns() cycle_position = 0 @@ -478,7 +477,7 @@ class ColorWheel(Animation): """ Resets the animation. """ - self._generator = self._wheel_generator(period) + self._generator = self._wheel_generator() class Chase(Animation): @@ -486,7 +485,7 @@ class Chase(Animation): Chase pixels in one direction in a single color, like a theater marquee sign. :param pixel_object: The initialised LED object. - :param int speed: Animation speed rate in seconds, e.g. ``0.1``. + :param float speed: Animation speed rate in seconds, e.g. ``0.1``. :param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format. :param size: Number of pixels to turn on in a row. :param spacing: Number of pixels to turn off in a row. @@ -504,12 +503,12 @@ class Chase(Animation): self._reverse = reverse self._n = 0 - def resetter(): + def _resetter(): self._n = 0 self._reverse = reverse self._direction = 1 if not reverse else -1 - self._reset = resetter + self._reset = _resetter super(Chase, self).__init__(pixel_object, speed, color, name=name) @@ -787,7 +786,7 @@ class AnimationGroup: for item in self._members: item.resume() - def done_handler(self, animation): + def done_handler(self, animation): # pylint: disable=unused-argument """ Called by some animations when they complete a cycle. For an AnimationGroup this is the first member of the group, if any. diff --git a/docs/api.rst b/docs/api.rst index 465084a..dd0a87d 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1,10 +1,8 @@ -API Reference -************* .. If you created a package, create one automodule per module in the package. .. 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" -.. automodule:: led_animation +.. automodule:: adafruit_led_animation :members: diff --git a/docs/conf.py b/docs/conf.py index 290aa7e..83d37e2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,7 +20,7 @@ extensions = [ # Uncomment the below if you use native CircuitPython modules such as # digitalio, micropython and busio. List the modules you use. Without it, the # autodoc module docs will fail to generate with a warning. -autodoc_mock_imports = ["led_animation"] +# autodoc_mock_imports = ["digitalio", "busio"] intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} @@ -34,9 +34,9 @@ source_suffix = '.rst' master_doc = 'index' # General information about the project. -project = u'LED_Animation Library' -copyright = u'2017 Adam Patt' -author = u'Adam Patt' +project = u'Adafruit_LED_Animation Library' +copyright = u'2020 Roy Hooper' +author = u'Roy Hooper' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -109,7 +109,7 @@ html_static_path = ['_static'] html_favicon = '_static/favicon.ico' # Output file base name for HTML help builder. -htmlhelp_basename = 'Led_animationLibrarydoc' +htmlhelp_basename = 'Adafruit_LED_animation_Librarydoc' # -- Options for LaTeX output --------------------------------------------- @@ -135,7 +135,8 @@ latex_elements = { # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'LED_AnimationLibrary.tex', u'LED_Animation Library Documentation', + (master_doc, 'Adafruit_LED_Animation_Library.tex', + u'Adafruit_LED_Animation Library Documentation', author, 'manual'), ] @@ -144,7 +145,7 @@ latex_documents = [ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'LED_Animationlibrary', u'LED_Animation Library Documentation', + (master_doc, 'Adafruit_LED_Animation_library', u'Adafruit LED_Animation Library Documentation', [author], 1) ] @@ -154,7 +155,7 @@ man_pages = [ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'LED_AnimationLibrary', u' LED_Animation Library Documentation', - author, 'LED_AnimationLibrary', 'One line description of project.', + (master_doc, 'Adafruit_LED_Animation_library', u'Adafruit LED_Animation Library Documentation', + author, 'Adafruit_LED_Animation_library', 'One line description of project.', 'Miscellaneous'), ] diff --git a/docs/index.rst b/docs/index.rst index c7c4b7a..426a2fb 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -20,16 +20,10 @@ Table of Contents api -.. toctree:: - :caption: Tutorials - -.. toctree:: - :caption: Related Products - .. toctree:: :caption: Other Links - Download + Download CircuitPython Reference Documentation CircuitPython Support Forum Discord Chat diff --git a/examples/led_animation_simpletest.py b/examples/led_animation_simpletest.py index f8b3b2e..a70e652 100644 --- a/examples/led_animation_simpletest.py +++ b/examples/led_animation_simpletest.py @@ -1,17 +1,14 @@ -"""Blink LED animation.""" -import board +""" +Example animation sequence. +""" +from adafruit_led_animation.animation import Comet, AnimationSequence, Chase import neopixel -from adafruit_led_animation.animation import Blink -import adafruit_led_animation.color as color +import board -# Works on Circuit Playground Express and Bluefruit. -# For other boards, change board.NEOPIXEL to match the pin to which the NeoPixels are attached. -pixel_pin = board.NEOPIXEL -# Change to match the number of pixels you have attached to your board. -num_pixels = 10 - -pixels = neopixel.NeoPixel(pixel_pin, num_pixels) -blink = Blink(pixels, 0.5, color.PURPLE) +pixels = neopixel.NeoPixel(board.D6, 32, brightness=0.2, auto_write=False) +comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True) +chase = Chase(pixels, speed=0.1, size=3, spacing=6, color=WHITE) +animations = AnimationSequence(comet, chase, advance_interval=15) while True: - blink.animate() + animations.animate() diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..547436e --- /dev/null +++ b/setup.py @@ -0,0 +1,60 @@ +"""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='A library to easily generate LED 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', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + ], + + # What does your project relate to? + keywords='adafruit blinka circuitpython micropython led_animation led animation neopixel ' + 'dotstar', + + py_modules=['adafruit_led_animation'], +)