From d4a877c7d875dc832d4490a418cc76f5a4ade1b6 Mon Sep 17 00:00:00 2001 From: Oleksandr Kovalchuk Date: Tue, 17 Oct 2017 11:21:51 +0300 Subject: [PATCH 1/3] Choose the degault temperature units As to https://github.com/snipter/firebase-iot-codelab/issues/3 there is a strange design when temperature is read in Celsius by default and heatIndex is computed in Farenheit by default. This commit sets the default unit to Celsius for calculating heatIndex. --- DHT.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DHT.h b/DHT.h index d81f6db..c4c6a6d 100644 --- a/DHT.h +++ b/DHT.h @@ -42,7 +42,7 @@ class DHT { float readTemperature(bool S=false, bool force=false); float convertCtoF(float); float convertFtoC(float); - float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true); + float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=false); float readHumidity(bool force=false); boolean read(bool force=false); From a80367cfe348c7b5c66a31a845e78058b8c8f662 Mon Sep 17 00:00:00 2001 From: Oleksandr Kovalchuk Date: Tue, 17 Oct 2017 11:25:19 +0300 Subject: [PATCH 2/3] Use better naming for S flag when reading temperature S == Scale does not clearly represents the flag purpose. Rename it to isFarenheit so it describes the flag purpose more precise --- DHT.cpp | 8 ++++---- DHT.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/DHT.cpp b/DHT.cpp index 86ad91c..cbf9643 100644 --- a/DHT.cpp +++ b/DHT.cpp @@ -31,15 +31,15 @@ void DHT::begin(void) { DEBUG_PRINT("Max clock cycles: "); DEBUG_PRINTLN(_maxcycles, DEC); } -//boolean S == Scale. True == Fahrenheit; False == Celcius -float DHT::readTemperature(bool S, bool force) { +//boolean isFahrenheit: True == Fahrenheit; False == Celcius +float DHT::readTemperature(bool isFahrenheit, bool force) { float f = NAN; if (read(force)) { switch (_type) { case DHT11: f = data[2]; - if(S) { + if(isFahrenheit) { f = convertCtoF(f); } break; @@ -52,7 +52,7 @@ float DHT::readTemperature(bool S, bool force) { if (data[2] & 0x80) { f *= -1; } - if(S) { + if(isFahrenheit) { f = convertCtoF(f); } break; diff --git a/DHT.h b/DHT.h index c4c6a6d..ffae7c6 100644 --- a/DHT.h +++ b/DHT.h @@ -39,7 +39,7 @@ class DHT { public: DHT(uint8_t pin, uint8_t type, uint8_t count=6); void begin(void); - float readTemperature(bool S=false, bool force=false); + float readTemperature(bool isFahrenheit=false, bool force=false); float convertCtoF(float); float convertFtoC(float); float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=false); From cfb8fd5470748553f98e772e19bc3bbcc725a302 Mon Sep 17 00:00:00 2001 From: Oleksandr Kovalchuk Date: Tue, 17 Oct 2017 11:28:37 +0300 Subject: [PATCH 3/3] Modify the example to reflect recent changes in code --- examples/DHTtester/DHTtester.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/DHTtester/DHTtester.ino b/examples/DHTtester/DHTtester.ino index ae6c41a..e00f95d 100644 --- a/examples/DHTtester/DHTtester.ino +++ b/examples/DHTtester/DHTtester.ino @@ -48,10 +48,10 @@ void loop() { return; } - // Compute heat index in Fahrenheit (the default) - float hif = dht.computeHeatIndex(f, h); - // Compute heat index in Celsius (isFahreheit = false) - float hic = dht.computeHeatIndex(t, h, false); + // Compute heat index in Celsius (the default) + float hif = dht.computeHeatIndex(t, h); + // Compute heat index in Fahrenheit (isFahreheit = true) + float hic = dht.computeHeatIndex(f, h, true); Serial.print("Humidity: "); Serial.print(h);