Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix api inconsistency about temperature units #87

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions DHT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions DHT.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ 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=true);
float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=false);
float readHumidity(bool force=false);
boolean read(bool force=false);

Expand Down
8 changes: 4 additions & 4 deletions examples/DHTtester/DHTtester.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down