ex_co2_mini v0.1.1 ExCO2Mini.Reader
Reads data packets from the USB CO₂ sensor, decodes them, and sends events to the subscribed process(es).
Due to the ioctl
calls required, this module will open a Port
to a tiny
C wrapper, rather than reading the device directly.
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor
Starts reading from the USB CO₂ sensor device
Starts sending data values to a target process
Link to this section Functions
child_spec(init_arg)
Returns a specification to start this module under a supervisor.
See Supervisor
.
start_link(opts)
Starts reading from the USB CO₂ sensor device.
opts
is a keyword list. It accepts all of the options that GenServer.start_link/3
does, as well as the following:
opts[:device]
(required) — The path to the CO₂Mini device, e.g./dev/hidraw0
or a symlink to the device.opts[:subscribers]
— A list of initial subscribers (default: none).- This can be used to save a call to
subscribe/2
, and/or to ensure correct data routing in the case of a supervisor restart.
- This can be used to save a call to
opts[:send_from_name]
— If true, thenopts[:name]
must be included as well. Messages sent by this reader will use that name instead of the PID.
Returns {:ok, pid}
once the reader (and wrapper process) has been successfully started.
subscribe(reader, target \\ self())
Starts sending data values to a target process.
target
can be a PID or a registered name (atom or module).
A given name or PID can only be subscribed once. Subsequent calls to this
function will be effectively ignored, and target
will still only receive
one message per data packet. However, if a process may receive multiple
messages per packet if subscribed under both its PID and name.