Skip to content
Permalink
Browse files

Re-implement set_pin_io_mode

  • Loading branch information...
ConnorRigby committed Aug 8, 2019
1 parent f771e0f commit 8dbeb65c69faa46e7f6c0cc8741de92f96391315
@@ -18,7 +18,8 @@ defmodule FarmbotOS.SysCalls do
ExecuteScript,
FactoryReset,
FlashFirmware,
SendMessage
SendMessage,
SetPinIOMode
}

alias FarmbotCore.{Asset, Asset.Repo, Asset.Private, Asset.Sync, BotState, Leds}
@@ -50,6 +51,9 @@ defmodule FarmbotOS.SysCalls do
@impl true
defdelegate factory_reset(package), to: FactoryReset

@impl true
defdelegate set_pin_io_mode(pin, mode), to: SetPinIOMode

@impl true
def log(message) do
if FarmbotCore.Asset.fbos_config(:sequence_body_log) do
@@ -0,0 +1,19 @@
defmodule FarmbotOS.SysCalls.SetPinIOMode do
alias FarmbotFirmware

def set_pin_io_mode(pin_number, mode) do
mode = extract_set_pin_mode(to_string(mode))

case FarmbotFirmware.command({:pin_mode_write, [p: pin_number, m: mode]}) do
:ok ->
:ok

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

def extract_set_pin_mode("input"), do: 0x0
def extract_set_pin_mode("input_pullup"), do: 0x2
def extract_set_pin_mode("output"), do: 0x1
end
@@ -71,6 +71,11 @@ defmodule Farmbot.TestSupport.CeleryScript.TestSysCalls do
call({:set_servo_angle, [pin_number, angle]})
end

@impl true
def set_pin_io_mode(pin_number, mode) do
call({:set_pin_io_mode, [pin_number, mode]})
end

@impl true
def install_first_party_farmware() do
call({:install_first_party_farmware, []})

0 comments on commit 8dbeb65

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