Implement correct conversion of humidity for SHT4x

The conversion of humidity from raw value is different for the SHT4x
series. The fix implements the conversion as per datasheet. Also, the
raw value is now cast to float before division.
This commit is contained in:
Stefan Tibus 2022-06-05 00:54:10 +02:00
parent 37e1bc6e7d
commit 0ddcaa8fe7
1 changed files with 6 additions and 2 deletions

View File

@ -104,8 +104,12 @@ bool Sht3xRead(uint32_t type, float &t, float &h, uint8_t i2c_address) {
if ((Sht3xComputeCrc(&data[0], 2) != data[2]) || (Sht3xComputeCrc(&data[3], 2) != data[5])) {
return false;
}
t = (float)((((data[0] << 8) | data[1]) * 175) / 65535.0) - 45;
h = (float)((((data[3] << 8) | data[4]) * 100) / 65535.0);
t = ((float)(((data[0] << 8) | data[1]) * 175) / 65535.0) - 45.0;
if (type == SHT3X_TYPE_SHT4X) {
h = ((float)(((data[3] << 8) | data[4]) * 125) / 65535.0) - 6.0;
} else {
h = ((float)(((data[3] << 8) | data[4]) * 100) / 65535.0);
}
return (!isnan(t) && !isnan(h));
}