Wafer.Conn behaviour (wafer v1.0.2)
Defines a behaviour for connecting to a peripheral.
This behaviour is used by all the driver types in Wafer
and you should
implement it for your devices also.
example
Example
Implementing Conn
for a HTS221
chip connected via Circuits' I2C driver.
defmodule HTS221 do
defstruct ~w[conn]a
alias Wafer.Driver.Circuits.I2C, as: Driver
@behaviour Wafer.Conn
@default_bus "i2c-1"
@default_address 0x5F
def acquire(opts) when is_list(opts) do
bus = Keyword.get(opts, :bus, @default_bus)
address = Keyword.get(opts, :address, @default_address)
with {:ok, conn} <- Driver.acquire(bus_name: bus, address: address),
do: {:ok, %HTS221{conn: conn}}
end
end
Link to this section Summary
Callbacks
Acquire a connection to a peripheral using the provided driver.
Link to this section Types
Link to this type
option()
Specs
Link to this type
options()
Specs
options() :: [option()]
Specs
t() :: any()
Link to this section Callbacks
Link to this callback
acquire(options)
Specs
Acquire a connection to a peripheral using the provided driver.