return values: DHTLIB_OK DHTLIB_ERROR_CHECKSUM DHTLIB_ERROR_TIMEOUT
| 38 | // DHTLIB_ERROR_CHECKSUM |
| 39 | // DHTLIB_ERROR_TIMEOUT |
| 40 | int dht::read11(uint8_t pin) |
| 41 | { |
| 42 | // READ VALUES |
| 43 | int rv = _readSensor(pin, DHTLIB_DHT11_WAKEUP); |
| 44 | if (rv != DHTLIB_OK) |
| 45 | { |
| 46 | humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered? |
| 47 | temperature = DHTLIB_INVALID_VALUE; // invalid value |
| 48 | return rv; |
| 49 | } |
| 50 | |
| 51 | // CONVERT AND STORE |
| 52 | humidity = bits[0]; // bits[1] == 0; |
| 53 | temperature = bits[2]; // bits[3] == 0; |
| 54 | |
| 55 | // TEST CHECKSUM |
| 56 | // bits[1] && bits[3] both 0 |
| 57 | uint8_t sum = bits[0] + bits[2]; |
| 58 | if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM; |
| 59 | |
| 60 | return DHTLIB_OK; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | // return values: |