Skip to content
Permalink
Browse files

Re-enable set_servo_angle

* set_servo_angle works.
* Tests for set_servo_angle in  FarmbotCeleryScript.Syscalls
  • Loading branch information
RickCarlino committed Dec 27, 2019
1 parent d65a542 commit 845e69ce7efa31c6c2c4b0f1d3950b96c948ea20
@@ -285,7 +285,7 @@ defmodule FarmbotCeleryScript.SysCalls do
end

def set_servo_angle(sys_calls \\ @sys_calls, pin_num, pin_value) do
number_or_error(sys_calls, :set_servo_angle, [pin_num, pin_value])
ok_or_error(sys_calls, :set_servo_angle, [pin_num, pin_value])
end

def set_pin_io_mode(sys_calls \\ @sys_calls, pin_number, pin_io_mode) do
@@ -133,6 +133,17 @@ defmodule FarmbotCeleryScript.SysCallsTest do
assert {:error, "not installed"} == SysCalls.execute_script(TestSysCalls, "take-photo", %{})
end

test "set_servo_angle errors", %{shim: shim} do
:ok = shim_fun_ok(shim)
arg0 = [5, 40]
assert :ok = SysCalls.set_servo_angle(TestSysCalls, "set_servo_angle", arg0)
assert_receive {:set_servo_angle, arg0}

arg1 = [40, -5]
:ok = shim_fun_error(shim, "boom")
assert {:error, "boom"} == SysCalls.set_servo_angle(TestSysCalls, "set_servo_angle", arg1)
end

test "get_sequence", %{shim: shim} do
:ok =
shim_fun_ok(shim, %AST{
@@ -84,6 +84,9 @@ defmodule FarmbotOS.SysCalls do
@impl true
defdelegate toggle_pin(number), to: PinControl

@impl true
defdelegate set_servo_angle(pin, angle), to: PinControl

@impl true
defdelegate resource_update(kind, id, params), to: ResourceUpdate

@@ -282,11 +285,6 @@ defmodule FarmbotOS.SysCalls do
%{x: x, y: y, z: z}
end

@impl true
def set_servo_angle(_pin, _angle) do
{:error, "set_servo_angle not yet supported"}
end

@impl true
def install_first_party_farmware() do
{:error, "install_first_party_farmware not yet supported"}
@@ -42,6 +42,16 @@ defmodule FarmbotOS.SysCalls.PinControl do
{:error, "Unknown pin data: #{inspect(pin_number)}"}
end

def set_servo_angle(pin, angle) do
case FarmbotFirmware.command({:servo_write, [p: pin, v: angle]}) do
:ok ->
:ok

{:error, reason} ->
{:error, "Firmware error: #{inspect(reason)}"}
end
end

defp do_toggle_pin(%Peripheral{pin: pin_number} = data, value) do
with :ok <- FarmbotFirmware.command({:pin_write, [p: pin_number, v: value, m: 0]}),
value when is_number(value) <- do_read_pin(data, 0) do

0 comments on commit 845e69c

Please sign in to comment.
You can’t perform that action at this time.