GrovePi v0.6.1 GrovePi.Button.DefaultTrigger View Source
This is the default triggering mechanism for Button events. Events
are either pressed
or released
and include the trigger state.
The trigger state for the default trigger is a struct containing
a value
property.
Examples
iex> GrovePi.Button.DefaultTrigger.init([])
{:ok, %GrovePi.Button.DefaultTrigger.State{value: 0}}
iex> GrovePi.Button.DefaultTrigger.update(0, %{value: 0})
{:ok, %{value: 0}}
iex> GrovePi.Button.DefaultTrigger.update(1, %{value: 1})
{:ok, %{value: 1}}
iex> GrovePi.Button.DefaultTrigger.update(0, %{value: 1})
{:released, %{value: 0}}
iex> GrovePi.Button.DefaultTrigger.update(1, %{value: 0})
{:pressed, %{value: 1}}
Link to this section Summary
Functions
The init callback that must return {:ok, state}
or an error tuple
The update callback receives a new value and a trigger state and returns
a tuple of {:event_name, new_state}
Link to this section Functions
The init callback that must return {:ok, state}
or an error tuple.
Callback implementation for GrovePi.Trigger.init/1
.
The update callback receives a new value and a trigger state and returns
a tuple of {:event_name, new_state}
.
If no event is needed to fire return {:ok, new_state}
.
Callback implementation for GrovePi.Trigger.update/2
.