+ version 0.1.20

+ changed return type to int8_t reducing footprint with 34 bytes
+ minor comment change
This commit is contained in:
rob tillaart 2015-03-01 11:53:47 +01:00
parent 9bca4c27da
commit 33843c68ba
3 changed files with 24 additions and 21 deletions

View File

@ -1,11 +1,13 @@
//
// FILE: dht.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.19
// VERSION: 0.1.20
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
// URL: http://arduino.cc/playground/Main/DHTLib
//
// HISTORY:
// 0.1.20 Reduce footprint (34 bytes) by using int8_t as error codes.
// (thanks to chaveiro)
// 0.1.19 masking error for DHT11 - FIXED (thanks Richard for noticing)
// 0.1.18 version 1.16/17 broke the DHT11 - FIXED
// 0.1.17 replaced micros() with adaptive loopcount
@ -14,7 +16,9 @@
// added DHTLIB_ERROR_ACK_L DHTLIB_ERROR_ACK_H
// 0.1.16 masking unused bits (less errors); refactored bits[]
// 0.1.15 reduced # micros calls 2->1 in inner loop.
// 0.1.14 replace digital read with faster (~3x) code => more robust low MHz machines.
// 0.1.14 replace digital read with faster (~3x) code
// => more robust low MHz machines.
//
// 0.1.13 fix negative temperature
// 0.1.12 support DHT33 and DHT44 initial version
// 0.1.11 renamed DHTLIB_TIMEOUT
@ -42,10 +46,10 @@
// PUBLIC
//
int dht::read11(uint8_t pin)
int8_t dht::read11(uint8_t pin)
{
// READ VALUES
int result = _readSensor(pin, DHTLIB_DHT11_WAKEUP, DHTLIB_DHT11_LEADING_ZEROS);
int8_t result = _readSensor(pin, DHTLIB_DHT11_WAKEUP, DHTLIB_DHT11_LEADING_ZEROS);
// these bits are always zero, masking them reduces errors.
bits[0] &= 0x7F;
@ -65,10 +69,10 @@ int dht::read11(uint8_t pin)
return result;
}
int dht::read(uint8_t pin)
int8_t dht::read(uint8_t pin)
{
// READ VALUES
int result = _readSensor(pin, DHTLIB_DHT_WAKEUP, DHTLIB_DHT_LEADING_ZEROS);
int8_t result = _readSensor(pin, DHTLIB_DHT_WAKEUP, DHTLIB_DHT_LEADING_ZEROS);
// these bits are always zero, masking them reduces errors.
bits[0] &= 0x03;
@ -96,7 +100,7 @@ int dht::read(uint8_t pin)
// PRIVATE
//
int dht::_readSensor(uint8_t pin, uint8_t wakeupDelay, uint8_t leadingZeroBits)
int8_t dht::_readSensor(uint8_t pin, uint8_t wakeupDelay, uint8_t leadingZeroBits)
{
// INIT BUFFERVAR TO RECEIVE DATA
uint8_t mask = 128;

View File

@ -1,7 +1,7 @@
//
// FILE: dht.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.19
// VERSION: 0.1.20
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
// URL: http://arduino.cc/playground/Main/DHTLib
//
@ -19,7 +19,7 @@
#include <Arduino.h>
#endif
#define DHT_LIB_VERSION "0.1.19"
#define DHT_LIB_VERSION "0.1.20"
#define DHTLIB_OK 0
#define DHTLIB_ERROR_CHECKSUM -1
@ -51,20 +51,20 @@ public:
// DHTLIB_ERROR_CONNECT
// DHTLIB_ERROR_ACK_L
// DHTLIB_ERROR_ACK_H
int read11(uint8_t pin);
int read(uint8_t pin);
int8_t read11(uint8_t pin);
int8_t read(uint8_t pin);
inline int read21(uint8_t pin) { return read(pin); };
inline int read22(uint8_t pin) { return read(pin); };
inline int read33(uint8_t pin) { return read(pin); };
inline int read44(uint8_t pin) { return read(pin); };
inline int8_t read21(uint8_t pin) { return read(pin); };
inline int8_t read22(uint8_t pin) { return read(pin); };
inline int8_t read33(uint8_t pin) { return read(pin); };
inline int8_t read44(uint8_t pin) { return read(pin); };
double humidity;
double temperature;
private:
uint8_t bits[5]; // buffer to receive data
int _readSensor(uint8_t pin, uint8_t wakeupDelay, uint8_t leadingZeroBits);
int8_t _readSensor(uint8_t pin, uint8_t wakeupDelay, uint8_t leadingZeroBits);
};
#endif
//

View File

@ -1,6 +1,6 @@
The DHT11, 21, 22, 33 and 44 are relative inexpensive sensors for measuring temperature and humidity.
The DHT11, 21, 22, 33 and 44 are relative inexpensive sensors for measuring temperature and humidity.
This library can be used for reading both values from these DHT sensors.
This library can be used for reading both values from these DHT sensors.
The DHT11 only returns integers (e.g. 20) and does not support negative values.
The others are quite similar and provide one decimal digit (e.g. 20.2)
The hardware pins of the sensors and handshake are identical so ideal to combine in one lib.
@ -16,7 +16,7 @@ Digistump Digix @ 84 MHz
More information - http://playground.arduino.cc//Main/DHTLib -
Notes:
Notes:
version 0.1.13 is the last stable version for both AVR and ARM
version 0.1.14 and up are not compatible anymore with pre 1.0 Arduino
@ -25,5 +25,4 @@ version 0.1.15 is stable version for AVR only
version 0.1.16 and 0.1.17 have breaking changes for DHT11
version 0.1.18 works again for DHT11 (avr only)
version 0.1.19 fixed masking bug DHT11 (avr only)
version 0.1.20 Reduce footprint (34 bytes) by using int8_t as error codes. (thanks to chaveiro)