it works somewhat

This commit is contained in:
Pim Kunis 2022-10-10 22:40:31 +02:00
parent 2c935df494
commit 4119328864
3 changed files with 10 additions and 23 deletions

View file

@ -1,6 +1,7 @@
%{
"beam_notify": {:hex, :beam_notify, "1.0.0", "5b8dceed76f8ac4acadf4d2915ac85b98c42bb17d7dd58253c7593d2a0deedbd", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "a80331f6c3596918affa408d91ed634106b7ae71b3fc589432363aca68378362"},
"castore": {:hex, :castore, "0.1.18", "deb5b9ab02400561b6f5708f3e7660fc35ca2d51bfc6a940d2f513f89c2975fc", [:mix], [], "hexpm", "61bbaf6452b782ef80b33cdb45701afbcf0a918a45ebe7e73f1130d661e66a06"},
"circuits_gpio": {:hex, :circuits_gpio, "1.0.1", "53e0aefebc0eedc1326f7f28cc53831bed84654767eb3c613934c6ec8ca77caa", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "d8e918fdfada785b24a071edc7e4dbd334b3b42c6a0298fc0d13e7f1fc5b3e0a"},
"circular_buffer": {:hex, :circular_buffer, "0.4.1", "477f370fd8cfe1787b0a1bade6208bbd274b34f1610e41f1180ba756a7679839", [:mix], [], "hexpm", "633ef2e059dde0d7b89bbab13b1da9d04c6685e80e68fbdf41282d4fae746b72"},
"cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"},
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"},

View file

@ -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

View file

@ -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