Skip to content

Commit

Permalink
docs led anim fixes re #117
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyIvan359 committed Nov 21, 2021
1 parent 6fbe0e3 commit 964f6f3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion source/interface/led/animations/built-in.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Example message to trigger this animation:
.. code-block:: python
{
"anim": "brightness",
"anim": "set.brightness",
"brightness": 128
}
Expand Down
46 changes: 39 additions & 7 deletions source/interface/led/animations/custom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,34 @@ but you can specify multiple other locations using the ``anim dir`` option in
the config file.


File Header
===========

You will likely want to add the following to the top of each of your files to
get the best experience writing your own animations. This will provide type
hints and autocompletion while creating animations.

.. code-block:: python
import typing as t
if t.TYPE_CHECKING:
import threading, sys
sys.path.append("/opt/mqttany")
from mqttany.modules.led.anim import parse_color, parse_pixel
from mqttany.modules.led.array.base import baseArray
from mqttany.modules.led.common import Color
from mqttany.logger import mqttanyLogger
log: mqttanyLogger
FRAME_MS: float
If you did not install MQTTany in the default ``/opt/mqttany`` directory you
will need to modify the path in the above header or otherwise ensure that the
imports are available.


Function Naming
===============

Expand Down Expand Up @@ -42,14 +70,18 @@ reliably:

.. code-block:: python
def anim_blink(array: baseArray, cancel: threading.Event, **kwargs: t.Any) -> None:
def anim_blink(
array, # type: baseArray
cancel, # type: threading.Event
**kwargs, # type: t.Any
) -> None:
+--------------+----------------------------------------------------------------+
| Parameter | Description |
+==============+================================================================+
| ``array`` | This is the LED array object subclassed from |
| | ``led.array.baseLED``. All operations to change the LEDs are |
| | done using this object. See |
| | ``led.array.base.baseArray``. All operations to change the |
| | LEDs are done using this object. See |
| | :ref:`interface/led/animations/custom:\`\`array\`\` Object` |
| | for details. |
+--------------+----------------------------------------------------------------+
Expand Down Expand Up @@ -78,7 +110,7 @@ reliably:

The ``array`` object provides methods to get information about the array and
set LED colors. The ``array`` object received will be subclassed from
``modules.led.array.baseArray``.
``modules.led.array.base.baseArray``.

+----------------------------------------+------------------------------------------------------+
| Method / Property | Description |
Expand All @@ -95,8 +127,8 @@ set LED colors. The ``array`` object received will be subclassed from
| | ``b``, and ``w`` properties representing the pixel |
| | color. |
+----------------------------------------+------------------------------------------------------+
| ``setPixelColorRGB`` | Sets the specified ``pixel`` to the provided |
| ``(pixel, red, green, blue, white=0)`` | ``red``, ``green``, ``blue``, and ``white`` values. |
| ``setPixelColorRGB | Sets the specified ``pixel`` to the provided |
| (pixel, red, green, blue, white=0)`` | ``red``, ``green``, ``blue``, and ``white`` values. |
+----------------------------------------+------------------------------------------------------+
| ``getPixelColorRGB(pixel) -> tuple`` | Returns a tuple of ``red``, ``green``, ``blue``, |
| | and ``white`` integers representing the pixel |
Expand Down Expand Up @@ -154,7 +186,7 @@ animation file.
+--------------------------------------+----------------------------------------------------------------+
| ``FRAME_MIN`` | The configuration value ``anim fps`` is used to calulate the |
| | duration of each frame in milliseconds and is made available |
| | as ``FRAME_MS`` to help with the frame timing of animations. |
| | as ``FRAME_MIN`` to help with the frame timing of animations. |
| | See the built in fade animations to see how you might use this |
| | value. |
+--------------------------------------+----------------------------------------------------------------+
Expand Down

0 comments on commit 964f6f3

Please sign in to comment.