HcSr501Occupation.MovementSensor behaviour (hc_sr_501_occupation v0.1.1)

Creates an instance of the movement and occupation sensor.

Usage:

defmodule MyApp.MySensor do
  use HcSr501Occupation.MovementSensor

  @impl HcSr501Occupation.MovementSensor
  def pin, do: 17

  @impl HcSr501Occupation.MovementSensor
  def occupation_timeout, do: :timer.seconds(180)
end

Add to the supervision tree, eg

defmodule MyApp.Application do
  use Application

  def start(_type, _args) do
    children = [
      MyApp.MySensor
    ]
    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

See README for full usage.

Link to this section Summary

Callbacks

In milliseconds, how long after movement is no longer detected do we flip the state to unoccupied

GPIO Pin to which the sensor is attached

Automatically implemented by the __using__ macro.

Link to this section Callbacks

Link to this callback

occupation_timeout()

@callback occupation_timeout() :: pos_integer()

In milliseconds, how long after movement is no longer detected do we flip the state to unoccupied

@callback pin() :: pos_integer()

GPIO Pin to which the sensor is attached

Link to this callback

set_occupied(occupied?, timestamp)

@callback set_occupied(occupied? :: boolean(), timestamp :: DateTime.t()) :: :ok

Automatically implemented by the __using__ macro.

Sets the occupation status. Provided for setting on reboot if the client has persisted the status somewhere. The status will be broadcast to all subscribers