Wafer.InterruptRegistry (wafer v1.0.1)
This module provides Wafer's interrupt registry. This allows multiple subscribers to be subscribed to interrupts from many different pins.
It is used by Driver.Circuits.GPIO.Dispatcher
and
Driver.ElixirALE.GPIO.Dispatcher
and you should probably use it if you're
writing your own driver which supports sending interrupts to subscribers.
Link to this section Summary
Functions
Count the number of active subscriptions for key
.
Count the number of active subscriptions for key
and pin_condition
.
Publish an interrupt to subscribers that are interested in key
and
pin_condition
.
Subscribe the calling process to interrupts for the specified pin_condition
using the provided key
.
Subscribe the calling process to interrupts for the specified pin_condition
using the provided key
.
Are there any subscribers to key
?
Are there any subscribers to key
and pin_condition
?
Returns a list of all subscriptions to key
.
Returns a list of all subscriptions key
and pin_condition
.
Remove all subscriptions for key
, pin_condition
and conn
.
Link to this section Types
key()
Specs
key() :: any()
Link to this section Functions
count_subscriptions(key)
Specs
count_subscriptions(key()) :: non_neg_integer()
Count the number of active subscriptions for key
.
count_subscriptions(key, pin_condition)
Specs
count_subscriptions(key(), Wafer.GPIO.pin_condition()) :: non_neg_integer()
Count the number of active subscriptions for key
and pin_condition
.
publish(key, pin_condition)
Specs
publish(key(), :rising | :falling) :: {:ok, non_neg_integer()}
Publish an interrupt to subscribers that are interested in key
and
pin_condition
.
Searches the registry for all subscribers to are subscribed to pin_condition
or :both
and publishes the interrupt message to them. The interrupt message
takes the form {:interrupt, Conn.t(), :rising | :falling, metadata :: any}
.
subscribe(key, pin_condition, conn)
Specs
subscribe(key(), Wafer.GPIO.pin_condition(), Wafer.Conn.t()) :: :ok
Subscribe the calling process to interrupts for the specified pin_condition
using the provided key
.
See subscribe/4
for more information.
example
Example
iex> subscribe({MCP230017.Pin, 13}, :rising, conn)
:ok
subscribe(key, pin_condition, conn, metadata)
Specs
subscribe(key(), Wafer.GPIO.pin_condition(), Wafer.Conn.t(), any()) :: :ok
Subscribe the calling process to interrupts for the specified pin_condition
using the provided key
.
arguments
Arguments
key
a key which uniquely describes the pin. Probably a combination of device name and pin.pin_condition
either:rising
,:falling
or:both
.conn
the receiver's connection to the pin, sent back to them in the interrupt message.metadata
arbitrary data which will be sent to the receiver process in the interrupt message. Defaults tonil
.
subscribers?(key)
Specs
Are there any subscribers to key
?
subscribers?(key, pin_condition)
Specs
subscribers?(key(), Wafer.GPIO.pin_condition()) :: boolean()
Are there any subscribers to key
and pin_condition
?
subscriptions(key)
Specs
subscriptions(key()) :: [ {Wafer.GPIO.pin_condition(), Wafer.Conn.t(), metadata :: any(), receiver :: pid()} ]
Returns a list of all subscriptions to key
.
subscriptions(key, pin_condition)
Specs
subscriptions(key(), Wafer.GPIO.pin_condition()) :: [ {Wafer.GPIO.pin_condition(), Wafer.Conn.t(), metadata :: any(), receiver :: pid()} ]
Returns a list of all subscriptions key
and pin_condition
.
unsubscribe(key, pin_condition, conn)
Specs
unsubscribe(key(), Wafer.GPIO.pin_condition(), Wafer.Conn.t()) :: :ok
Remove all subscriptions for key
, pin_condition
and conn
.