Skip to content

Commit

Permalink
xsns_14_sht3x.ino - data types adjusted, code size reduced (#21868)
Browse files Browse the repository at this point in the history
* code size, data type improvements

* Change temp calculation to int
  • Loading branch information
Grumium authored Jul 30, 2024
1 parent b4a0e27 commit 4101ad7
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions tasmota/tasmota_xsns_sensor/xsns_14_sht3x.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4101ad7

Please sign in to comment.