diff --git a/firmware/config/config.exs b/firmware/config/config.exs index 82b9a63..ff5aa36 100644 --- a/firmware/config/config.exs +++ b/firmware/config/config.exs @@ -28,6 +28,8 @@ config :logger, backends: [RingLogger] config :phoenix, :json_library, Jason +config :morse, :progress_socket, UiWeb.UserSocket + if Mix.target() != :host do "target.exs" else diff --git a/morse/lib/morse/server.ex b/morse/lib/morse/server.ex index 8c344e0..2aa28fd 100644 --- a/morse/lib/morse/server.ex +++ b/morse/lib/morse/server.ex @@ -30,7 +30,11 @@ defmodule Morse.Server do @impl true def handle_cast({:progress, new_progress}, {pid, _progress}) do - GenServer.cast(Ui.SocketAPI, {:broadcast_progress, new_progress}) + apply(progress_socket(), :broadcast_progress, [new_progress]) {:noreply, {pid, new_progress}} end + + defp progress_socket do + Application.fetch_env!(:morse, :progress_socket) + end end diff --git a/morse/lib/morse/worker.ex b/morse/lib/morse/worker.ex index 7821c48..31ebe13 100644 --- a/morse/lib/morse/worker.ex +++ b/morse/lib/morse/worker.ex @@ -49,7 +49,7 @@ defmodule Morse.Worker do Process.sleep(@sleep_delay) end - defp signal_symbol(_gpio, {? , index}, length) do + defp signal_symbol(_gpio, {?\s, index}, length) do Process.sleep(@sleep_pause) update_progress(index, length) end diff --git a/ui/lib/ui/application.ex b/ui/lib/ui/application.ex index 7bdd4f4..2d39b6c 100644 --- a/ui/lib/ui/application.ex +++ b/ui/lib/ui/application.ex @@ -9,8 +9,7 @@ defmodule Ui.Application do # List all child processes to be supervised children = [ # Start the endpoint when the application starts - UiWeb.Endpoint, - Ui.SocketAPI + UiWeb.Endpoint # Starts a worker by calling: Ui.Worker.start_link(arg) # {Ui.Worker, arg}, ] diff --git a/ui/lib/ui/socket_api.ex b/ui/lib/ui/socket_api.ex deleted file mode 100644 index 20775e0..0000000 --- a/ui/lib/ui/socket_api.ex +++ /dev/null @@ -1,18 +0,0 @@ -defmodule Ui.SocketAPI do - use GenServer - - def start_link(_) do - GenServer.start_link(__MODULE__, nil, name: __MODULE__) - end - - @impl true - def init(state) do - {:ok, state} - end - - @impl true - def handle_cast({:broadcast_progress, progress}, state) do - UiWeb.Endpoint.broadcast("morse:progress", "update", %{value: progress}) - {:noreply, state} - end -end diff --git a/ui/lib/ui_web/channels/user_socket.ex b/ui/lib/ui_web/channels/user_socket.ex index 4a588ea..f624af5 100644 --- a/ui/lib/ui_web/channels/user_socket.ex +++ b/ui/lib/ui_web/channels/user_socket.ex @@ -30,4 +30,9 @@ defmodule UiWeb.UserSocket do # # Returning `nil` makes this socket anonymous. def id(_socket), do: nil + + def broadcast_progress(progress) do + IO.puts("in user socket!") + UiWeb.Endpoint.broadcast("morse:progress", "update", %{value: progress}) + end end diff --git a/ui/lib/ui_web/endpoint.ex b/ui/lib/ui_web/endpoint.ex index d37fcc2..eac31d8 100644 --- a/ui/lib/ui_web/endpoint.ex +++ b/ui/lib/ui_web/endpoint.ex @@ -17,6 +17,7 @@ defmodule UiWeb.Endpoint do # Code reloading can be explicitly enabled under the # :code_reloader configuration of your endpoint. + IO.inspect code_reloading? if code_reloading? do socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket plug Phoenix.LiveReloader