Merge branch 'staging' of github.com:FarmBot/farmbot_os into qa/9.1.2-rc1
commit
2c724e2a85
|
@ -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
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
defmodule FarmbotCore.Asset.Repo.Migrations.ForceResyncPoints do
|
||||
use Ecto.Migration
|
||||
|
||||
alias FarmbotCore.Asset.{Repo, Point}
|
||||
alias FarmbotCore.Asset.Repo
|
||||
|
||||
def change do
|
||||
for %{id: id} = point when is_integer(id) <- Repo.all(Point) do
|
||||
Repo.delete!(point)
|
||||
end
|
||||
Repo.query("TRUNCATE points")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
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
|
|
@ -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
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
defmodule FarmbotOS.SysCalls.PointLookupTest do
|
||||
use ExUnit.Case
|
||||
use Mimic
|
||||
|
||||
alias FarmbotOS.SysCalls.PointLookup
|
||||
alias FarmbotCore.Asset.Point
|
||||
alias FarmbotCore.Asset.Repo
|
||||
|
@ -11,6 +13,8 @@ defmodule FarmbotOS.SysCalls.PointLookupTest do
|
|||
Tool
|
||||
}
|
||||
|
||||
setup :verify_on_exit!
|
||||
|
||||
test "failure cases" do
|
||||
err1 = PointLookup.point("GenericPointer", 24)
|
||||
assert {:error, "GenericPointer not found"} == err1
|
||||
|
@ -37,6 +41,35 @@ defmodule FarmbotOS.SysCalls.PointLookupTest do
|
|||
assert expected == PointLookup.point("GenericPointer", p.id)
|
||||
end
|
||||
|
||||
test "PointLookup.get_toolslot_for_tool/1 (gantry mounted tool)" do
|
||||
Repo.delete_all(Point)
|
||||
Repo.delete_all(Tool)
|
||||
expect(FarmbotOS.SysCalls.Movement, :get_current_x, 1, fn -> 9.99 end)
|
||||
|
||||
t = tool(%{name: "moisture probe"})
|
||||
|
||||
p =
|
||||
point(%{
|
||||
pointer_type: "ToolSlot",
|
||||
name: "Tool Slot",
|
||||
tool_id: t.id,
|
||||
gantry_mounted: true,
|
||||
x: 4.4,
|
||||
y: 4.4,
|
||||
z: 4.4
|
||||
})
|
||||
|
||||
important_part = %{
|
||||
name: "Tool Slot",
|
||||
x: 9.99,
|
||||
y: 4.4,
|
||||
z: 4.4,
|
||||
gantry_mounted: true
|
||||
}
|
||||
|
||||
assert important_part == PointLookup.get_toolslot_for_tool(t.id)
|
||||
end
|
||||
|
||||
test "PointLookup.get_toolslot_for_tool/1" do
|
||||
Repo.delete_all(Point)
|
||||
Repo.delete_all(Tool)
|
||||
|
@ -47,7 +80,8 @@ defmodule FarmbotOS.SysCalls.PointLookupTest do
|
|||
name: "Tool Slot",
|
||||
x: 1.9,
|
||||
y: 2.9,
|
||||
z: 3.9
|
||||
z: 3.9,
|
||||
gantry_mounted: false
|
||||
}
|
||||
|
||||
other_stuff = %{
|
||||
|
|
|
@ -13,6 +13,7 @@ Mimic.copy(FarmbotFirmware)
|
|||
Mimic.copy(FarmbotOS.Configurator.ConfigDataLayer)
|
||||
Mimic.copy(FarmbotOS.Configurator.DetsTelemetryLayer)
|
||||
Mimic.copy(FarmbotOS.Configurator.FakeNetworkLayer)
|
||||
Mimic.copy(FarmbotOS.SysCalls.Movement)
|
||||
Mimic.copy(File)
|
||||
Mimic.copy(MuonTrap)
|
||||
ExUnit.start()
|
||||
|
|
Loading…
Reference in New Issue