MCPcopy Create free account
hub / github.com/WiringPi/WiringPi / myReadRHT03

Function myReadRHT03

wiringPi/rht03.c:175–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

173 */
174
175static int myReadRHT03 (const int pin, int *temp, int *rh)
176{
177 int result ;
178 unsigned char buffer [4] ;
179
180// Read ...
181
182 result = maxDetectRead (pin, buffer) ;
183
184 if (!result)
185 return false ;
186
187 *rh = (buffer [0] * 256 + buffer [1]) ;
188 *temp = (buffer [2] * 256 + buffer [3]) ;
189
190 if ((*temp & 0x8000) != 0) // Negative
191 {
192 *temp &= 0x7FFF ;
193 *temp = -*temp ;
194 }
195
196// Discard obviously bogus readings - the checksum can't detect a 2-bit error
197// (which does seem to happen - no realtime here)
198
199 if ((*rh > 999) || (*temp > 800) || (*temp < -400))
200 return false ;
201
202 return true ;
203}
204
205
206/*

Callers 1

myAnalogReadFunction · 0.85

Calls 1

maxDetectReadFunction · 0.70

Tested by

no test coverage detected