esrom/ui/lib/ui_web/controllers/page_controller.ex

39 lines
789 B
Elixir
Raw Normal View History

2019-07-13 18:16:46 +00:00
defmodule UiWeb.PageController do
use UiWeb, :controller
def index(conn, _params) do
conn
|> send_resp(201, "")
end
def instructions(conn, _params) do
conn
|> render(:instructions)
end
def morse(conn, _params) do
conn
|> render(:morse)
end
def start(conn, _params) do
now = System.system_time(:second)
case get_start_time() do
start_time when start_time + 35 <= now ->
System.put_env("MORSE_START_TIME", Integer.to_string(now))
2019-07-14 13:05:45 +00:00
Morse.signal("...---...")
text(conn, "Done.")
_ ->
text(conn, "It is still in progress...")
end
end
defp get_start_time() do
case System.get_env("MORSE_START_TIME") do
nil -> 0
start_time -> String.to_integer(start_time)
end
2019-07-13 18:16:46 +00:00
end
end