25 lines
786 B
Elixir
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
|