From 311477bbe7ccb2357437c1a17f6bf900df8274a9 Mon Sep 17 00:00:00 2001 From: maze Date: Sat, 6 Apr 2024 22:58:54 +0200 Subject: [PATCH] Formatting the code according to the standard --- lib/fledex.ex | 2 +- lib/fledex/animation/animator.ex | 2 +- lib/fledex/component/clock.ex | 13 ++++++++++--- lib/fledex/component/dot.ex | 4 +++- lib/fledex/component/thermometer.ex | 1 + lib/fledex/utils/dsl.ex | 5 +++-- lib/fledex/utils/pubsub.ex | 1 + 7 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/fledex.ex b/lib/fledex.ex index 6e15918..f99a428 100644 --- a/lib/fledex.ex +++ b/lib/fledex.ex @@ -229,7 +229,7 @@ defmodule Fledex do `Fledex.Component.Clock` example. """ -# @spec led_strip(atom, atom | keyword, Macro.t) :: Macro.t | map() + # @spec led_strip(atom, atom | keyword, Macro.t) :: Macro.t | map() defmacro led_strip(strip_name, strip_options \\ :kino, do: block) do configs_ast = Dsl.ast_extract_configs(block) diff --git a/lib/fledex/animation/animator.ex b/lib/fledex/animation/animator.ex index ac21b95..ef29597 100644 --- a/lib/fledex/animation/animator.ex +++ b/lib/fledex/animation/animator.ex @@ -55,7 +55,7 @@ defmodule Fledex.Animation.Animator do alias Fledex.Utils.PubSub @type config_t :: %{ - optional(:type) => (:animation | :static | :job | :coordinator), + optional(:type) => :animation | :static | :job | :coordinator, optional(:def_func) => (map -> Leds.t()), optional(:options) => keyword | nil, optional(:effects) => [{module, keyword}], diff --git a/lib/fledex/component/clock.ex b/lib/fledex/component/clock.ex index 3b8779e..f79a8cd 100644 --- a/lib/fledex/component/clock.ex +++ b/lib/fledex/component/clock.ex @@ -13,18 +13,25 @@ defmodule Fledex.Component.Clock do @impl true def configure(name, options) do trigger_name = Keyword.fetch!(options, :trigger_name) - {helper_color, hour_color, minute_color} = Keyword.get(options, :colors, {:davy_s_grey, :red, :blue}) + + {helper_color, hour_color, minute_color} = + Keyword.get(options, :colors, {:davy_s_grey, :red, :blue}) use Fledex + led_strip name, :config do - component :minute, Dot, + component(:minute, Dot, color: minute_color, count: 60, trigger_name: create_name(trigger_name, :minute) - component :hour, Dot, + ) + + component(:hour, Dot, color: hour_color, count: 24, trigger_name: create_name(trigger_name, :hour) + ) + static create_name(trigger_name, :helper) do leds(5) |> light(helper_color, 5) |> repeat(12) end diff --git a/lib/fledex/component/dot.ex b/lib/fledex/component/dot.ex index 83ed651..a1072f4 100644 --- a/lib/fledex/component/dot.ex +++ b/lib/fledex/component/dot.ex @@ -14,7 +14,9 @@ defmodule Fledex.Component.Dot do animation name do triggers when is_map(triggers) and is_map_key(triggers, trigger_name) -> leds(count) |> light(color, triggers[trigger_name]) - _triggers -> leds() + + _triggers -> + leds() end end end diff --git a/lib/fledex/component/thermometer.ex b/lib/fledex/component/thermometer.ex index b2338cf..f85e05c 100644 --- a/lib/fledex/component/thermometer.ex +++ b/lib/fledex/component/thermometer.ex @@ -20,6 +20,7 @@ defmodule Fledex.Component.Thermometer do # @spec configure(atom, keyword) :: %{atom => Animator.config_t()} def configure(name, options) when is_atom(name) and is_list(options) do name_helper = String.to_atom("#{name}.helper") + case Keyword.keyword?(options) do true -> %{ diff --git a/lib/fledex/utils/dsl.ex b/lib/fledex/utils/dsl.ex index 92d0052..181aebb 100644 --- a/lib/fledex/utils/dsl.ex +++ b/lib/fledex/utils/dsl.ex @@ -85,12 +85,13 @@ defmodule Fledex.Utils.Dsl do end def configure_strip(_strip_name, :config, config), do: config + def configure_strip(strip_name, strip_options, config) do # if is_atom(strip_options) and strip_options == :config do # config # else - Manager.register_strip(strip_name, strip_options) - Manager.register_config(strip_name, config) + Manager.register_strip(strip_name, strip_options) + Manager.register_config(strip_name, config) # end end diff --git a/lib/fledex/utils/pubsub.ex b/lib/fledex/utils/pubsub.ex index f3cb460..19a1d57 100644 --- a/lib/fledex/utils/pubsub.ex +++ b/lib/fledex/utils/pubsub.ex @@ -7,6 +7,7 @@ defmodule Fledex.Utils.PubSub do defdelegate subscribe(pubsub, topic), to: Phoenix.PubSub defdelegate unsubscribe(pubsub, topic), to: Phoenix.PubSub defdelegate broadcast(pubsub, topic, message), to: Phoenix.PubSub + def simple_broadcast(message) when is_map(message) do broadcast(:fledex, "trigger", {:trigger, message}) end