GrovePi v0.6.1 GrovePi.IRReflective.DefaultTrigger View Source

This is the default triggering mechanism for IRReflective events. Events are either close or far and include the trigger state. The trigger state for the default trigger is a struct containing a value property.

Examples

iex> GrovePi.IRReflective.DefaultTrigger.init([])
{:ok, %GrovePi.IRReflective.DefaultTrigger.State{value: 0}}

iex> GrovePi.IRReflective.DefaultTrigger.update(0, %{value: 0})
{:ok, %{value: 0}}

iex> GrovePi.IRReflective.DefaultTrigger.update(1, %{value: 1})
{:ok, %{value: 1}}

iex> GrovePi.IRReflective.DefaultTrigger.update(0, %{value: 1})
{:released, %{value: 0}}

iex> GrovePi.IRReflective.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.