Fledex.Animation.Animator (fledex v0.5.0)
View SourceThe client often wants to run some animations. This can of course be done by
repeatedly updating the Leds
definitions and calling
Leds.send()
to send it to the driver.
This often results in constructs like the following:application
Enum.each(1..10, fn index ->
Leds
|> led_definition function(index)
|> Leds.send(config)
Process.sleep(600)
end)
This creates a loop over some led definition, sends it to the LED strip and then waits for a while to do the next step. The index can be used for either influencing the led definition function, or the offset of the strip and thereby influencing the animation.
This approach is not really good, because of the following drawbacks:
- it is difficult to update the animation while it's running, because it would require to interrupt the loop
- the sending to the LED strip can not be optimized, except by knowing at which update frequency the driver is updating the strip. Of course it would be possible for a client to figure this out, but who would do that?
The idea of this module is to take care of those concerns by implementing a GenServer that runs the loop, but can be updated in-between.
From the above example it can be seen that two things can be updated:
- The led_definition_function and
- The send config (even though we will have to implement that as a function too due to the handling of the index)
Note: the time is not something that can be specified, since the animator will
be triggered by Fledex.LedStrip
in it's update frequency. Thus to implement
some wait pattern, the trigger counter (or some other timer logic) should be used
Both of them can be set by defining an appropriate function and setting and resetting a reference at will
This module does not define any functions on its own, because the interface is defined
by Fledex.Animation.AnimatorBase
.
Summary
Functions
Returns a specification to start this module under a supervisor.
Types
@type config_t() :: %{ optional(:type) => :animation | :static, optional(:def_func) => (map() -> Fledex.Leds.t()), optional(:options) => keyword() | nil, optional(:effects) => [{module(), keyword()}] }
Functions
@spec apply_effects(Fledex.Leds.t(), [{module(), map()}], map(), map()) :: {Fledex.Leds.t(), map()}
Returns a specification to start this module under a supervisor.
See Supervisor
.