negative values for all DHT22 variants (#6074)

Co-authored-by: Samuel Sieb <samuel@sieb.net>
This commit is contained in:
Samuel Sieb 2024-01-12 01:20:08 -08:00 committed by Keith Burzinski
parent a6f864a4a3
commit 2cda6462f3
No known key found for this signature in database
GPG key ID: 802564C5F0EEFFBE

View file

@ -217,8 +217,12 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r
uint16_t raw_humidity = (uint16_t(data[0] & 0xFF) << 8) | (data[1] & 0xFF); uint16_t raw_humidity = (uint16_t(data[0] & 0xFF) << 8) | (data[1] & 0xFF);
uint16_t raw_temperature = (uint16_t(data[2] & 0xFF) << 8) | (data[3] & 0xFF); uint16_t raw_temperature = (uint16_t(data[2] & 0xFF) << 8) | (data[3] & 0xFF);
if (this->model_ != DHT_MODEL_DHT22_TYPE2 && (raw_temperature & 0x8000) != 0) if (raw_temperature & 0x8000) {
if (!(raw_temperature & 0x4000))
raw_temperature = ~(raw_temperature & 0x7FFF); raw_temperature = ~(raw_temperature & 0x7FFF);
} else if (raw_temperature & 0x800) {
raw_temperature |= 0xf000;
}
if (raw_temperature == 1 && raw_humidity == 10) { if (raw_temperature == 1 && raw_humidity == 10) {
if (report_errors) { if (report_errors) {