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 
9 #pragma once
10 
24 #include "sched.h"
25 #include "periph/gpio.h"
26 #include "stdbool.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
35 enum {
36  PIR_OK = 0,
37  PIR_NOGPIO = -1,
38  PIR_NOTHREAD = -2,
39  PIR_TIMEERR = -3,
40 };
41 
45 typedef struct {
46  gpio_t gpio;
47  bool active_high;
48 } pir_params_t;
49 
53 typedef struct {
54  uint64_t start_active_time;
55  uint64_t accum_active_time;
56  uint64_t last_read_time;
58  bool active;
60 } pir_t;
61 
70 #ifndef PIR_MSG_T_STATUS_START
71 #define PIR_MSG_T_STATUS_START 150
72 #endif
78 typedef enum {
81 } pir_event_t;
82 
99 int pir_init(pir_t *dev, const pir_params_t* params);
100 
109 
121 int pir_get_occupancy(pir_t *dev, int16_t *occup);
122 
138 
139 #ifdef __cplusplus
140 }
141 #endif
142 
Low-level GPIO peripheral driver interface definitions.
int16_t kernel_pid_t
Unique process identifier.
Definition: sched.h:138
#define PIR_MSG_T_STATUS_START
Sensitivity of sensor.
Definition: pir.h:71
int pir_get_occupancy(pir_t *dev, int16_t *occup)
Read OCCUPANCY value.
pir_event_t pir_get_status(const pir_t *dev)
Read the current status of the motion sensor.
int pir_register_thread(pir_t *dev)
Register a thread for notification when state changes on the motion sensor.
int pir_init(pir_t *dev, const pir_params_t *params)
Initialize a PIR motion sensor.
pir_event_t
event type for a PIR sensor
Definition: pir.h:78
@ PIR_TIMEERR
errors while getting the time information
Definition: pir.h:39
@ PIR_OK
everything went as expected
Definition: pir.h:36
@ PIR_NOTHREAD
errors while registering the thread
Definition: pir.h:38
@ PIR_NOGPIO
errors while initializing the GPIO
Definition: pir.h:37
@ PIR_STATUS_INACTIVE
no motion is detected
Definition: pir.h:80
@ PIR_STATUS_ACTIVE
motion was detected
Definition: pir.h:79
Scheduler API definition.
Parameters needed for device initialization.
Definition: pir.h:45
bool active_high
Active when GPIO pin is high or not.
Definition: pir.h:47
gpio_t gpio
GPIO device which is used.
Definition: pir.h:46
device descriptor for a PIR sensor
Definition: pir.h:53
uint64_t start_active_time
Time when PIR starts to be active.
Definition: pir.h:54
kernel_pid_t msg_thread_pid
thread to msg on irq
Definition: pir.h:57
uint64_t accum_active_time
Accumulated active time.
Definition: pir.h:55
bool active
Indicate PIR is active or not.
Definition: pir.h:58
uint64_t last_read_time
Last time when PIR status is read.
Definition: pir.h:56
pir_params_t p
Configuration parameters.
Definition: pir.h:59