mirror of https://github.com/arendst/Tasmota.git
xsns_14_sht3x.ino - data types adjusted, code size reduced (#21868)
* code size, data type improvements * Change temp calculation to int
This commit is contained in:
parent
b4a0e27852
commit
4101ad7303
|
@ -106,16 +106,15 @@ bool Sht3xRead(uint32_t sensor) {
|
|||
if ((Sht3xComputeCrc(&data[0], 2) != data[2]) || (Sht3xComputeCrc(&data[3], 2) != data[5])) {
|
||||
return false;
|
||||
}
|
||||
float t;
|
||||
float h;
|
||||
t = ((((data[0] << 8) | data[1]) * 175) / 65535.0) - 45.0;
|
||||
int32_t t_100 = ((((data[0] << 8) | data[1]) * 17500) >> 16) - 4500;
|
||||
int32_t h_100;
|
||||
if (type == SHT3X_TYPE_SHT4X) {
|
||||
h = ((((data[3] << 8) | data[4]) * 125) / 65535.0) - 6.0;
|
||||
h_100 = ((((data[3] << 8) | data[4]) * 12500) >> 16) - 600;
|
||||
} else {
|
||||
h = (((data[3] << 8) | data[4]) * 100) / 65535.0;
|
||||
h_100 = ((((data[3] << 8) | data[4]) * 10000) >> 16);
|
||||
}
|
||||
sht3x_sensors[sensor].temp = ConvertTemp(t);
|
||||
sht3x_sensors[sensor].humi = ConvertHumidity(h);
|
||||
sht3x_sensors[sensor].temp = ConvertTemp(t_100/100.0f);
|
||||
sht3x_sensors[sensor].humi = ConvertHumidity(h_100/100.0f);
|
||||
if (isnan(sht3x_sensors[sensor].temp) || isnan(sht3x_sensors[sensor].humi)) { return false; }
|
||||
sht3x_sensors[sensor].valid = SENSOR_MAX_MISS;
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue