PIR Motion Sensor¶
Device driver interface for the PIR motion sensor.
-
enum
@151
¶ - PIR_OK
= 0
- everything went as expected
- PIR_NOGPIO
= -1
- errors while initializing the GPIO
- PIR_NOTHREAD
= -2
- errors while registering the thread
- PIR_TIMEERR
= -3
- errors while getting the time information
- PIR_OK
-
enum
pir_event_t
¶ - PIR_STATUS_ACTIVE
= PIR_MSG_T_STATUS_START
- motion was detected
- PIR_STATUS_INACTIVE
- no motion is detected
- PIR_STATUS_ACTIVE
-
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
dev: device descriptor of an PIR sensor params: parameters of the PIR sensor Return values
- 0 on success
- -1 on error
-
pir.h::pir_event_t
pir_get_status
(const pir_t * dev)¶ Read the current status of the motion sensor.
Parameters
dev: device descriptor of the PIR motion sensor to read from Return values
- 1 if motion is detected, 0 otherwise
-
int
pir_get_occupancy
(pir_t * dev, int16_t * occup)¶ Read OCCUPANCY value.
Parameters
dev: device descriptor of the PIR motion sensor to read from occup: occupancy ratio [in 100 * percentage] The value is renewed when it is read. So it is percentage of occupancy since the last read. Return values
- 0 on success,
- -1 on errors,
-
int
pir_register_thread
(pir_t * dev)¶ Register a thread for notification whan state changes on the motion sensor.
Note
This configures the gpio device for interrupt driven operation.
Parameters
dev: device descriptor of the PIR motion sensor to register for Return values
- 0 on succuess,
- -1 on internal errors,
- -2 if another thread is registered already
-
PIR_MSG_T_STATUS_START
¶ value to configure sensitivity of sensore
1
150
-
struct
pir_params_t
¶ Parameters needed for device initialization.
-
gpio.h::gpio_t
gpio
¶ GPIO device which is used.
-
bool
active_high
¶ Active when GPIO pin is high or not.
-
-
struct
pir_t
¶ device descriptor for a PIR sensor
-
uint64_t
start_active_time
¶ Time when PIR starts to be active.
-
uint64_t
accum_active_time
¶ Accumulated active time.
-
uint64_t
last_read_time
¶ Last time when PIR status is read.
-
kernel_types.h::kernel_pid_t
msg_thread_pid
¶ thread to msg on irq
-
bool
active
¶ Indicate PIR is active or not.
-
pir_params_t
p
¶ Configuration parameters.
-
uint64_t