59 lines
1.7 KiB
Elixir
59 lines
1.7 KiB
Elixir
defmodule ExSpeedGame.Application do
|
|
# See https://hexdocs.pm/elixir/Application.html
|
|
# for more information on OTP Applications
|
|
@moduledoc false
|
|
|
|
use Application
|
|
|
|
alias ExSpeedGame.Game.{
|
|
ButtonInput,
|
|
Lights,
|
|
Menu
|
|
}
|
|
|
|
alias ExSpeedGame.Game.Supervisor, as: GameSupervisor
|
|
|
|
def start(_type, _args) do
|
|
# See https://hexdocs.pm/elixir/Supervisor.html
|
|
# for other strategies and supported options
|
|
opts = [strategy: :one_for_one, name: ExSpeedGame.Supervisor]
|
|
|
|
children =
|
|
[
|
|
# Children for all targets
|
|
# Starts a worker by calling: ExSpeedGame.Worker.start_link(arg)
|
|
# {ExSpeedGame.Worker, arg},
|
|
] ++ children(target())
|
|
|
|
Supervisor.start_link(children, opts)
|
|
end
|
|
|
|
# List all child processes to be supervised
|
|
def children(:host) do
|
|
[
|
|
# Children that only run on the host
|
|
# Starts a worker by calling: ExSpeedGame.Worker.start_link(arg)
|
|
# {ExSpeedGame.Worker, arg},
|
|
]
|
|
end
|
|
|
|
def children(_target) do
|
|
pins = Application.get_env(:ex_speed_game, :button_pins)
|
|
led_pins = Application.get_env(:ex_speed_game, :button_light_pins)
|
|
debounce_delay = Application.get_env(:ex_speed_game, :debounce_delay)
|
|
|
|
[
|
|
# Children for all targets except host
|
|
# Starts a worker by calling: ExSpeedGame.Worker.start_link(arg)
|
|
{ButtonInput,
|
|
%ButtonInput.Options{pins: pins, debounce_delay: debounce_delay, name: ButtonInput}},
|
|
{Lights, %Lights.Options{light_pins: led_pins, name: Lights}},
|
|
{Menu, %Menu.Options{name: Menu}},
|
|
{DynamicSupervisor, strategy: :one_for_one, name: GameSupervisor}
|
|
]
|
|
end
|
|
|
|
def target() do
|
|
Application.get_env(:ex_speed_game, :target)
|
|
end
|
|
end
|