Save 66 bytes by using integer arithmetric

This commit is contained in:
Bodo Eggert 2016-09-08 17:11:29 +02:00
parent 09344416d2
commit 519393f42e

View File

@ -45,9 +45,7 @@ float DHT::readTemperature(bool S, bool force) {
break; break;
case DHT22: case DHT22:
case DHT21: case DHT21:
f = data[2] & 0x7F; f = ((word)(data[2] & 0x7F)) << 8 | data[3];
f *= 256;
f += data[3];
f *= 0.1; f *= 0.1;
if (data[2] & 0x80) { if (data[2] & 0x80) {
f *= -1; f *= -1;
@ -78,9 +76,7 @@ float DHT::readHumidity(bool force) {
break; break;
case DHT22: case DHT22:
case DHT21: case DHT21:
f = data[0]; f = ((word)data[0]) << 8 | data[1];
f *= 256;
f += data[1];
f *= 0.1; f *= 0.1;
break; break;
} }