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

67 lines
1.8 KiB
Elixir
Raw Normal View History

defmodule AugieWeb.DashboardLive do
use Phoenix.LiveView
alias Augie.Telemetry
@moduledoc """
A live view which shows or hides the dashboard based on whether the Teensy USB
serial connection was found.
"""
def render(assigns) do
~L"""
<%= if @connected do %>
<div class="grid-x grid-padding-x">
<div class="cell small-1 large-4">
<%= live_render(@socket, AugieWeb.IMUSensorLive, id: :imu) %>
</div>
<div class="cell small-1 large-4">
<%= live_render(@socket, AugieWeb.PowerSensorLive, id: :power) %>
<%= live_render(@socket, AugieWeb.GPSSensorLive, id: :gps) %>
</div>
<div class="cell small-1 large-4">
<%= live_render(@socket, AugieWeb.CameraLive, id: :camera) %>
<%= live_render(@socket, AugieWeb.LoggerLive, id: :logger) %>
</div>
</div>
<% else %>
<div class="callout alert">
<h5> No Teensy USB Connection Found</h5>
<%= if Enum.any?(@uarts) do %>
<p>
Found the following UART devices:
<ul>
<%= for {device, properties} <- @uarts do %>
<li>
<code><%= device %></code>
<ul>
<%= for {name, value} <- properties do %>
<%= name %> &mdash; <%= value %>
<% end %>
</ul>
</li>
<% end %>
</ul>
</p>
<% end %>
</div>
<% end %>
"""
end
def mount(_params, _context, socket) do
if connected?(socket), do: :timer.send_interval(1000, :tick)
{:ok, detect(socket)}
end
def handle_info(:tick, socket) do
{:noreply, detect(socket)}
end
defp detect(socket) do
assign(socket, connected: Telemetry.connected?(), uarts: Circuits.UART.enumerate())
end
end