| 173 | */ |
| 174 | |
| 175 | static 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 | /* |
no test coverage detected