pir.h
2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* Copyright (C) 2014 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup drivers_pir PIR Motion Sensor
* @ingroup drivers_sensors
* @brief Device driver interface for the PIR motion sensor
* @{
*
* @file
* @brief Device driver interface for the PIR motion sensor
*
* @author Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de>
*/
#ifndef PIR_H
#define PIR_H
#include "kernel_types.h"
#include "periph/gpio.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief device descriptor for a PIR sensor
*/
typedef struct {
gpio_t gpio_dev; /**< GPIO device which is used */
kernel_pid_t msg_thread_pid; /**< thread to msg on irq */
} pir_t;
/**
* @brief value to configure sensitivity of sensore
*/
#ifndef PIR_MSG_T_STATUS_START
#define PIR_MSG_T_STATUS_START 150
#endif
/**
* @brief event type for a PIR sensor
*/
typedef enum {
PIR_STATUS_HI = PIR_MSG_T_STATUS_START, /**< motion was detected */
PIR_STATUS_LO, /**< no motion is detected */
} pir_event_t;
/**
* @brief 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.
*
* @param[out] dev device descriptor of an PIR sensor
* @param[in] gpio the GPIO device the sensor is connected to
*
* @return 0 on success
* @return -1 on error
*/
int pir_init(pir_t *dev, gpio_t gpio);
/**
* @brief Read the current status of the motion sensor
*
* @param[in] dev device descriptor of the PIR motion sensor to read from
*
* @return 1 if motion is detected, 0 otherwise
*/
pir_event_t pir_get_status(const pir_t *dev);
/**
* @brief Register a thread for notification whan state changes on the
* motion sensor.
*
* @note
* This configures the gpio device for interrupt driven operation.
*
* @param[in] dev device descriptor of the PIR motion sensor to
* register for
*
* @return 0 on succuess,
* @return -1 on internal errors,
* @return -2 if another thread is registered already
*/
int pir_register_thread(pir_t *dev);
#ifdef __cplusplus
}
#endif
#endif /* PIR_H */
/** @} */