Skip to content

Commit

Permalink
Update documentation and README
Browse files Browse the repository at this point in the history
  • Loading branch information
adriankumpf committed Apr 1, 2018
1 parent bf575af commit 44aa5a2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 27 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Arb
# arb-ex

A NIF for controlling the ABACOM CH341A relay board ([documentation](https://hexdocs.pm/fritz_api)).
An Elixir NIF for controlling the ABACOM CH341A relay board ([documentation](https://hexdocs.pm/arb)).

## Installation
## Getting started

### Requirements

In order to compile a recent version of `rust` must be installed (tested with 1.25). Also, the native [libusb](https://github.com/libusb/libusb) library is required. On Debian-based distributions install `libusb-1.0-0-dev`.

### Installation

**Note:** this package is still in beta and thus not yet available on Hex.

Add `:arb` to your list of dependencies:

Expand Down Expand Up @@ -30,3 +38,7 @@ iex> Arb.get_active()
docker build -t arb-ex .
docker run --privileged -it arb-ex
```

## See also

* [abacom-relay-board](https://github.com/adriankumpf/abacom-relay-board)
5 changes: 4 additions & 1 deletion lib/arb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ defmodule Arb do
@doc """
Given a list of ids turns on the corresponding relays. An empty list turns off all relays.
The relays are labeled from 1 to 8 according to the
[data sheet](http://www.abacom-online.de/div/ABACOM_USB_LRB.pdf).
## Options
The accepted options are:
Expand All @@ -28,7 +31,7 @@ defmodule Arb do
def activate(_ids, _opts), do: {:error, :invalid_args}

@doc """
Returns a list of ids whose relays are active.
Returns ids of active relays.
## Examples
Expand Down
6 changes: 0 additions & 6 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ defmodule Arb.MixProject do
]
end

def application do
[
# extra_applications: [:logger]
]
end

defp deps do
[
{:rustler, "~> 0.16.0"}
Expand Down
22 changes: 11 additions & 11 deletions native/arb/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion native/arb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ crate-type = ["dylib"]
rustler = "0.16.0"
rustler_codegen = "0.16.0"
lazy_static = "0.2"
abacom-relay-board = { git = "https://github.com/adriankumpf/abacom-relay-board" }
arb = { git = "https://github.com/adriankumpf/abacom-relay-board", tag = 'v0.1.0' }
10 changes: 5 additions & 5 deletions native/arb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extern crate rustler;
#[macro_use]
extern crate rustler_codegen;

extern crate abacom_relay_board;
extern crate arb;

use rustler::{NifEncoder, NifEnv, NifResult, NifTerm, types::NifListIterator};

Expand Down Expand Up @@ -33,8 +33,8 @@ struct Options {
pub verify: bool,
}

fn arb_error_to_term<'a>(env: NifEnv<'a>, err: abacom_relay_board::Error) -> NifTerm<'a> {
use abacom_relay_board::Error;
fn arb_error_to_term<'a>(env: NifEnv<'a>, err: arb::Error) -> NifTerm<'a> {
use arb::Error;

let error = match err {
Error::NotFound => atoms::not_found().encode(env),
Expand Down Expand Up @@ -64,7 +64,7 @@ fn activate<'a>(env: NifEnv<'a>, args: &[NifTerm<'a>]) -> NifResult<NifTerm<'a>>

let options: Options = args[1].decode()?;

match abacom_relay_board::switch_relays(relays, options.verify, options.port) {
match arb::set_status(relays, options.verify, options.port) {
Err(err) => Ok(arb_error_to_term(env, err)),
Ok(()) => Ok(atoms::ok().encode(env)),
}
Expand All @@ -73,7 +73,7 @@ fn activate<'a>(env: NifEnv<'a>, args: &[NifTerm<'a>]) -> NifResult<NifTerm<'a>>
fn get_active<'a>(env: NifEnv<'a>, args: &[NifTerm<'a>]) -> NifResult<NifTerm<'a>> {
let port: Option<u8> = args[0].decode()?;

let result = match abacom_relay_board::get_relays(port) {
let result = match arb::get_status(port) {
Err(err) => return Ok(arb_error_to_term(env, err)),
Ok(inner) => inner,
};
Expand Down

0 comments on commit 44aa5a2

Please sign in to comment.