Domotique/WifiControlSensor/sensor_DHT.ino

29 lines
497 B
Arduino
Raw Normal View History

#ifdef CONFIG_ENABLE_DHT
#include "sensor_DHT.h"
int DHTSetup(int pin){
dht = new DHT(pin, DHTTYPE);
dht->begin();
return 0;
}
int DHTGetTempAndHumidity(float &t, float &h){
2016-06-01 00:36:14 +02:00
if(!DHTIsConnected())
goto err;
t = dht->readTemperature();
h = dht->readHumidity();
2016-06-01 00:36:14 +02:00
if(isnan(t) || isnan(h))
goto err;
return 0;
err:
t=0;
h=0;
return -1;
}
bool DHTIsConnected(){
//No way to know if connected
//Check at least if initialized
return dht != NULL;
}
#endif