HcSr501Occupation.MovementSensor behaviour (hc_sr_501_occupation v0.1.3)
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
Implemented by the __using__
macro.
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
Implemented by the __using__
macro.
Link to this section Callbacks
occupation()
@callback occupation() :: {occupied? :: boolean(), timestamp :: DateTime.t()}
Implemented by the __using__
macro.
The current occupation status: occupied or not and the last occupation event.
occupation_timeout()
@callback occupation_timeout() :: pos_integer()
In milliseconds, how long after movement is no longer detected do we flip the state to unoccupied
pin()
@callback pin() :: pos_integer()
GPIO Pin to which the sensor is attached
set_occupied(occupied?, timestamp)
@callback set_occupied(occupied? :: boolean(), timestamp :: DateTime.t()) :: :ok
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