pir.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
22 #ifndef PIR_H
23 #define PIR_H
24 
25 #include "sched.h"
26 #include "periph/gpio.h"
27 #include "stdbool.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
36 enum {
37  PIR_OK = 0,
38  PIR_NOGPIO = -1,
39  PIR_NOTHREAD = -2,
40  PIR_TIMEERR = -3,
41 };
42 
46 typedef struct {
47  gpio_t gpio;
48  bool active_high;
49 } pir_params_t;
50 
51 
55 typedef struct {
56  uint64_t start_active_time;
57  uint64_t accum_active_time;
58  uint64_t last_read_time;
60  bool active;
62 } pir_t;
63 
72 #ifndef PIR_MSG_T_STATUS_START
73 #define PIR_MSG_T_STATUS_START 150
74 #endif
75 
80 typedef enum {
83 } pir_event_t;
84 
101 int pir_init(pir_t *dev, const pir_params_t* params);
102 
110 pir_event_t pir_get_status(const pir_t *dev);
111 
123 int pir_get_occupancy(pir_t *dev, int16_t *occup);
124 
139 int pir_register_thread(pir_t *dev);
140 
141 #ifdef __cplusplus
142 }
143 #endif
144 
145 #endif /* PIR_H */
146 
pir_init
int pir_init(pir_t *dev, const pir_params_t *params)
Initialize a PIR motion sensor.
PIR_NOGPIO
@ PIR_NOGPIO
errors while initializing the GPIO
Definition: pir.h:38
pir_t
device descriptor for a PIR sensor
Definition: pir.h:55
kernel_pid_t
int16_t kernel_pid_t
Unique process identifier.
Definition: sched.h:125
PIR_STATUS_INACTIVE
@ PIR_STATUS_INACTIVE
no motion is detected
Definition: pir.h:82
PIR_STATUS_ACTIVE
@ PIR_STATUS_ACTIVE
motion was detected
Definition: pir.h:81
pir_t::p
pir_params_t p
Configuration parameters.
Definition: pir.h:61
PIR_NOTHREAD
@ PIR_NOTHREAD
errors while registering the thread
Definition: pir.h:39
PIR_MSG_T_STATUS_START
#define PIR_MSG_T_STATUS_START
Sensitivity of sensor.
Definition: pir.h:73
PIR_TIMEERR
@ PIR_TIMEERR
errors while getting the time information
Definition: pir.h:40
sched.h
Scheduler API definition.
pir_register_thread
int pir_register_thread(pir_t *dev)
Register a thread for notification when state changes on the motion sensor.
pir_t::msg_thread_pid
kernel_pid_t msg_thread_pid
thread to msg on irq
Definition: pir.h:59
PIR_OK
@ PIR_OK
everything went as expected
Definition: pir.h:37
pir_t::active
bool active
Indicate PIR is active or not.
Definition: pir.h:60
pir_params_t
Parameters needed for device initialization.
Definition: pir.h:46
pir_t::last_read_time
uint64_t last_read_time
Last time when PIR status is read.
Definition: pir.h:58
pir_get_status
pir_event_t pir_get_status(const pir_t *dev)
Read the current status of the motion sensor.
pir_event_t
pir_event_t
event type for a PIR sensor
Definition: pir.h:80
pir_get_occupancy
int pir_get_occupancy(pir_t *dev, int16_t *occup)
Read OCCUPANCY value.
pir_params_t::gpio
gpio_t gpio
GPIO device which is used.
Definition: pir.h:47
gpio.h
Low-level GPIO peripheral driver interface definitions.
pir_t::start_active_time
uint64_t start_active_time
Time when PIR starts to be active.
Definition: pir.h:56
pir_params_t::active_high
bool active_high
Active when GPIO pin is high or not.
Definition: pir.h:48
pir_t::accum_active_time
uint64_t accum_active_time
Accumulated active time.
Definition: pir.h:57