Fledex.Animation.Coordinator (fledex v0.6.0)
View SourceThe coordinator is a module that is responsible for running the coordinator function.
This module is rather simple:
- It listens to events on the
Fledex.Utils.PubSub.channel_state()channel - Passes the events to the function (
:func) with which it was configured (or changed through theconfig/3function) - And keeps track of some settings, that the function can use in it's processing
See config_t/0 for more details on how to implement the function.
Summary
Types
The configuration of a coordinator.
Functions
Returns a specification to start this module under a supervisor.
Change the config of the given coordinator
Start a new coordinator for the given led strip with the specified config
Stop the coordinator
Types
@type config_t() :: %{ type: :coordinator, options: keyword(), func: (broadcast_state :: any(), context :: map(), state :: keyword() -> new_state :: keyword()) }
The configuration of a coordinator.
The most important part is the :func which is a function that
takes 3 parameters
broadcast_state: event (usually an atom),context: descriptor to describe who has sent ou the event. It usually contains the strip_name and/or the animation_name and/or information about the effect.state: contains the state of the coordinator. The first time the function is called the:optionsare passed in asstate. The Coordinator should return anew_state.
You probably would impelment it something like this:
func: fn
{:stop_start, %{strip_name: :john, animation_name: :doe}, state} ->
# ... do something with the animations or effects
# ... update the state if necessary
state
_ ->
# do nothing
state
end
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Change the config of the given coordinator
@spec start_link( strip_name :: atom(), coordinator_name :: atom(), config :: config_t() ) :: GenServer.on_start()
Start a new coordinator for the given led strip with the specified config
Stop the coordinator