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

Added Convenience Methods #54

Open
wants to merge 5 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
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Vi files
*~

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
22 changes: 17 additions & 5 deletions DHT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ written by Adafruit Industries

#define MIN_INTERVAL 2000

DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) {
// Old constructor.
//DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) {

/*
* New constructor.
*
* Note that count is now ignored as the DHT reading algorithm adjusts itself
* based on the speed of the processor.
*/
DHT::DHT(uint8_t pin, uint8_t type) {
_pin = pin;
_type = type;
#ifdef __AVR
Expand All @@ -17,10 +26,9 @@ DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) {
#endif
_maxcycles = microsecondsToClockCycles(1000); // 1 millisecond timeout for
// reading pulses from DHT sensor.
// Note that count is now ignored as the DHT reading algorithm adjusts itself
// basd on the speed of the processor.
}


void DHT::begin(void) {
// set up the pins!
pinMode(_pin, INPUT_PULLUP);
Expand Down Expand Up @@ -152,8 +160,12 @@ boolean DHT::read(bool force) {
InterruptLock lock;

// End the start signal by setting data line high for 40 microseconds.
digitalWrite(_pin, HIGH);
delayMicroseconds(40);
//digitalWrite(_pin, HIGH);
//delayMicroseconds(40);
// WEB: This is an error. DHT tries to pull the line low as soon as it came back to high.
// therefore the low-high transition after the start signal "low" needs to be realised by
// the pullup resistor only, uC pin must already be in INPUT mode.
// ref: https://github.com/adafruit/DHT-sensor-library/issues/48

// Now start reading the data line to get the value from the DHT sensor.
pinMode(_pin, INPUT_PULLUP);
Expand Down
20 changes: 19 additions & 1 deletion DHT.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,28 @@ written by Adafruit Industries

class DHT {
public:
DHT(uint8_t pin, uint8_t type, uint8_t count=6);
// Note that count is now ignored as the DHT reading algorithm adjusts itself
// based on the speed of the processor.
DHT(uint8_t pin, uint8_t type, uint8_t count) {
DHT(pin, type);
Copy link

@dotdoom dotdoom Feb 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's quite accurate. What it does is a call to constructor DHT, but the instance constructed goes nowhere. Perhaps you wanted DHT(...): DHT(pin, type) { }; ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your feedback.

I am not sure I understand your comment.

The 3 arg constructor DHT(pin, type, count) calls the 2 arg constructor with DHT(pin, type) in the header. The 2 arg constructor is the header definition for the 2 arg constructor in the DHT.cpp file. I removed the 3 arg constructor that used to be in the DHT.cpp file.

Does that make sense or am misunderstanding your comment?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the right C++ syntax to delegate constructors.
It does call the constructor indeed, but it just constructs another
instance instead, which is then immediately discarded. See for example
https://en.wikipedia.org/wiki/C%2B%2B11#Object_construction_improvement

On Fri, Mar 4, 2016, 07:23 Gregg Ubben notifications@github.com wrote:

In DHT.h
#54 (comment)
:

@@ -37,11 +37,28 @@ written by Adafruit Industries

class DHT {
public:

  • DHT(uint8_t pin, uint8_t type, uint8_t count=6);
  • // Note that count is now ignored as the DHT reading algorithm adjusts itself
  • // based on the speed of the processor.
  • DHT(uint8_t pin, uint8_t type, uint8_t count) {
  • DHT(pin, type);
    

Thank you for your feedback.

I am not sure I understand your comment.

The 3 arg constructor DHT(pin, type, count) calls the 2 arg constructor
with DHT(pin, type) in the header. The 2 arg constructor is the header
definition for the 2 arg constructor in the DHT.cpp file. I removed the 3
arg constructor that used to be in the DHT.cpp file.

Does that make sense or am misunderstanding your comment?


Reply to this email directly or view it on GitHub
https://github.com/adafruit/DHT-sensor-library/pull/54/files#r54982620.

};
DHT(uint8_t pin, uint8_t type);
void begin(void);
float readFahrenheit(bool force=false) {
return readTemperature(true, force);
};
float readCelcius(bool force=false) {
return readTemperature(false, force);
};
float readTemperature(bool S=false, bool force=false);
float convertCtoF(float);
float convertFtoC(float);
float computeHeatIndexFahrenheit(float temperature, float percentHumidity) {
return computeHeatIndex(temperature, percentHumidity, true);
};
float computeHeatIndexCelcius(float temperature, float percentHumidity) {
return computeHeatIndex(temperature, percentHumidity, false);
};
float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true);
float readHumidity(bool force=false);
boolean read(bool force=false);
Expand All @@ -59,6 +76,7 @@ class DHT {

uint32_t expectPulse(bool level);

void _init(uint8_t pin, uint8_t type);
};

class InterruptLock {
Expand Down