Skip to content
Permalink
Browse files

Add :set_pin_io_mode rpc back to known rpcs

  • Loading branch information...
ConnorRigby committed Aug 8, 2019
1 parent de1a65a commit f771e0f3053c3261c0b4faa4e09f20c08929a201
@@ -406,6 +406,16 @@ defmodule FarmbotCeleryScript.Compiler do
end
end

# compiles set_pin_io_mode
compile :set_pin_io_mode, %{pin_number: pin_number, pin_io_mode: mode} do
quote location: :keep do
pin = unquote(compile_ast(pin_number))
mode = unquote(compile_ast(mode))
FarmbotCeleryScript.SysCalls.log("Setting pin mode: #{pin}: #{mode}")
FarmbotCeleryScript.SysCalls.set_pin_io_mode(pin, mode)
end
end

# Expands find_home(all) into three find_home/1 calls
compile :find_home, %{axis: "all"} do
quote location: :keep do
@@ -55,6 +55,7 @@ defmodule FarmbotCeleryScript.SysCalls do
@callback resource_update(String.t(), resource_id, map()) :: ok_or_error
@callback send_message(type :: String.t(), message :: String.t(), [atom]) :: ok_or_error
@callback set_servo_angle(pin :: number(), value :: number()) :: ok_or_error
@callback set_pin_io_mode(pin :: number(), mode :: number()) :: ok_or_error
@callback set_user_env(env_name :: String.t(), env_value :: String.t()) :: ok_or_error
@callback sync() :: ok_or_error
@callback wait(millis :: number()) :: ok_or_error
@@ -107,6 +107,9 @@ defmodule FarmbotCeleryScript.SysCalls.Stubs do
@impl true
def set_servo_angle(pin, value), do: error(:set_servo_angle, [pin, value])

@impl true
def set_pin_io_mode(pin, mode), do: error(:set_pin_io_mode, [pin, mode])

@impl true
def set_user_env(env_name, env_value), do: error(:set_user_env, [env_name, env_value])

@@ -326,6 +326,22 @@ defmodule FarmbotCeleryScript.CompilerTest do
""")
end

test "compiles set_pin_io_mode" do
compiled =
compile(%AST{
kind: :set_pin_io_mode,
args: %{pin_number: 23, pin_io_mode: "input"}
})

assert compiled ==
strip_nl("""
pin = 23
mode = "input"
FarmbotCeleryScript.SysCalls.log("Setting pin mode: \#{pin}: \#{mode}")
FarmbotCeleryScript.SysCalls.set_pin_io_mode(pin, mode)
""")
end

defp compile(ast) do
ast
|> Compiler.compile_ast()

0 comments on commit f771e0f

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