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.
Internals
The underlying Registry uses {key, :rising} and {key, :falling} as its
keys. Subscribing with :both simply registers the caller under both keys,
so publishing an edge is a plain registry dispatch — no filtering or match
specs required.
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 for 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.
A subscriber who subscribed with :both is counted twice.
@spec count_subscriptions(key(), Wafer.GPIO.pin_condition()) :: non_neg_integer()
Count the number of active subscriptions for key and pin_condition.
Subscribers who subscribed with :both contribute to both counts.
@spec publish(key(), :rising | :falling) :: {:ok, non_neg_integer()}
Publish an interrupt to subscribers that are interested in key and
pin_condition.
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
keya key which uniquely describes the pin. Probably a combination of device name and pin.pin_conditioneither:rising,:fallingor:both. Subscribing with:bothis equivalent to subscribing with:risingand:fallingseparately.connthe receiver's connection to the pin, sent back to them in the interrupt message.metadataarbitrary 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.
A subscriber who subscribed with :both is returned as two entries — one
per edge.
@spec subscriptions(key(), Wafer.GPIO.pin_condition()) :: [ {Wafer.GPIO.pin_condition(), Wafer.Conn.t(), metadata :: any(), receiver :: pid()} ]
Returns a list of all subscriptions for key and pin_condition.
Subscribers who subscribed with :both appear in the lists for both
:rising and :falling. Calling with :both returns the same as
subscriptions/1.
@spec unsubscribe(key(), Wafer.GPIO.pin_condition(), Wafer.Conn.t()) :: :ok
Remove all subscriptions for key, pin_condition and conn.
Unsubscribing with :both removes the caller's subscription from both the
:rising and :falling buckets.