GrovePi v0.6.1 GrovePi.Potentiometer.DefaultTrigger View Source
This is the default triggering mechanism for Potentiometer events. The
event is :changed
and includes the trigger state. The trigger state
for the default trigger is a struct containing a value
property.
Examples
iex> GrovePi.Potentiometer.DefaultTrigger.init([])
{:ok, %GrovePi.Potentiometer.DefaultTrigger.State{value: 0}}
iex> GrovePi.Potentiometer.DefaultTrigger.update(0, %{value: 0})
{:ok, %{value: 0}}
iex> GrovePi.Potentiometer.DefaultTrigger.update(500, %{value: 0})
{:changed, %{value: 500}}
iex> GrovePi.Potentiometer.DefaultTrigger.update(500, %{value: 500})
{:ok, %{value: 500}}
iex> GrovePi.Potentiometer.DefaultTrigger.update(125, %{value: 500})
{:changed, %{value: 125}}
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
.