return values: DHTLIB_OK DHTLIB_ERROR_CHECKSUM DHTLIB_ERROR_TIMEOUT
| 71 | // DHTLIB_ERROR_CHECKSUM |
| 72 | // DHTLIB_ERROR_TIMEOUT |
| 73 | int DHTStable::read11(uint8_t pin) |
| 74 | { |
| 75 | // READ VALUES |
| 76 | if (_disableIRQ) noInterrupts(); |
| 77 | int rv = _readSensor(pin, DHTLIB_DHT11_WAKEUP); |
| 78 | if (_disableIRQ) interrupts(); |
| 79 | if (rv != DHTLIB_OK) |
| 80 | { |
| 81 | _humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered? |
| 82 | _temperature = DHTLIB_INVALID_VALUE; // invalid value |
| 83 | return rv; |
| 84 | } |
| 85 | |
| 86 | // CONVERT AND STORE |
| 87 | _humidity = _bits[0] + _bits[1] * 0.1; |
| 88 | _temperature = (_bits[2] & 0x7F) + _bits[3] * 0.1; |
| 89 | if (_bits[2] & 0x80) // negative temperature |
| 90 | { |
| 91 | _temperature = -_temperature; |
| 92 | } |
| 93 | |
| 94 | // TEST CHECKSUM |
| 95 | uint8_t sum = _bits[0] + _bits[1] + _bits[2] + _bits[3]; |
| 96 | if (_bits[4] != sum) |
| 97 | { |
| 98 | return DHTLIB_ERROR_CHECKSUM; |
| 99 | } |
| 100 | return DHTLIB_OK; |
| 101 | } |
| 102 | |
| 103 | |
| 104 | // return values: |