added dialyzer and added type specs for bot commands

pull/197/head
connor rigby 2016-11-08 08:15:17 -08:00
parent 32bf00d67a
commit 2051e23fc3
3 changed files with 24 additions and 7 deletions

View File

@ -1,6 +1,7 @@
defmodule Command do
require Logger
@log_tag "BotControl"
@type command_output :: :done | :timeout | :error
@moduledoc """
BotCommands.
"""
@ -16,8 +17,9 @@ defmodule Command do
end
@doc """
Home All (TODO: this might be broken)
Home All
"""
@spec home_all(number | nil) :: command_output
def home_all(speed \\ nil) do
msg = "HOME ALL"
Logger.debug(msg)
@ -27,7 +29,7 @@ defmodule Command do
@doc """
Home x
I dont think anything uses these.
I dont think anything uses this.
"""
def home_x() do
msg = "HOME X"
@ -59,6 +61,7 @@ defmodule Command do
@doc """
Writes a pin high or low
"""
@spec write_pin(number, number, number) :: command_output
def write_pin(pin, value, mode)
when is_integer(pin) and is_integer(value) and is_integer(mode) do
BotState.set_pin_mode(pin, mode)
@ -69,6 +72,7 @@ defmodule Command do
@doc """
Moves to (x,y,z) point.
"""
@spec move_absolute(number, number, number, number | nil) :: command_output
def move_absolute(x ,y ,z ,s \\ nil)
def move_absolute(x, y, z, s) do
msg = "Moving to X#{x} Y#{y} Z#{z}"
@ -82,7 +86,12 @@ defmodule Command do
Gets the current position
then pipes into move_absolute
"""
def move_relative(e)
@spec move_relative(
{:x, number | nil, number} |
{:y, number | nil, number} |
{:z, number | nil, number} |
%{x: number, y: number, z: number, speed: number | nil}
) :: command_output
def move_relative({:x, s, move_by}) when is_integer move_by do
[x,y,z] = BotState.get_current_pos
move_absolute(x + move_by,y,z,s)
@ -113,6 +122,7 @@ defmodule Command do
Reads all the params.
TODO: Make these not magic numbers.
"""
@spec read_all_params(list(number)) :: :ok | :fail
def read_all_params(params \\ [0,11,12,13,21,22,23,
31,32,33,41,42,43,51,
52,53,61,62,63,71,72,73])
@ -131,6 +141,7 @@ defmodule Command do
Reads a pin value.
mode can be 0 (digital) or 1 (analog)
"""
@spec read_pin(number, 0 | 1) :: command_output
def read_pin(pin, mode \\ 0) when is_integer(pin) do
BotState.set_pin_mode(pin, mode)
Gcode.Handler.block_send("F42 P#{pin} M#{mode}") |> logmsg("read_pin")
@ -139,6 +150,7 @@ defmodule Command do
@doc """
gets the current value, and then toggles it.
"""
@spec toggle_pin(number) :: command_output
def toggle_pin(pin) when is_integer(pin) do
pinMap = BotState.get_pin(pin)
case pinMap do
@ -156,6 +168,7 @@ defmodule Command do
@doc """
Reads a param. Needs the integer version of said param.
"""
@spec read_param(number) :: command_output
def read_param(param) when is_integer param do
Gcode.Handler.block_send "F21 P#{param}"
end
@ -163,6 +176,7 @@ defmodule Command do
@doc """
Update a param. Param needs to be an integer.
"""
@spec update_param(number | nil, number) :: command_output
def update_param(param, value) when is_integer param do
Gcode.Handler.block_send "F22 P#{param} V#{value}"
Command.read_param(param)
@ -172,6 +186,7 @@ defmodule Command do
{:error, "Unknown param"}
end
@spec logmsg(command_output, String.t) :: command_output
defp logmsg(:done, command) when is_bitstring(command) do
RPC.MessageHandler.log("#{command} Complete", [],[@log_tag])
:done

View File

@ -101,9 +101,10 @@ defmodule Fw.Mixfile do
def deps(:dev) do
deps ++ [
# {:fake_nerves, github: "ConnorRigby/fake_nerves"},
{:fake_nerves, path: "../fake_nerves"},
{:credo, "~> 0.4"}]
{:fake_nerves, github: "ConnorRigby/fake_nerves"},
# {:fake_nerves, path: "../fake_nerves"},
{:credo, "~> 0.4"},
{:dialyxir, "~> 0.4"}]
end
def platform_deps("rpi3") do

View File

@ -7,12 +7,13 @@
"cowboy": {:hex, :cowboy, "1.0.4", "a324a8df9f2316c833a470d918aaf73ae894278b8aa6226ce7a9bf699388f878", [:rebar, :make], [{:cowlib, "~> 1.0.0", [hex: :cowlib, optional: false]}, {:ranch, "~> 1.0", [hex: :ranch, optional: false]}]},
"cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], []},
"credo": {:hex, :credo, "0.5.2", "92e8c9f86e0ffbf9f688595e9f4e936bc96a52e5606d2c19713e9e4d191d5c74", [:mix], [{:bunt, "~> 0.1.6", [hex: :bunt, optional: false]}]},
"dialyxir": {:hex, :dialyxir, "0.4.0", "53ac3014bb4aef647728a697052b4db3a84c6742de7aab0e0a1c863ea274007b", [:mix], []},
"elixir_ale": {:hex, :elixir_ale, "0.5.6", "a94c89a17ec39ad4c4a9a90d4f00bd9f33b2f2e98703317fbdf5efceab276b44", [:mix, :make], [{:elixir_make, "~> 0.3", [hex: :elixir_make, optional: false]}]},
"elixir_make": {:hex, :elixir_make, "0.4.0", "992f38fabe705bb45821a728f20914c554b276838433349d4f2341f7a687cddf", [:mix], []},
"erlware_commons": {:hex, :erlware_commons, "0.21.0", "a04433071ad7d112edefc75ac77719dd3e6753e697ac09428fc83d7564b80b15", [:rebar3], [{:cf, "0.2.1", [hex: :cf, optional: false]}]},
"exjsx": {:hex, :exjsx, "3.2.1", "1bc5bf1e4fd249104178f0885030bcd75a4526f4d2a1e976f4b428d347614f0f", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, optional: false]}]},
"exrm": {:hex, :exrm, "1.0.8", "5aa8990cdfe300282828b02cefdc339e235f7916388ce99f9a1f926a9271a45d", [:mix], [{:relx, "~> 3.5", [hex: :relx, optional: false]}]},
"fake_nerves": {:git, "https://github.com/ConnorRigby/fake_nerves.git", "9bbf56f3e538580f9e7e09d08d77021b907f2a44", []},
"fake_nerves": {:git, "https://github.com/ConnorRigby/fake_nerves.git", "0ffd1df5f4a823257c1c5966d74cd1b26263b2a9", []},
"farmbot_auth": {:git, "https://github.com/Farmbot/farmbot_auth.git", "97f003ee4f241c65a6f4f835e9db733c84c7f477", []},
"farmbot_configurator": {:git, "https://github.com/Farmbot/farmbot_configurator.git", "1fb13c087859659dcf189b814c2bc4c4c3ea5b53", []},
"gen_stage": {:hex, :gen_stage, "0.8.0", "a76e3f0530f86fae8b8a1021c06527b1ec171cf4c0bdfecd8d5ad0376d1205af", [:mix], []},