1
- // DHT Temperature & Humidity Unified Sensor Library
2
- // Copyright (c) 2014 Adafruit Industries
3
- // Author: Tony DiCola
4
-
5
- // Permission is hereby granted, free of charge, to any person obtaining a copy
6
- // of this software and associated documentation files (the "Software"), to deal
7
- // in the Software without restriction, including without limitation the rights
8
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- // copies of the Software, and to permit persons to whom the Software is
10
- // furnished to do so, subject to the following conditions:
11
-
12
- // The above copyright notice and this permission notice shall be included in all
13
- // copies or substantial portions of the Software.
14
-
15
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- // SOFTWARE.
1
+ /* !
2
+ * @file DHT_U.cpp
3
+ *
4
+ * Temperature & Humidity Unified Sensor Library
5
+ *
6
+ * This is a library for DHT series of low cost temperature/humidity sensors.
7
+ *
8
+ * You must have Adafruit Unified Sensor Library library installed to use this
9
+ * class.
10
+ *
11
+ * Adafruit invests time and resources providing this open source code,
12
+ * please support Adafruit andopen-source hardware by purchasing products
13
+ * from Adafruit!
14
+ */
22
15
#include " DHT_U.h"
23
16
17
+ /* !
18
+ * @brief Instantiates a new DHT_Unified class
19
+ * @param pin
20
+ * pin number that sensor is connected
21
+ * @param type
22
+ * type of sensor
23
+ * @param count
24
+ * number of sensors
25
+ * @param tempSensorId
26
+ * temperature sensor id
27
+ * @param humiditySensorId
28
+ * humidity sensor id
29
+ */
24
30
DHT_Unified::DHT_Unified (uint8_t pin, uint8_t type, uint8_t count, int32_t tempSensorId, int32_t humiditySensorId):
25
31
_dht(pin, type, count),
26
32
_type(type),
27
33
_temp(this , tempSensorId),
28
34
_humidity(this , humiditySensorId)
29
35
{}
30
36
37
+ /* !
38
+ * @brief Setup sensor (calls begin on It)
39
+ */
31
40
void DHT_Unified::begin () {
32
41
_dht.begin ();
33
42
}
34
43
44
+ /* !
45
+ * @brief Sets sensor name
46
+ * @param sensor
47
+ * Sensor that will be set
48
+ */
35
49
void DHT_Unified::setName (sensor_t * sensor) {
36
50
switch (_type) {
37
51
case DHT11:
@@ -55,6 +69,11 @@ void DHT_Unified::setName(sensor_t* sensor) {
55
69
sensor->name [sizeof (sensor->name )- 1 ] = 0 ;
56
70
}
57
71
72
+ /* !
73
+ * @brief Sets Minimum Delay Value
74
+ * @param sensor
75
+ * Sensor that will be set
76
+ */
58
77
void DHT_Unified::setMinDelay (sensor_t * sensor) {
59
78
switch (_type) {
60
79
case DHT11:
@@ -76,11 +95,23 @@ void DHT_Unified::setMinDelay(sensor_t* sensor) {
76
95
}
77
96
}
78
97
98
+ /* !
99
+ * @brief Instantiates a new DHT_Unified Temperature Class
100
+ * @param parent
101
+ * Parent Sensor
102
+ * @param id
103
+ * Sensor id
104
+ */
79
105
DHT_Unified::Temperature::Temperature (DHT_Unified* parent, int32_t id):
80
106
_parent(parent),
81
107
_id(id)
82
108
{}
83
109
110
+ /* !
111
+ * @brief Reads the sensor and returns the data as a sensors_event_t
112
+ * @param event
113
+ * @return always returns true
114
+ */
84
115
bool DHT_Unified::Temperature::getEvent (sensors_event_t * event) {
85
116
// Clear event definition.
86
117
memset (event, 0 , sizeof (sensors_event_t ));
@@ -94,6 +125,10 @@ bool DHT_Unified::Temperature::getEvent(sensors_event_t* event) {
94
125
return true ;
95
126
}
96
127
128
+ /* !
129
+ * @brief Provides the sensor_t data for this sensor
130
+ * @param sensor
131
+ */
97
132
void DHT_Unified::Temperature::getSensor (sensor_t * sensor) {
98
133
// Clear sensor definition.
99
134
memset (sensor, 0 , sizeof (sensor_t ));
@@ -135,11 +170,23 @@ void DHT_Unified::Temperature::getSensor(sensor_t* sensor) {
135
170
}
136
171
}
137
172
173
+ /* !
174
+ * @brief Instantiates a new DHT_Unified Humidity Class
175
+ * @param parent
176
+ * Parent Sensor
177
+ * @param id
178
+ * Sensor id
179
+ */
138
180
DHT_Unified::Humidity::Humidity (DHT_Unified* parent, int32_t id):
139
181
_parent(parent),
140
182
_id(id)
141
183
{}
142
184
185
+ /* !
186
+ * @brief Reads the sensor and returns the data as a sensors_event_t
187
+ * @param event
188
+ * @return always returns true
189
+ */
143
190
bool DHT_Unified::Humidity::getEvent (sensors_event_t * event) {
144
191
// Clear event definition.
145
192
memset (event, 0 , sizeof (sensors_event_t ));
@@ -153,6 +200,10 @@ bool DHT_Unified::Humidity::getEvent(sensors_event_t* event) {
153
200
return true ;
154
201
}
155
202
203
+ /* !
204
+ * @brief Provides the sensor_t data for this sensor
205
+ * @param sensor
206
+ */
156
207
void DHT_Unified::Humidity::getSensor (sensor_t * sensor) {
157
208
// Clear sensor definition.
158
209
memset (sensor, 0 , sizeof (sensor_t ));
0 commit comments