Possible implementation. Needs tests.
parent
e0068bd3c2
commit
a939c4f812
|
@ -24,6 +24,7 @@ defmodule FarmbotCore.Asset.Point do
|
|||
field(:z, :float)
|
||||
field(:tool_id, :integer)
|
||||
field(:discarded_at, :utc_datetime)
|
||||
field(:gantry_mounted, :boolean, default: false)
|
||||
field(:monitor, :boolean, default: true)
|
||||
timestamps()
|
||||
end
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
defmodule FarmbotCore.Asset.Repo.Migrations.AddGantryMountedFields do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:points) do
|
||||
add(:gantry_mounted, :boolean, default: false)
|
||||
end
|
||||
|
||||
# Invalidate cache of local device resource:
|
||||
execute("UPDATE points SET updated_at = \"1970-11-07 16:52:31.618000\"")
|
||||
end
|
||||
end
|
||||
# farmbot_core/priv/asset/migrations/20190926161914_add_point_discarded_at.exs
|
||||
# farmbot_core/priv/repo/migrations/20200219001135_add_gantry_mounted_fields.exs
|
|
@ -2,6 +2,8 @@ defmodule FarmbotOS.SysCalls.PointLookup do
|
|||
@moduledoc false
|
||||
|
||||
alias FarmbotCore.Asset
|
||||
alias FarmbotOS.SysCalls.Movement
|
||||
|
||||
require Logger
|
||||
|
||||
def point(kind, id) do
|
||||
|
@ -11,15 +13,6 @@ defmodule FarmbotOS.SysCalls.PointLookup do
|
|||
end
|
||||
end
|
||||
|
||||
def get_toolslot_for_tool(id) do
|
||||
with %{id: ^id} <- Asset.get_tool(id: id),
|
||||
%{name: name, x: x, y: y, z: z} <- Asset.get_point(tool_id: id) do
|
||||
%{name: name, x: x, y: y, z: z}
|
||||
else
|
||||
nil -> {:error, "Could not find point for tool by id: #{id}"}
|
||||
end
|
||||
end
|
||||
|
||||
def get_point_group(id) when is_number(id) do
|
||||
case Asset.get_point_group(id: id) do
|
||||
nil -> {:error, "Could not find PointGroup.#{id}"}
|
||||
|
@ -35,4 +28,28 @@ defmodule FarmbotOS.SysCalls.PointLookup do
|
|||
%{id: id}, acc -> %{acc | point_ids: [id | acc.point_ids]}
|
||||
end)
|
||||
end
|
||||
|
||||
def get_toolslot_for_tool(id) do
|
||||
tool = Asset.get_tool(id: id)
|
||||
p = Asset.get_point(tool_id: id)
|
||||
|
||||
with %{id: ^id} <- tool,
|
||||
%{name: name, x: x, y: y, z: z, gantry_mounted: mounted} <- p do
|
||||
maybe_adjust_coordinates(%{
|
||||
name: name,
|
||||
x: x,
|
||||
y: y,
|
||||
z: z,
|
||||
gantry_mounted: mounted
|
||||
})
|
||||
else
|
||||
nil -> {:error, "Could not find point for tool by id: #{id}"}
|
||||
end
|
||||
end
|
||||
|
||||
defp maybe_adjust_coordinates(%{gantry_mounted: true} = point) do
|
||||
%{point | x: Movement.get_current_x()}
|
||||
end
|
||||
|
||||
defp maybe_adjust_coordinates(point), do: point
|
||||
end
|
||||
|
|
|
@ -39,13 +39,15 @@ defmodule FarmbotOS.SysCalls.PointLookupTest do
|
|||
|
||||
test "PointLookup.get_toolslot_for_tool/1" do
|
||||
Repo.delete_all(Point)
|
||||
Repo.delete_all(Tool)
|
||||
t = tool(%{name: "moisture probe"})
|
||||
|
||||
important_part = %{
|
||||
name: "Tool Slot",
|
||||
x: 1.9,
|
||||
y: 2.9,
|
||||
z: 3.9
|
||||
z: 3.9,
|
||||
gantry_mounted: false
|
||||
}
|
||||
|
||||
other_stuff = %{
|
||||
|
|
Loading…
Reference in New Issue