View Source Wafer.InterruptRegistry (wafer v1.1.0)
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 you should probably use it
if you're writing your own driver which supports sending interrupts to
subscribers.
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
.
Types
@type key() :: any()
Functions
@spec count_subscriptions(key()) :: non_neg_integer()
Count the number of active subscriptions for key
.
@spec count_subscriptions(key(), Wafer.GPIO.pin_condition()) :: non_neg_integer()
Count the number of active subscriptions for key
and pin_condition
.
@spec 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}
.
@spec 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
iex> subscribe({MCP230017.Pin, 13}, :rising, conn)
:ok
@spec 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
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
.
Are there any subscribers to key
?
@spec subscribers?(key(), Wafer.GPIO.pin_condition()) :: boolean()
Are there any subscribers to key
and pin_condition
?
@spec subscriptions(key()) :: [ {Wafer.GPIO.pin_condition(), Wafer.Conn.t(), metadata :: any(), receiver :: pid()} ]
Returns a list of all subscriptions to key
.
@spec 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
.
@spec unsubscribe(key(), Wafer.GPIO.pin_condition(), Wafer.Conn.t()) :: :ok
Remove all subscriptions for key
, pin_condition
and conn
.