mirror of
https://github.com/adafruit/DHT-sensor-library.git
synced 2023-10-23 22:20:38 +03:00
Merge pull request #61 from 7eggert/master
Save 66 bytes by using integer arithmetric
This commit is contained in:
commit
5550a040c2
8
DHT.cpp
8
DHT.cpp
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user