Skip to content

Commit

Permalink
Merge branch 'example'
Browse files Browse the repository at this point in the history
  • Loading branch information
chaeplin committed Feb 29, 2016
2 parents a5db21f + 8a40ec3 commit 4c8a369
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
12 changes: 10 additions & 2 deletions PietteTech_DHT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ void PietteTech_DHT::begin(uint8_t sigPin, uint8_t dht_type, void (*callback_wra
_status = DHTLIB_ERROR_NOTSTARTED;
}

int PietteTech_DHT::acquire() {
void PietteTech_DHT::reset() {
detachInterrupt(_sigPin);
_lastreadtime = 0;
_state = STOPPED;
_status = DHTLIB_ERROR_NOTSTARTED;

}

int ICACHE_RAM_ATTR PietteTech_DHT::acquire() {
// Check if sensor was read less than two seconds ago and return early
// to use last reading
unsigned long currenttime = millis();
Expand Down Expand Up @@ -152,7 +160,7 @@ int PietteTech_DHT::acquireAndWait(uint32_t timeout=0) {
return getStatus();
}

void PietteTech_DHT::isrCallback() {
void ICACHE_RAM_ATTR PietteTech_DHT::isrCallback() {
unsigned long newUs = micros();
unsigned long delta = (newUs - _us);
_us = newUs;
Expand Down
1 change: 1 addition & 0 deletions PietteTech_DHT.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class PietteTech_DHT
public:
PietteTech_DHT(uint8_t sigPin, uint8_t dht_type, void (*isrCallback_wrapper)());
void begin(uint8_t sigPin, uint8_t dht_type, void (*isrCallback_wrapper)());
void reset();
void isrCallback();
int acquire();
int acquireAndWait(uint32_t);
Expand Down
12 changes: 10 additions & 2 deletions examples/DHT_esp8266/DHT_esp8266.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#define DHTTYPE DHT22 // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN 2 // Digital pin for communications

#define REPORT_INTERVAL 5000 // in msec
#define REPORT_INTERVAL 5000 // in msec must > 2000

// to check dht
unsigned long startMills;
float t, h, d;
int acquireresult;
int acquirestatus;

//declaration
void dht_wrapper(); // must be declared before the lib initialization
Expand All @@ -36,6 +37,7 @@ void setup()
Serial.println("");

// blocking method
acquirestatus = 0;
acquireresult = DHT.acquireAndWait(1000);
if ( acquireresult == 0 ) {
t = DHT.getCelsius();
Expand All @@ -49,7 +51,8 @@ void setup()
void loop()
{
if (bDHTstarted) {
if (!DHT.acquiring()) {
acquirestatus = DHT.acquiring();
if (!acquirestatus) {
acquireresult = DHT.getStatus();
if ( acquireresult == 0 ) {
t = DHT.getCelsius();
Expand All @@ -74,6 +77,11 @@ void loop()

startMills = millis();

// to remove lock
if (acquirestatus == 1) {
DHT.reset();
}

if (!bDHTstarted) {
// non blocking method
DHT.acquire();
Expand Down

0 comments on commit 4c8a369

Please sign in to comment.