View Source LibNFC.Presence behaviour (LibNFC v0.1.0)
Passive tag monitor process.
- Repeatedly polls for passive targets in range.
- Emits an event when target enters.
- Emits another event when target leaves.
Target presence is tracked by polling nfc_initiator_target_is_present
with a short debounce.
Usage
defmodule MyApp.NFC do
use LibNFC.Presence
@impl true
def handle_target_in(target, state) do
# ...
{:ok, state}
end
@impl true
def handle_target_out(state) do
# ...
{:ok, state}
end
end
defmodule MyApp.Application do
def start(_, _) do
children = [
...
{MyApp.NFC, client_state: :foo}
]
Supervisor.start_link(...)
end
end
Summary
Callbacks
Emitted when a passive target is detected.
Emitted when selected target left.
Called on process initialization to open the NFC reader device.
Functions
Returns a specification to start this module under a supervisor.
Starts the passive tag monitor process.
Types
@type client_state() :: any()
Arbitrary client state held within the presence monitor process.
@type server_options() :: [ client_state: client_state(), mock: boolean(), schedule_delay: non_neg_integer(), alive_after_last_seen: non_neg_integer() ]
Server Options
client_state
initial client state (default: nil)mock
when set to true, default device will be the mock (default: false)schedule_delay
poll interval in ms (default: 300)alive_after_last_seen
debounce leave event for a short period as some calls tonfc_initiator_target_is_present
come back as false negatives (default: 500)
Callbacks
@callback handle_target_in(LibNFC.target_info(), client_state()) :: {:ok, client_state()}
Emitted when a passive target is detected.
@callback handle_target_out(client_state()) :: {:ok, client_state()}
Emitted when selected target left.
@callback open_device(client_state()) :: {:ok, LibNFC.device()}
Called on process initialization to open the NFC reader device.
Optional callback. Defaults to opening the "first" device found by calling nfc_open
without
a connstring.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec start_link(module(), server_options()) :: GenServer.on_start()
Starts the passive tag monitor process.