Skip to content

Commit

Permalink
code review changes - engine.ex
Browse files Browse the repository at this point in the history
Completely removes config functions from Engine
  • Loading branch information
Jesse Van Volkinburg committed Jul 30, 2020
1 parent 7f5d16c commit de998ce
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions lib/rgb_matrix/engine.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ defmodule RGBMatrix.Engine do
alias Layout.LED
alias RGBMatrix.Animation

@type frame :: %{LED.t() => RGBMatrix.any_color_model()}

defmodule State do
@moduledoc false
defstruct [:leds, :animation, :paintables, :last_frame, :timer, :configurables]
Expand All @@ -22,27 +24,22 @@ defmodule RGBMatrix.Engine do
This module registers its process globally and is expected to be started by a
supervisor.
This function accepts the following arguments as a tuple:
This function accepts the following argument:
- `leds` - The list of LEDs to be painted on.
- `initial_animation` - The Animation type to initialize and play when the
engine starts.
"""
@spec start_link(leds :: [LED.t()]) ::
GenServer.on_start()
@spec start_link(leds :: [LED.t()]) :: GenServer.on_start()
def start_link(leds) do
GenServer.start_link(__MODULE__, leds, name: __MODULE__)
end

@doc """
Sets the given animation as the currently active animation.
"""
@spec set_animation(animation_type :: Animation.type()) :: :ok
def set_animation(animation_type) do
GenServer.cast(__MODULE__, {:set_animation, animation_type})
@spec set_animation(animation :: Animation.t()) :: :ok
def set_animation(animation) do
GenServer.cast(__MODULE__, {:set_animation, animation})
end

@typep frame :: %{LED.t() => RGBMatrix.any_color_model()}

@doc """
Register a paint function for the engine to send frames to.
Expand Down Expand Up @@ -73,14 +70,6 @@ defmodule RGBMatrix.Engine do
GenServer.cast(__MODULE__, {:interact, led})
end

@doc """
Updates the current animation's configuration.
"""
@spec update_animation_config(params :: map) :: :ok | :error
def update_animation_config(params) do
GenServer.call(__MODULE__, {:update_animation_config, params})
end

@doc """
Register a config function for the engine to send animation configuration to
when it changes.
Expand Down Expand Up @@ -218,17 +207,6 @@ defmodule RGBMatrix.Engine do
{:reply, :ok, state}
end

@impl GenServer
def handle_call({:update_animation_config, params}, _from, state) do
animation = Animation.update_config(state.animation, params)

state =
%State{state | animation: animation}
|> inform_configurables()

{:reply, Xebow.update_animation_config(animation), state}
end

@impl GenServer
def handle_call({:register_configurable, config_fn}, _from, state) do
state = add_configurable(config_fn, state)
Expand Down

0 comments on commit de998ce

Please sign in to comment.