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

25 lines
765 B
Elixir
Raw Normal View History

defmodule AugieWeb.DashboardLive do
2020-04-28 21:09:54 +12:00
use Phoenix.LiveView, layout: {AugieWeb.LayoutView, "live.html"}
alias Augie.Firmata
2020-04-28 21:09:54 +12:00
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
2020-04-28 21:09:54 +12:00
if connected?(socket), do: PubSub.subscribe(Augie.PubSub, "serial_telemetry")
{:ok, assign(socket, connected: Firmata.connected?(), uarts: Circuits.UART.enumerate())}
end
2020-04-28 21:09:54 +12:00
def handle_info({:connected, false}, socket) do
{:noreply, assign(socket, connected: false, uarts: Circuits.UART.enumerate())}
end
2020-04-28 21:09:54 +12:00
def handle_info({:connected, _}, socket) do
{:noreply, assign(socket, connected: true, uarts: [])}
end
end