Fledex.Animation.AnimatorInterface behaviour (fledex v0.5.0)

View Source

The behaviour for an Animator.

This behaviour is the interface expected by the Fledex.Animation.Manager and should be implemented as a GenServer. If you implement an animation you will have to implement those functions but you can use Fledex.Animation.AnimatorBase to assist you.

Summary

Callbacks

(Re-)Configure this animation. You will have to implement this function on server side. This will look something like the following

When the animation is no long required, this function should be called. This will call (by default) GenServer.stop. The animation can implement the terminate/2 function if necessary.

Create a new animation (with a given name and configuration) for the led strip with the specified name.

Update the configuration of an effect at runtime

Functions

This utility function will create an atomic name for the combination of strip name and animation name. This is used to name the animator. It is important that we do have a naming convention, because we would otherwise have a hard time to shutdown animators that have been removed. We do not keep a reference, but only a config Therefore the animator needs to adhere to this naming convention to properly be shut down. It is the responsibility of the Animator to set the servername correctly. The Fledex.Animation.AnimatorBase is doing this by default.

Callbacks

config strip_name, animation_name, config

@callback config(strip_name :: atom(), animation_name :: atom(), config :: map()) :: :ok

(Re-)Configure this animation. You will have to implement this function on server side. This will look something like the following:

  @spec handle_cast({:config, config_t}, state_t) :: {:noreply, state_t}
  def handle_cast({:config, config}, state) do
    # do something here
    {:noreply, state}
  end

shutdown(strip_name, animation_name)

@callback shutdown(strip_name :: atom(), animation_name :: atom()) :: :ok

When the animation is no long required, this function should be called. This will call (by default) GenServer.stop. The animation can implement the terminate/2 function if necessary.

start_link(config, strip_name, animation_name)

@callback start_link(config :: any(), strip_name :: atom(), animation_name :: atom()) ::
  GenServer.on_start()

Create a new animation (with a given name and configuration) for the led strip with the specified name.

update_effect(strip_name, animation_name, what, config_update)

@callback update_effect(
  strip_name :: atom(),
  animation_name :: atom(),
  what :: :all | pos_integer(),
  config_update :: keyword()
) :: :ok

Update the configuration of an effect at runtime

Sometimes you want to change the configuration of an effect not only at definition time, but aiso at runtime. It is possible to apply the configuration change to ALL effects of the animator, which can be convenient especially if you want to enable/disable all effects at once.

Functions

build_name(strip_name, type, animation_name)

@spec build_name(atom(), :animator | :job | :coordinator, atom()) :: atom()

This utility function will create an atomic name for the combination of strip name and animation name. This is used to name the animator. It is important that we do have a naming convention, because we would otherwise have a hard time to shutdown animators that have been removed. We do not keep a reference, but only a config Therefore the animator needs to adhere to this naming convention to properly be shut down. It is the responsibility of the Animator to set the servername correctly. The Fledex.Animation.AnimatorBase is doing this by default.