This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
augie/webapp/lib/augie_web/live/dashboard_live.ex
2020-05-02 19:09:46 +12:00

25 lines
786 B
Elixir

defmodule AugieWeb.DashboardLive do
use Phoenix.LiveView, layout: {AugieWeb.LayoutView, "live.html"}
alias Augie.SerialTelemetry
alias Phoenix.PubSub
@moduledoc """
A live view which shows or hides the dashboard based on whether the Teensy USB
serial connection was found.
"""
def mount(_params, _context, socket) do
if connected?(socket), do: PubSub.subscribe(Augie.PubSub, "serial_telemetry")
{:ok,
assign(socket, connected: SerialTelemetry.connected?(), uarts: Circuits.UART.enumerate())}
end
def handle_info({:connected, false}, socket) do
{:noreply, assign(socket, connected: false, uarts: Circuits.UART.enumerate())}
end
def handle_info({:connected, _}, socket) do
{:noreply, assign(socket, connected: true, uarts: [])}
end
end