hid v0.1.4 HID

NIF wrapper for hidapi library.

Summary

Functions

Closes the HID device

Enumerates the HID devices

Opens the HID device

Reads an Input report from a HID device

Writes an Output report to a HID device

Types

enum_result()
enum_result :: {:ok, [HID.DeviceInfo]} | {:error, :ehidenum}
handle()
handle :: term
open_result()
open_result ::
  {:ok, handle} |
  {:error, :ehidopen} |
  {:error, :ehidopen, String.t}
read_result()
read_result ::
  {:ok, binary} |
  {:error, :ehidread} |
  {:error, :ehidread, String.t}
write_result()
write_result ::
  {:ok, non_neg_integer} |
  {:error, :ehidwrite} |
  {:error, :ehidwrite, String.t}

Functions

close(device)
close(device :: handle) :: :ok

Closes the HID device.

See original docs for details.

device is a device handle, returned by open.

enumerate(vendor_id \\ 0, product_id \\ 0)
enumerate(vendor_id :: byte, product_id :: byte) :: enum_result

Enumerates the HID devices.

See original docs for details.

vendor_id and product_id are the positive integer masks for enumeration. 0x00 means any value. Both arguments have 0x00 as a default value.

open(path)
open(path :: String.t | charlist) :: open_result

Opens the HID device.

See original docs for details.

You can open device by path ("/dev/hidraw0" for example) or by vendor_id, product_id and optionally serial arguments.

path can be string or char list.

vendor_id and product_id are positive integers.

serial can be a string or charlist.

Function returns device handle that can be used in other device reading/writing functions.

open(vendor_id, product_id)
open(vendor_id :: byte, product_id :: byte) :: open_result
open(vendor_id, product_id, serial)
open(vendor_id :: byte, product_id :: byte, serial :: String.t | charlist) :: open_result
read(device, size)
read(device :: handle, size :: integer) :: read_result

Reads an Input report from a HID device.

See original docs for details.

Reads at most size bytes from HID device. Note that first byte of data would be a HID Report ID, so you should include this byte into size.

write(device, data)
write(device :: handle, data :: binary | [byte]) :: write_result

Writes an Output report to a HID device.

See original docs for details.

Writes data to HID device. Note that first byte of data must be a HID Report ID. If device supports a single reports only this byte must be set to 0x00.

Returns a number of actually written bytes.