GrovePi v0.3.2 GrovePi.Trigger behaviour View Source

The Trigger behaviour is used for implementing triggers for poller behaviors such as GrovePi.Sound and GrovePi.Button. The triggers must implement two callbacks, init and update.

Link to this section Summary

Callbacks

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 Types

Link to this type event() View Source
event() :: atom
Link to this type state() View Source
state() :: struct

Link to this section Callbacks

Link to this callback init(args) View Source
init(args :: term) :: {:ok, state} | {:error, reason :: any}

The init callback that must return {:ok, state} or an error tuple.

Link to this callback update(value, state) View Source
update(value :: any, state) :: {:ok, state} | {event, state}

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}.