diff --git a/README.md b/README.md index 9196bba..ec80676 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Add `:arb` to your list of dependencies: ```elixir def deps do [ - {:arb, "~> 0.1.0"} + {:arb, "~> 0.2.0"} ] end ``` diff --git a/lib/arb.ex b/lib/arb.ex index 7916309..fb18f74 100644 --- a/lib/arb.ex +++ b/lib/arb.ex @@ -43,4 +43,18 @@ defmodule Arb do def get_active(port \\ nil) def get_active(port) when is_integer(port) or is_nil(port), do: Native.get_active(port) def get_active(_port), do: {:error, :invalid_args} + + @doc """ + Resets the relay board. + + ## Examples + + iex> Arb.reset() + :ok + + """ + @spec reset(integer) :: {:ok, list(integer)} | {:error, atom} + def reset(port \\ nil) + def reset(port) when is_integer(port) or is_nil(port), do: Native.reset(port) + def reset(_port), do: {:error, :invalid_args} end diff --git a/lib/arb/native.ex b/lib/arb/native.ex index b852b43..ed7e61c 100644 --- a/lib/arb/native.ex +++ b/lib/arb/native.ex @@ -11,5 +11,7 @@ defmodule Arb.Native do def get_active(_port), do: error() + def reset(_port), do: error() + defp error, do: :erlang.nif_error(:nif_not_loaded) end diff --git a/mix.exs b/mix.exs index 0fef4de..f945d28 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Arb.MixProject do def project do [ app: :arb, - version: "0.1.0", + version: "0.2.0", elixir: "~> 1.6", start_permanent: Mix.env() == :prod, compilers: [:rustler] ++ Mix.compilers(), diff --git a/native/arb/.gitignore b/native/arb/.gitignore new file mode 100644 index 0000000..eccd7b4 --- /dev/null +++ b/native/arb/.gitignore @@ -0,0 +1,2 @@ +/target/ +**/*.rs.bk diff --git a/native/arb/Cargo.lock b/native/arb/Cargo.lock index f21c507..7f434a3 100644 --- a/native/arb/Cargo.lock +++ b/native/arb/Cargo.lock @@ -1,38 +1,19 @@ -[[package]] -name = "ansi_term" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "arb" version = "0.1.0" -source = "git+https://github.com/adriankumpf/abacom-relay-board?tag=v0.1.0#813f36ad1a7b9787bee8a076a539dc9912c44c0c" dependencies = [ - "clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libusb 0.3.0 (git+https://github.com/adriankumpf/libusb-rs?branch=dev)", -] - -[[package]] -name = "arb" -version = "0.1.0" -dependencies = [ - "arb 0.1.0 (git+https://github.com/adriankumpf/abacom-relay-board?tag=v0.1.0)", + "arb 0.2.0 (git+https://github.com/adriankumpf/abacom-relay-board?tag=v0.2.0)", "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "rustler 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustler_codegen 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "atty" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" +name = "arb" +version = "0.2.0" +source = "git+https://github.com/adriankumpf/abacom-relay-board?tag=v0.2.0#78d4eb5b67a57067817270257bd91213e4ef04b5" dependencies = [ - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libusb 0.3.0 (git+https://github.com/adriankumpf/libusb-rs?branch=dev)", ] [[package]] @@ -48,25 +29,6 @@ name = "bit-vec" version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "bitflags" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "clap" -version = "2.31.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "atty 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "erlang_nif-sys" version = "0.6.3" @@ -127,19 +89,6 @@ name = "quote" version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "redox_syscall" -version = "0.1.37" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "redox_termios" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rustler" version = "0.16.0" @@ -159,11 +108,6 @@ dependencies = [ "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "strsim" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "syn" version = "0.11.11" @@ -182,34 +126,11 @@ dependencies = [ "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "termion" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "textwrap" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "unicode-segmentation" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "unicode-width" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "unicode-xid" version = "0.0.4" @@ -223,43 +144,15 @@ dependencies = [ "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "vec_map" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "void" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "winapi" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [metadata] -"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -"checksum arb 0.1.0 (git+https://github.com/adriankumpf/abacom-relay-board?tag=v0.1.0)" = "" -"checksum atty 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "af80143d6f7608d746df1520709e5d141c96f240b0e62b0aa41bdfb53374d9d4" +"checksum arb 0.2.0 (git+https://github.com/adriankumpf/abacom-relay-board?tag=v0.2.0)" = "" "checksum bit-set 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e6e1e6fb1c9e3d6fcdec57216a74eaa03e41f52a22f13a16438251d8e88b89da" "checksum bit-vec 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "02b4ff8b16e6076c3e14220b39fbc1fabb6737522281a388998046859400895f" -"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf" -"checksum clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0f16b89cbb9ee36d87483dc939fe9f1e13c05898d56d7b230a0d4dff033a536" "checksum erlang_nif-sys 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2804cb6ae339787d993faafdd5e4af5a882128e44343a710d1061c487086eaa3" "checksum heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea04fa3ead4e05e51a7c806fc07271fdbde4e246a6c6d1efd52e72230b771b82" "checksum lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "cf186d1a8aa5f5bee5fd662bc9c1b949e0259e1bcc379d1f006847b0080c7417" @@ -269,21 +162,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum libusb-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4c53b6582563d64ad3e692f54ef95239c3ea8069e82c9eb70ca948869a7ad767" "checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" -"checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd" -"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum rustler 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "346b8e397f17bc25a7a2b2a394fe016547817fe17a7c6849d878f1c6f1e369a2" "checksum rustler_codegen 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0b94e2cb016a43a5e269a5cf76523d00278347f985cf7fbf6062ef026236144d" -"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" -"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" -"checksum textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0b59b6b4b44d867f1370ef1bd91bfb262bf07bf0ae65c202ea2fbc16153b693" "checksum unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a8083c594e02b8ae1654ae26f0ade5158b119bd88ad0e8227a5d8fcd72407946" -"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2ae5ddb18e1c92664717616dd9549dde73f539f01bd7b77c2edb2446bdff91" -"checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" -"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" -"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/native/arb/Cargo.toml b/native/arb/Cargo.toml index bbdf5f9..392294a 100644 --- a/native/arb/Cargo.toml +++ b/native/arb/Cargo.toml @@ -12,4 +12,4 @@ crate-type = ["dylib"] rustler = "0.16.0" rustler_codegen = "0.16.0" lazy_static = "0.2" -arb = { git = "https://github.com/adriankumpf/abacom-relay-board", tag = 'v0.1.0' } +arb = { git = "https://github.com/adriankumpf/abacom-relay-board", tag = 'v0.2.0' } diff --git a/native/arb/src/lib.rs b/native/arb/src/lib.rs index fa2ffaf..7199746 100644 --- a/native/arb/src/lib.rs +++ b/native/arb/src/lib.rs @@ -91,11 +91,21 @@ fn get_active<'a>(env: NifEnv<'a>, args: &[NifTerm<'a>]) -> NifResult(env: NifEnv<'a>, args: &[NifTerm<'a>]) -> NifResult> { + let port: Option = args[0].decode()?; + + match arb::reset(port) { + Err(err) => return Ok(arb_error_to_term(env, err)), + Ok(()) => Ok(atoms::ok().encode(env)), + } +} + rustler_export_nifs! { "Elixir.Arb.Native", [ ("activate", 2, activate), - ("get_active", 1, get_active) + ("get_active", 1, get_active), + ("reset", 1, reset) ], None }