Skip to content

Commit ef9590a

Browse files
committed
Fix merge conflicts, make compute heat index default to Fahrenheit to not break old code that assumes default is Fahrenheit.
2 parents b6925ee + 25942ac commit ef9590a

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

DHT.cpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void DHT::begin(void) {
2121
_lastreadtime = 0;
2222
}
2323

24-
//boolean S == Scale. True == Farenheit; False == Celcius
24+
//boolean S == Scale. True == Fahrenheit; False == Celcius
2525
float DHT::readTemperature(bool S) {
2626
float f = NAN;
2727

@@ -78,18 +78,34 @@ float DHT::readHumidity(void) {
7878
return f;
7979
}
8080

81-
float DHT::computeHeatIndex(float tempFahrenheit, float percentHumidity) {
81+
//boolean isFahrenheit: True == Fahrenheit; False == Celcius
82+
float DHT::computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit) {
8283
// Adapted from equation at: https://github.com/adafruit/DHT-sensor-library/issues/9 and
8384
// Wikipedia: http://en.wikipedia.org/wiki/Heat_index
84-
return -42.379 +
85-
2.04901523 * tempFahrenheit +
86-
10.14333127 * percentHumidity +
87-
-0.22475541 * tempFahrenheit*percentHumidity +
88-
-0.00683783 * pow(tempFahrenheit, 2) +
89-
-0.05481717 * pow(percentHumidity, 2) +
90-
0.00122874 * pow(tempFahrenheit, 2) * percentHumidity +
91-
0.00085282 * tempFahrenheit*pow(percentHumidity, 2) +
92-
-0.00000199 * pow(tempFahrenheit, 2) * pow(percentHumidity, 2);
85+
if (!isFahrenheit) {
86+
// Celsius heat index calculation.
87+
return -8.784695 +
88+
1.61139411 * temperature +
89+
2.338549 * percentHumidity +
90+
-0.14611605 * temperature*percentHumidity +
91+
-0.01230809 * pow(temperature, 2) +
92+
-0.01642482 * pow(percentHumidity, 2) +
93+
0.00221173 * pow(temperature, 2) * percentHumidity +
94+
0.00072546 * temperature*pow(percentHumidity, 2) +
95+
-0.00000358 * pow(temperature, 2) * pow(percentHumidity, 2);
96+
}
97+
else {
98+
// Fahrenheit heat index calculation.
99+
return -42.379 +
100+
2.04901523 * temperature +
101+
10.14333127 * percentHumidity +
102+
-0.22475541 * temperature*percentHumidity +
103+
-0.00683783 * pow(temperature, 2) +
104+
-0.05481717 * pow(percentHumidity, 2) +
105+
0.00122874 * pow(temperature, 2) * percentHumidity +
106+
0.00085282 * temperature*pow(percentHumidity, 2) +
107+
-0.00000199 * pow(temperature, 2) * pow(percentHumidity, 2);
108+
}
93109
}
94110

95111
boolean DHT::read(void) {

DHT.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class DHT {
4242
float readTemperature(bool S=false);
4343
float convertCtoF(float);
4444
float convertFtoC(float);
45-
float computeHeatIndex(float tempFahrenheit, float percentHumidity);
45+
float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true);
4646
float readHumidity(void);
4747
boolean read(void);
4848

examples/DHTtester/DHTtester.ino

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ void loop() {
3737
// Reading temperature or humidity takes about 250 milliseconds!
3838
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
3939
float h = dht.readHumidity();
40-
// Read temperature as Celsius
40+
// Read temperature as Celsius (the default)
4141
float t = dht.readTemperature();
42-
// Read temperature as Fahrenheit
42+
// Read temperature as Fahrenheit (isFahrenheit = true)
4343
float f = dht.readTemperature(true);
4444

4545
// Check if any reads failed and exit early (to try again).
@@ -48,9 +48,10 @@ void loop() {
4848
return;
4949
}
5050

51-
// Compute heat index
52-
// Must send in temp in Fahrenheit!
53-
float hi = dht.computeHeatIndex(f, h);
51+
// Compute heat index in Fahrenheit (the default)
52+
float hif = dht.computeHeatIndex(f, h);
53+
// Compute heat index in Celsius (isFahreheit = false)
54+
float hic = dht.computeHeatIndex(t, h, false);
5455

5556
Serial.print("Humidity: ");
5657
Serial.print(h);
@@ -61,6 +62,8 @@ void loop() {
6162
Serial.print(f);
6263
Serial.print(" *F\t");
6364
Serial.print("Heat index: ");
64-
Serial.print(hi);
65+
Serial.print(hic);
66+
Serial.print(" *C ");
67+
Serial.print(hif);
6568
Serial.println(" *F");
6669
}

0 commit comments

Comments
 (0)