it works somewhat
This commit is contained in:
parent
2c935df494
commit
4119328864
3 changed files with 10 additions and 23 deletions
|
@ -34,7 +34,7 @@ defmodule Eisrom.Morse.Server do
|
|||
# apply(pubsub(), :broadcast, [EisromUi.PubSub, "morse_progress", 0])
|
||||
{:reply, :ok, {nil, 0}}
|
||||
else
|
||||
pid = spawn(&Eisrom.Morse.Worker.signal/0)
|
||||
pid = spawn(&EisromUi.Morse.Worker.signal/0)
|
||||
{:reply, :ok, {pid, 0}}
|
||||
end
|
||||
end
|
||||
|
@ -49,7 +49,7 @@ defmodule Eisrom.Morse.Server do
|
|||
|
||||
@impl true
|
||||
def handle_cast({:progress, new_progress}, {pid, _progress}) do
|
||||
Phoenix.PubSub.broadcast(EiromUi.PubSub, "morse_progress", new_progress)
|
||||
Phoenix.PubSub.broadcast(EisromUi.PubSub, "morse_progress", new_progress)
|
||||
# apply(pubsub(), :broadcast, [EisromUi.PubSub, "morse_progress", new_progress])
|
||||
{:noreply, {pid, new_progress}}
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
defmodule Eisrom.Morse.Worker do
|
||||
defmodule EisromUi.Morse.Worker do
|
||||
@moduledoc """
|
||||
Functions to control the signal lamp connected with GPIO.
|
||||
"""
|
||||
|
@ -65,26 +65,12 @@ defmodule Eisrom.Morse.Worker do
|
|||
|> String.to_charlist()
|
||||
end
|
||||
|
||||
# Communicate with a deployed esrom node, if running on a host.
|
||||
case Application.get_env(:eisrom_ui, :target) do
|
||||
:host ->
|
||||
@esrom_node :"esrom@esrom.lan"
|
||||
def toggle_lamp(state) do
|
||||
{:ok, gpio} = Circuits.GPIO.open(relay_pin(), :output)
|
||||
Circuits.GPIO.write(gpio, state)
|
||||
end
|
||||
|
||||
def toggle_lamp(state) do
|
||||
# Check if the deployed esrom node is online.
|
||||
if :pong == Node.ping(@esrom_node) do
|
||||
:rpc.call(@esrom_node, Eisrom.Morse.Worker, :toggle_lamp, [state])
|
||||
end
|
||||
end
|
||||
|
||||
_ ->
|
||||
def toggle_lamp(state) do
|
||||
{:ok, gpio} = Circuits.GPIO.open(relay_pin(), :output)
|
||||
Circuits.GPIO.write(gpio, state)
|
||||
end
|
||||
|
||||
defp relay_pin() do
|
||||
Application.fetch_env!(:eisrom_ui, :relay_pin)
|
||||
end
|
||||
defp relay_pin() do
|
||||
Application.fetch_env!(:eisrom_ui, :relay_pin)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue