forked from adafruit/DHT-sensor-library
actionified, formatted and doxy'd
This commit is contained in:
1 parent
428e115b57
commit
5d60b0d3f0
10 files changed
+387
-341
No files matched your search
@@ -3,7 +3,8 @@
|
||||
*
|
||||
* This is a library for DHT series of low cost temperature/humidity sensors.
|
||||
*
|
||||
* You must have Adafruit Unified Sensor Library library installed to use this class.
|
||||
* You must have Adafruit Unified Sensor Library library installed to use this
|
||||
* class.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit andopen-source hardware by purchasing products
|
||||
@@ -22,71 +23,77 @@
|
||||
/* Uncomment to enable printing out nice debug messages. */
|
||||
//#define DHT_DEBUG
|
||||
|
||||
|
||||
#define DEBUG_PRINTER Serial /**< Define where debug output will be printed. */
|
||||
#define DEBUG_PRINTER \
|
||||
Serial /**< Define where debug output will be printed. \
|
||||
*/
|
||||
|
||||
/* Setup debug printing macros. */
|
||||
#ifdef DHT_DEBUG
|
||||
#define DEBUG_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); }
|
||||
#define DEBUG_PRINTLN(...) { DEBUG_PRINTER.println(__VA_ARGS__); }
|
||||
#define DEBUG_PRINT(...) \
|
||||
{ DEBUG_PRINTER.print(__VA_ARGS__); }
|
||||
#define DEBUG_PRINTLN(...) \
|
||||
{ DEBUG_PRINTER.println(__VA_ARGS__); }
|
||||
#else
|
||||
#define DEBUG_PRINT(...) {} /**< Debug Print Placeholder if Debug is disabled */
|
||||
#define DEBUG_PRINTLN(...) {} /**< Debug Print Line Placeholder if Debug is disabled */
|
||||
#define DEBUG_PRINT(...) \
|
||||
{} /**< Debug Print Placeholder if Debug is disabled */
|
||||
#define DEBUG_PRINTLN(...) \
|
||||
{} /**< Debug Print Line Placeholder if Debug is disabled */
|
||||
#endif
|
||||
|
||||
/* Define types of sensors. */
|
||||
#define DHT11 11 /**< DHT TYPE 11 */
|
||||
#define DHT12 12 /**< DHY TYPE 12 */
|
||||
#define DHT22 22 /**< DHT TYPE 22 */
|
||||
#define DHT21 21 /**< DHT TYPE 21 */
|
||||
#define DHT11 11 /**< DHT TYPE 11 */
|
||||
#define DHT12 12 /**< DHY TYPE 12 */
|
||||
#define DHT22 22 /**< DHT TYPE 22 */
|
||||
#define DHT21 21 /**< DHT TYPE 21 */
|
||||
#define AM2301 21 /**< AM2301 */
|
||||
|
||||
/*!
|
||||
/*!
|
||||
* @brief Class that stores state and functions for DHT
|
||||
*/
|
||||
class DHT {
|
||||
public:
|
||||
DHT(uint8_t pin, uint8_t type, uint8_t count=6);
|
||||
void begin(uint8_t usec=55);
|
||||
float readTemperature(bool S=false, bool force=false);
|
||||
float convertCtoF(float);
|
||||
float convertFtoC(float);
|
||||
float computeHeatIndex(bool isFahrenheit=true);
|
||||
float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true);
|
||||
float readHumidity(bool force=false);
|
||||
bool read(bool force=false);
|
||||
public:
|
||||
DHT(uint8_t pin, uint8_t type, uint8_t count = 6);
|
||||
void begin(uint8_t usec = 55);
|
||||
float readTemperature(bool S = false, bool force = false);
|
||||
float convertCtoF(float);
|
||||
float convertFtoC(float);
|
||||
float computeHeatIndex(bool isFahrenheit = true);
|
||||
float computeHeatIndex(float temperature, float percentHumidity,
|
||||
bool isFahrenheit = true);
|
||||
float readHumidity(bool force = false);
|
||||
bool read(bool force = false);
|
||||
|
||||
private:
|
||||
private:
|
||||
uint8_t data[5];
|
||||
uint8_t _pin, _type;
|
||||
#ifdef __AVR
|
||||
// Use direct GPIO access on an 8-bit AVR so keep track of the port and bitmask
|
||||
// for the digital pin connected to the DHT. Other platforms will use digitalRead.
|
||||
uint8_t _bit, _port;
|
||||
#endif
|
||||
#ifdef __AVR
|
||||
// Use direct GPIO access on an 8-bit AVR so keep track of the port and
|
||||
// bitmask for the digital pin connected to the DHT. Other platforms will use
|
||||
// digitalRead.
|
||||
uint8_t _bit, _port;
|
||||
#endif
|
||||
uint32_t _lastreadtime, _maxcycles;
|
||||
bool _lastresult;
|
||||
uint8_t pullTime; // Time (in usec) to pull up data line before reading
|
||||
|
||||
uint32_t expectPulse(bool level);
|
||||
|
||||
};
|
||||
|
||||
/*!
|
||||
/*!
|
||||
* @brief Class that defines Interrupt Lock Avaiability
|
||||
*/
|
||||
class InterruptLock {
|
||||
public:
|
||||
InterruptLock() {
|
||||
#if !defined(ARDUINO_ARCH_NRF52)
|
||||
public:
|
||||
InterruptLock() {
|
||||
#if !defined(ARDUINO_ARCH_NRF52)
|
||||
noInterrupts();
|
||||
#endif
|
||||
}
|
||||
~InterruptLock() {
|
||||
#if !defined(ARDUINO_ARCH_NRF52)
|
||||
}
|
||||
~InterruptLock() {
|
||||
#if !defined(ARDUINO_ARCH_NRF52)
|
||||
interrupts();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user