feat: use AprilTag instead of QR code

This commit is contained in:
Schuwi
2025-09-14 18:52:24 +02:00
parent 788ad54724
commit 589c9964aa
600 changed files with 12814 additions and 122 deletions

View File

@@ -24,11 +24,9 @@ defmodule ComponentsElixir.Inventory do
processed_locations = compute_hierarchy_fields_batch(locations)
|> Enum.sort_by(&{&1.level, &1.name})
# Ensure QR codes exist for all locations (in background)
# Ensure AprilTag SVGs exist for all locations
spawn(fn ->
Enum.each(processed_locations, fn location ->
ComponentsElixir.QRCode.get_qr_image_url(location)
end)
ComponentsElixir.AprilTag.generate_all_apriltag_svgs()
end)
processed_locations
@@ -109,11 +107,11 @@ defmodule ComponentsElixir.Inventory do
end
@doc """
Gets a storage location by QR code.
Gets a storage location by AprilTag ID.
"""
def get_storage_location_by_qr_code(qr_code) do
def get_storage_location_by_apriltag_id(apriltag_id) do
StorageLocation
|> where([sl], sl.qr_code == ^qr_code)
|> where([sl], sl.apriltag_id == ^apriltag_id)
|> preload(:parent)
|> Repo.one()
|> case do
@@ -138,8 +136,6 @@ defmodule ComponentsElixir.Inventory do
case result do
{:ok, location} ->
# Automatically generate QR code image
spawn(fn -> ComponentsElixir.QRCode.get_qr_image_url(location) end)
{:ok, location}
error ->
error
@@ -159,8 +155,6 @@ defmodule ComponentsElixir.Inventory do
case result do
{:ok, updated_location} ->
# Automatically regenerate QR code image if name or hierarchy changed
spawn(fn -> ComponentsElixir.QRCode.get_qr_image_url(updated_location, force_regenerate: true) end)
{:ok, updated_location}
error ->
error
@@ -171,9 +165,6 @@ defmodule ComponentsElixir.Inventory do
Deletes a storage location.
"""
def delete_storage_location(%StorageLocation{} = storage_location) do
# Clean up QR code image before deleting
ComponentsElixir.QRCode.cleanup_qr_image(storage_location.id)
Repo.delete(storage_location)
end
@@ -185,17 +176,17 @@ defmodule ComponentsElixir.Inventory do
end
@doc """
Parses a QR code string and returns storage location information.
Parses an AprilTag ID and returns storage location information.
"""
def parse_qr_code(qr_string) do
case get_storage_location_by_qr_code(qr_string) do
def parse_apriltag_id(apriltag_id) when is_integer(apriltag_id) do
case get_storage_location_by_apriltag_id(apriltag_id) do
nil ->
{:error, :not_found}
location ->
{:ok, %{
type: :storage_location,
location: location,
qr_code: qr_string
apriltag_id: apriltag_id
}}
end
end