fetch relay pin from env
This commit is contained in:
parent
74bb465a38
commit
ef38b81dd6
3 changed files with 10 additions and 3 deletions
|
@ -5,7 +5,6 @@ defmodule Morse do
|
|||
Functions to control the signal lamp connected with GPIO.
|
||||
"""
|
||||
|
||||
@relay_pin 17
|
||||
@sleep_short 200
|
||||
@sleep_delay 400
|
||||
@sleep_long 700
|
||||
|
@ -25,7 +24,7 @@ defmodule Morse do
|
|||
end
|
||||
|
||||
def signal(symbols) do
|
||||
{:ok, gpio} = GPIO.open(@relay_pin, :output)
|
||||
{:ok, gpio} = GPIO.open(relay_pin(), :output)
|
||||
GPIO.write(gpio, @off)
|
||||
Process.sleep(@sleep_start)
|
||||
signal_sentence(gpio, String.graphemes(symbols))
|
||||
|
@ -40,10 +39,12 @@ defmodule Morse do
|
|||
|
||||
defp signal_sentence(gpio, [symbol | rest]) when symbol in [".", "-"] do
|
||||
GPIO.write(gpio, @on)
|
||||
|
||||
case symbol do
|
||||
"." -> Process.sleep(@sleep_short)
|
||||
"-" -> Process.sleep(@sleep_long)
|
||||
end
|
||||
|
||||
GPIO.write(gpio, @off)
|
||||
|
||||
Process.sleep(@sleep_delay)
|
||||
|
@ -59,4 +60,8 @@ defmodule Morse do
|
|||
defp signal_sentence(_gpio, [symbol | _rest]) do
|
||||
{:error, "Undefined symbol: " <> symbol}
|
||||
end
|
||||
|
||||
defp relay_pin() do
|
||||
Application.fetch_env!(:morse, :relay_pin)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,7 +15,7 @@ defmodule Morse.MixProject do
|
|||
def application do
|
||||
[
|
||||
extra_applications: [:logger],
|
||||
env: [morse_message: "...---..."]
|
||||
env: [morse_message: "...---...", relay_pin: 17]
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ config :logger, :console,
|
|||
# Use Jason for JSON parsing in Phoenix
|
||||
config :phoenix, :json_library, Jason
|
||||
|
||||
config :morse, :relay_pin, 17
|
||||
|
||||
# Import environment specific config. This must remain at the bottom
|
||||
# of this file so it overrides the configuration defined above.
|
||||
import_config "#{Mix.env()}.exs"
|
||||
|
|
Loading…
Reference in a new issue