11//
22// FILE: DHT2pin.cpp
33// AUTHOR: Rob Tillaart
4- // VERSION: 0.1.2
4+ // VERSION: 0.1.3
55// PURPOSE: Experimental DHT Temperature & Humidity Sensor library for Arduino
66// URL: https://github.com/RobTillaart/DHT2pin
77// http://arduino.cc/playground/Main/DHTLib
88//
9- // HISTORY:
10- // 0.1.2 2021-12-16 update library.json, license, minor edits
11- // 0.1.1 2020-12-19 added arduino-ci + unit test
12- // 0.1.0 2020-06-30 own repository; #pragma once
13- // 0.0.3 Fix issue #33
14- // 0.0.2 support for non "F_CPU" boards especially Galileo
15- // Tested and verified by Maria Emanuella Moura Silva (thanks)
16- // changed name to DHT2pin
17- // 0.0.1 initial version - 2016 SEP 05 (based upon 0.1.13 DHT)
18- //
9+ // HISTORY: see changelog.md
10+
1911
2012#include " DHT2pin.h"
2113
14+
2215// ///////////////////////////////////////////////////
2316//
24- // PUBLIC
17+ // PUBLIC
2518//
2619
27- // return values:
28- // DHTLIB_OK
29- // DHTLIB_ERROR_CHECKSUM
30- // DHTLIB_ERROR_TIMEOUT
20+ // return values:
21+ // DHTLIB_OK
22+ // DHTLIB_ERROR_CHECKSUM
23+ // DHTLIB_ERROR_TIMEOUT
3124int DHT2pin::read11 ()
3225{
33- // READ VALUES
26+ // READ VALUES
3427 int rv = _readSensor (DHTLIB_DHT11_WAKEUP);
3528 if (rv != DHTLIB_OK)
3629 {
@@ -39,38 +32,38 @@ int DHT2pin::read11()
3932 return rv;
4033 }
4134
42- // CONVERT AND STORE
35+ // CONVERT AND STORE
4336 humidity = bits[0 ]; // bits[1] == 0;
4437 temperature = bits[2 ]; // bits[3] == 0;
4538
46- // TEST CHECKSUM
47- // bits[1] && bits[3] both 0
39+ // TEST CHECKSUM
40+ // bits[1] && bits[3] both 0
4841 uint8_t sum = bits[0 ] + bits[2 ];
4942 if (bits[4 ] != sum) return DHTLIB_ERROR_CHECKSUM;
5043
5144 return DHTLIB_OK;
5245}
5346
5447
55- // return values:
56- // DHTLIB_OK
57- // DHTLIB_ERROR_CHECKSUM
58- // DHTLIB_ERROR_TIMEOUT
48+ // return values:
49+ // DHTLIB_OK
50+ // DHTLIB_ERROR_CHECKSUM
51+ // DHTLIB_ERROR_TIMEOUT
5952int DHT2pin::read ()
6053{
61- // READ VALUES
54+ // READ VALUES
6255 int rv = _readSensor (DHTLIB_DHT_WAKEUP);
6356 if (rv != DHTLIB_OK)
6457 {
65- humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered?
66- temperature = DHTLIB_INVALID_VALUE; // invalid value
67- return rv; // propagate error value
58+ humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered?
59+ temperature = DHTLIB_INVALID_VALUE; // invalid value
60+ return rv; // propagate error value
6861 }
6962
70- // CONVERT AND STORE
63+ // CONVERT AND STORE
7164 humidity = word (bits[0 ], bits[1 ]) * 0.1 ;
7265 temperature = word (bits[2 ] & 0x7F , bits[3 ]) * 0.1 ;
73- if (bits[2 ] & 0x80 ) // negative temperature
66+ if (bits[2 ] & 0x80 ) // negative temperature
7467 {
7568 temperature = -temperature;
7669 }
@@ -86,28 +79,28 @@ int DHT2pin::read()
8679
8780// ///////////////////////////////////////////////////
8881//
89- // PRIVATE
82+ // PRIVATE
9083//
9184
92- // return values:
93- // DHTLIB_OK
94- // DHTLIB_ERROR_TIMEOUT
85+ // return values:
86+ // DHTLIB_OK
87+ // DHTLIB_ERROR_TIMEOUT
9588int DHT2pin::_readSensor (uint8_t wakeupDelay)
9689{
97- // INIT BUFFERVAR TO RECEIVE DATA
90+ // INIT BUFFERVAR TO RECEIVE DATA
9891 uint8_t mask = 128 ;
9992 uint8_t idx = 0 ;
10093
101- // EMPTY BUFFER
94+ // EMPTY BUFFER
10295 for (uint8_t i = 0 ; i < 5 ; i++) bits[i] = 0 ;
10396
104- // REQUEST SAMPLE
97+ // REQUEST SAMPLE
10598 digitalWrite (_wpin, LOW);
10699 delay (wakeupDelay);
107100 digitalWrite (_wpin, HIGH);
108101 delayMicroseconds (40 );
109102
110- // GET ACKNOWLEDGE or TIMEOUT
103+ // GET ACKNOWLEDGE or TIMEOUT
111104 uint16_t loopCnt = DHTLIB_TIMEOUT;
112105 while (digitalRead (_rpin) == LOW)
113106 {
@@ -152,6 +145,7 @@ int DHT2pin::_readSensor(uint8_t wakeupDelay)
152145
153146 return DHTLIB_OK;
154147}
155- //
156- // END OF FILE
157- //
148+
149+
150+ // -- END OF FILE --
151+
0 commit comments