GrovePi v0.6.1 GrovePi.DHT.DefaultTrigger View Source

This is the default triggering mechanism for DHT events. The event is :changed and includes the trigger state. The trigger state for the default trigger is a struct containing temp and humidity properties.

Examples

iex> GrovePi.DHT.DefaultTrigger.init([])
{:ok, %GrovePi.DHT.DefaultTrigger.State{temp: 0, humidity: 0}}
iex> GrovePi.DHT.DefaultTrigger.update({0, 0}, %{temp: 0, humidity: 0})
{:ok, %{temp: 0, humidity: 0}}
iex> GrovePi.DHT.DefaultTrigger.update({11.3, 45.5}, %{temp: 0, humidity: 0})
{:changed, %{temp: 11.3, humidity: 45.5}}
iex> GrovePi.DHT.DefaultTrigger.update({11.3, 45.5}, %{temp: 11.3, humidity: 45.5})
{:ok, %{temp: 11.3, humidity: 45.5}}
iex> GrovePi.DHT.DefaultTrigger.update({22.5, 34.5}, %{temp: 11.3, humidity: 45.5})
{:changed, %{temp: 22.5, humidity: 34.5}}

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.