Skip to content

Commit

Permalink
New example some doc and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mwreef committed Oct 12, 2017
1 parent cf65701 commit e8ae2e5
Show file tree
Hide file tree
Showing 5 changed files with 3,847 additions and 14 deletions.
14 changes: 11 additions & 3 deletions DHT12.cpp
Expand Up @@ -80,7 +80,7 @@ DHT12::ReadStatus DHT12::readStatus(bool force) {
// Check if sensor was read less than two seconds ago and return early
// to use last reading.
uint32_t currenttime = millis();
if (!force && ((currenttime - _lastreadtime) < 2000)) {
if (!force && ((currenttime - _lastreadtime) < MIN_ELAPSED_TIME)) {
return _lastresult; // return last correct measurement
}
_lastreadtime = currenttime;
Expand Down Expand Up @@ -120,12 +120,12 @@ DHT12::ReadStatus DHT12::readStatus(bool force) {
// for ~80 microseconds again.
if (expectPulse(LOW) == 0) {
DEBUG_PRINTLN(F("Timeout waiting for start signal low pulse."));
_lastresult = ERROR_TIMEOUT;
_lastresult = ERROR_TIMEOUT_LOW;
return _lastresult;
}
if (expectPulse(HIGH) == 0) {
DEBUG_PRINTLN(F("Timeout waiting for start signal high pulse."));
_lastresult = ERROR_TIMEOUT;
_lastresult = ERROR_TIMEOUT_HIGH;
return _lastresult;
}

Expand Down Expand Up @@ -235,6 +235,14 @@ bool DHT12::read(bool force) {
DEBUG_PRINTLN(F("Timeout error"))
;
break;
case DHT12::ERROR_TIMEOUT_HIGH:
DEBUG_PRINTLN(F("Timeout error high"))
;
break;
case DHT12::ERROR_TIMEOUT_LOW:
DEBUG_PRINTLN(F("Timeout error low"))
;
break;
case DHT12::ERROR_CONNECT:
DEBUG_PRINTLN(F("Connect error"))
;
Expand Down
80 changes: 69 additions & 11 deletions DHT12.h
@@ -1,8 +1,9 @@
/* DHT library
MIT license
written by Adafruit Industries
/** \mainpage DHT12 sensor library
*
* MIT license
* written by Renzo Mischianti
*/

#ifndef DHT12_h
#define DHT12_h

Expand Down Expand Up @@ -46,30 +47,87 @@

class DHT12 {
public:
/**Status of the read*/
enum ReadStatus {
OK,
ERROR_CHECKSUM,
ERROR_TIMEOUT,
ERROR_CONNECT,
ERROR_ACK_L,
ERROR_ACK_H,
ERROR_UNKNOWN,
OK, /**All ok*/
ERROR_CHECKSUM, /**Error on checksum*/
ERROR_TIMEOUT, /**Timeout error*/
ERROR_TIMEOUT_LOW, /**Timeout on wait after low pulse*/
ERROR_TIMEOUT_HIGH,/**Timeout on wait after high pulse*/
ERROR_CONNECT, /**Connection error (Wire)*/
ERROR_ACK_L,/**Acknowledge Low */
ERROR_ACK_H,/**Acknowledge High */
ERROR_UNKNOWN, /**Error unknown */
NONE
};

/**
* Standard constructor, default wire connection on default SDA SCL pin
*/
DHT12(void);
/**
* Constructor
* @param addressORPin If oneWire == true this is pin number if oneWire false this is address of i2c
* @param oneWire select if is oneWire of i2c
*/
DHT12(uint8_t addressORPin, bool oneWire = false);
#ifndef __AVR
/**
* Additional parameter non tested for Arduino, Arduino very slow on software i2c
*/
DHT12(uint8_t sda, uint8_t scl);
DHT12(uint8_t sda, uint8_t scl, uint8_t address);
#endif
/**
* Start handshake
*/
void begin(void);
/**
* Read temperature
* @param scale Select false --> Celsius true --> Fahrenheit
* @param force
* @return
*/
float readTemperature(bool scale = false, bool force = false);
/**
* Convert Celsius to Fahrenheit
* @param
* @return
*/
float convertCtoF(float);
/**
* Convert Fahrenheit to Celsius
* @param
* @return
*/
float convertFtoC(float);
/**
* The heat index (HI) or humiture is an index that combines air temperature and relative humidity, in shaded areas, as an attempt to determine the human-perceived equivalent temperature, as how hot it would feel if the humidity were some other value in the shade. The result is also known as the "felt air temperature" or "apparent temperature".
* @param temperature
* @param percentHumidity
* @param isFahrenheit specify scale of temperature
* @return
*/
float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit = true);
/**
* Read humidity percentage
* @param force Force to request new data (if 2secs is not passed from previous request)
* @return
*/
float readHumidity(bool force = false);
/**
* Dew point the atmospheric temperature (varying according to pressure and humidity) below which water droplets begin to condense and dew can form.
* @param temperature
* @param humidity
* @param isFahrenheit specify scale of temperature
* @return
*/
float dewPoint(float temperature, float humidity, bool isFahrenheit = true);
/**
* Read and return status of the read
* @param force
* @return
*/
ReadStatus readStatus(bool force = false);bool read(bool force = false);

private:
Expand Down

0 comments on commit e8ae2e5

Please sign in to comment.