Fix calibration after report.

This commit is contained in:
connor rigby 2017-11-21 12:45:58 -08:00
parent b351882d68
commit 13c8cd675f
3 changed files with 23 additions and 2 deletions

View file

@ -47,7 +47,7 @@ config :farmbot, Farmbot.System.ConfigStorage,
config :farmbot, :behaviour,
authorization: Farmbot.Bootstrap.Authorization,
system_tasks: Farmbot.Host.SystemTasks,
update_handler: Farmbot.Host.UpdateHandler
# firmware_handler: Farmbot.Firmware.UartHandler
update_handler: Farmbot.Host.UpdateHandler,
firmware_handler: Farmbot.Firmware.UartHandler
config :farmbot, :uart_handler, tty: "/dev/ttyACM0"

View file

@ -10,6 +10,7 @@ defmodule Farmbot.CeleryScript.AST.Node.Calibrate do
do_reduce([:y, :z, :x], @default_speed, env)
end
def execute(%{speed: speed, axis: axis}, _, env) do
env = mutate_env(env)
case Farmbot.Firmware.calibrate(axis, speed) do
@ -18,6 +19,10 @@ defmodule Farmbot.CeleryScript.AST.Node.Calibrate do
end
end
def execute(%{axis: _axis} = args, body, env) do
execute(Map.put(args, :speed, @default_speed), body, env)
end
defp do_reduce([axis | rest], speed, env) do
case execute(%{axis: axis, speed: speed}, [], env) do
{:ok, new_env} -> do_reduce(rest, speed, new_env)

View file

@ -351,6 +351,22 @@ defmodule Farmbot.Firmware do
end
end
defp handle_gcode({:report_calibration, axis, status}, state) do
maybe_cancel_timer(state.timer)
Logger.busy 1, "Axis #{axis} calibration: #{status}"
{nil, state}
end
defp handle_gcode({:report_axis_calibration, param, val}, state) do
spawn fn() ->
case Farmbot.Firmware.update_param(param, val) do
:ok -> Logger.success 1, "Calibrated #{param}: #{val}"
{:error, reason} -> Logger.error 1, "Failed to set #{param}: #{val} (#{inspect reason})"
end
end
{nil, state}
end
defp handle_gcode(:error, state) do
maybe_cancel_timer(state.timer)
if state.current do