@@ -24,14 +24,6 @@ SOFTWARE.
2424
2525#include " SimpleDHT.h"
2626
27- int SimpleDHT::ErrSuccess = 0 ;
28- int SimpleDHT::ErrStartLow = 100 ;
29- int SimpleDHT::ErrStartHigh = 101 ;
30- int SimpleDHT::ErrDataLow = 102 ;
31- int SimpleDHT::ErrDataRead = 103 ;
32- int SimpleDHT::ErrDataEOF = 104 ;
33- int SimpleDHT::ErrDataChecksum = 105 ;
34-
3527int SimpleDHT::confirm (int pin, int us, byte level) {
3628 // wait one more count to ensure.
3729 int cnt = us / 10 + 1 ;
@@ -48,7 +40,7 @@ int SimpleDHT::confirm(int pin, int us, byte level) {
4840 if (!ok) {
4941 return -1 ;
5042 }
51- return ErrSuccess ;
43+ return SimpleDHTErrSuccess ;
5244}
5345
5446byte SimpleDHT::bits2byte (byte data[8 ]) {
@@ -67,24 +59,24 @@ int SimpleDHT::parse(byte data[40], byte* ptemperature, byte* phumidity) {
6759 byte check = bits2byte (data + 32 );
6860 byte expect = humidity + humidity2 + temperature + temperature2;
6961 if (check != expect) {
70- return ErrDataChecksum ;
62+ return SimpleDHTErrDataChecksum ;
7163 }
7264 *ptemperature = temperature;
7365 *phumidity = humidity;
74- return ErrSuccess ;
66+ return SimpleDHTErrSuccess ;
7567}
7668
7769int SimpleDHT::read (int pin, byte* ptemperature, byte* phumidity, byte pdata[40 ]) {
78- int ret = ErrSuccess ;
70+ int ret = SimpleDHTErrSuccess ;
7971
8072 byte data[40 ] = {0 };
81- if ((ret = sample (pin, data)) != ErrSuccess ) {
73+ if ((ret = sample (pin, data)) != SimpleDHTErrSuccess ) {
8274 return ret;
8375 }
8476
8577 byte temperature = 0 ;
8678 byte humidity = 0 ;
87- if ((ret = parse (data, &temperature, &humidity)) != ErrSuccess ) {
79+ if ((ret = parse (data, &temperature, &humidity)) != SimpleDHTErrSuccess ) {
8880 return ret;
8981 }
9082
@@ -120,10 +112,10 @@ int SimpleDHT11::sample(int pin, byte data[40]) {
120112 // 1. PULL LOW 80us
121113 // 2. PULL HIGH 80us
122114 if (confirm (pin, 80 , LOW)) {
123- return ErrStartLow ;
115+ return SimpleDHTErrStartLow ;
124116 }
125117 if (confirm (pin, 80 , HIGH)) {
126- return ErrStartHigh ;
118+ return SimpleDHTErrStartHigh ;
127119 }
128120
129121 // DHT11 data transmite:
@@ -132,7 +124,7 @@ int SimpleDHT11::sample(int pin, byte data[40]) {
132124 // 3. PULL HIGH 70us, bit(1)
133125 for (int j = 0 ; j < 40 ; j++) {
134126 if (confirm (pin, 50 , LOW)) {
135- return ErrDataLow ;
127+ return SimpleDHTErrDataLow ;
136128 }
137129
138130 // read a bit, should never call method,
@@ -148,18 +140,18 @@ int SimpleDHT11::sample(int pin, byte data[40]) {
148140 delayMicroseconds (10 );
149141 }
150142 if (!ok) {
151- return ErrDataRead ;
143+ return SimpleDHTErrDataRead ;
152144 }
153145 data[j] = (tick > 3 ? 1 :0 );
154146 }
155147
156148 // DHT11 EOF:
157149 // 1. PULL LOW 50us.
158150 if (confirm (pin, 50 , LOW)) {
159- return ErrDataEOF ;
151+ return SimpleDHTErrDataEOF ;
160152 }
161153
162- return ErrSuccess ;
154+ return SimpleDHTErrSuccess ;
163155}
164156
165157int SimpleDHT22::sample (int pin, byte data[40 ]) {
@@ -181,10 +173,10 @@ int SimpleDHT22::sample(int pin, byte data[40]) {
181173 // 1. PULL LOW 80us
182174 // 2. PULL HIGH 80us
183175 if (confirm (pin, 80 , LOW)) {
184- return ErrStartLow ;
176+ return SimpleDHTErrStartLow ;
185177 }
186178 if (confirm (pin, 80 , HIGH)) {
187- return ErrStartHigh ;
179+ return SimpleDHTErrStartHigh ;
188180 }
189181
190182 // DHT11 data transmite:
@@ -193,7 +185,7 @@ int SimpleDHT22::sample(int pin, byte data[40]) {
193185 // 3. PULL HIGH 70us, bit(1)
194186 for (int j = 0 ; j < 40 ; j++) {
195187 if (confirm (pin, 50 , LOW)) {
196- return ErrDataLow ;
188+ return SimpleDHTErrDataLow ;
197189 }
198190
199191 // read a bit, should never call method,
@@ -209,17 +201,17 @@ int SimpleDHT22::sample(int pin, byte data[40]) {
209201 delayMicroseconds (10 );
210202 }
211203 if (!ok) {
212- return ErrDataRead ;
204+ return SimpleDHTErrDataRead ;
213205 }
214206 data[j] = (tick > 3 ? 1 :0 );
215207 }
216208
217209 // DHT11 EOF:
218210 // 1. PULL LOW 50us.
219211 if (confirm (pin, 50 , LOW)) {
220- return ErrDataEOF ;
212+ return SimpleDHTErrDataEOF ;
221213 }
222214
223- return ErrSuccess ;
215+ return SimpleDHTErrSuccess ;
224216}
225217
0 commit comments