Loading...
Searching...
No Matches
PIR Motion Sensor

Device driver interface for the PIR motion sensor. More...

Detailed Description

Device driver interface for the PIR motion sensor.

Modules

 PIR Motion Sensor driver compile configuration
 

Files

file  pir.h
 Device driver interface for the PIR motion sensor.
 
file  pir_params.h
 Default configuration for PIR devices.
 

Data Structures

struct  pir_params_t
 Parameters needed for device initialization. More...
 
struct  pir_t
 device descriptor for a PIR sensor More...
 

Enumerations

enum  { PIR_OK = 0 , PIR_NOGPIO = -1 , PIR_NOTHREAD = -2 , PIR_TIMEERR = -3 }
 PIR specific return values. More...
 
enum  pir_event_t { PIR_STATUS_ACTIVE = PIR_MSG_T_STATUS_START , PIR_STATUS_INACTIVE }
 event type for a PIR sensor More...
 

Functions

int pir_init (pir_t *dev, const pir_params_t *params)
 Initialize a PIR motion sensor.
 
pir_event_t pir_get_status (const pir_t *dev)
 Read the current status of the motion sensor.
 
int pir_get_occupancy (pir_t *dev, int16_t *occup)
 Read OCCUPANCY value.
 
int pir_register_thread (pir_t *dev)
 Register a thread for notification when state changes on the motion sensor.
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

PIR specific return values.

Enumerator
PIR_OK 

everything went as expected

PIR_NOGPIO 

errors while initializing the GPIO

PIR_NOTHREAD 

errors while registering the thread

PIR_TIMEERR 

errors while getting the time information

Definition at line 36 of file pir.h.

◆ pir_event_t

event type for a PIR sensor

Enumerator
PIR_STATUS_ACTIVE 

motion was detected

PIR_STATUS_INACTIVE 

no motion is detected

Definition at line 79 of file pir.h.

Function Documentation

◆ pir_get_occupancy()

int pir_get_occupancy ( pir_t dev,
int16_t *  occup 
)

Read OCCUPANCY value.

Parameters
[in]devdevice descriptor of the PIR motion sensor to read from
[out]occupoccupancy ratio [in 100 * percentage] The value is renewed when it is read. So it is percentage of occupancy since the last read.
Returns
0 on success,
-1 on errors,

◆ pir_get_status()

pir_event_t pir_get_status ( const pir_t dev)

Read the current status of the motion sensor.

Parameters
[in]devdevice descriptor of the PIR motion sensor to read from
Returns
1 if motion is detected, 0 otherwise

◆ pir_init()

int pir_init ( pir_t dev,
const pir_params_t params 
)

Initialize a PIR motion sensor.

The PIR motion sensor is interfaced by a single GPIO pin, specified by gpio.

Note
The sensor needs up to a minute to settle down before meaningful measurements can be made.
Parameters
[out]devdevice descriptor of an PIR sensor
[in]paramsparameters of the PIR sensor
Returns
0 on success
-1 on error

◆ pir_register_thread()

int pir_register_thread ( pir_t dev)

Register a thread for notification when state changes on the motion sensor.

Note
This configures the gpio device for interrupt driven operation.
Parameters
[in]devdevice descriptor of the PIR motion sensor to register for
Returns
0 on succuess,
-1 on internal errors,
-2 if another thread is registered already