mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.27 added get + setDisableIRQ
This commit is contained in:
parent
f84b960cf4
commit
2b8f54b4cb
@ -1,11 +1,12 @@
|
||||
//
|
||||
// FILE: dht.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.26
|
||||
// VERSION: 0.1.27
|
||||
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
|
||||
// URL: http://arduino.cc/playground/Main/DHTLib
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.27 2018-03-26 added _disableIRQ flag
|
||||
// 0.1.26 2017-12-12 explicit support for AM23XX series and DHT12
|
||||
// 0.1.25 2017-09-20 FIX https://github.com/RobTillaart/Arduino/issues/80
|
||||
// 0.1.24 2017-07-27 FIX https://github.com/RobTillaart/Arduino/issues/33 double -> float
|
||||
@ -146,6 +147,7 @@ int8_t dht::_readSensor(uint8_t pin, uint8_t wakeupDelay, uint8_t leadingZeroBit
|
||||
uint8_t port = digitalPinToPort(pin);
|
||||
volatile uint8_t *PIR = portInputRegister(port);
|
||||
|
||||
if (_disableIRQ) noInterrupts();
|
||||
// REQUEST SAMPLE
|
||||
pinMode(pin, OUTPUT);
|
||||
digitalWrite(pin, LOW); // T-be
|
||||
@ -158,7 +160,11 @@ int8_t dht::_readSensor(uint8_t pin, uint8_t wakeupDelay, uint8_t leadingZeroBit
|
||||
// while(digitalRead(pin) == HIGH)
|
||||
while ((*PIR & bit) != LOW )
|
||||
{
|
||||
if (--loopCount == 0) return DHTLIB_ERROR_CONNECT;
|
||||
if (--loopCount == 0)
|
||||
{
|
||||
interrupts();
|
||||
return DHTLIB_ERROR_CONNECT;
|
||||
}
|
||||
}
|
||||
|
||||
// GET ACKNOWLEDGE or TIMEOUT
|
||||
@ -166,14 +172,22 @@ int8_t dht::_readSensor(uint8_t pin, uint8_t wakeupDelay, uint8_t leadingZeroBit
|
||||
// while(digitalRead(pin) == LOW)
|
||||
while ((*PIR & bit) == LOW ) // T-rel
|
||||
{
|
||||
if (--loopCount == 0) return DHTLIB_ERROR_ACK_L;
|
||||
if (--loopCount == 0)
|
||||
{
|
||||
interrupts();
|
||||
return DHTLIB_ERROR_ACK_L;
|
||||
}
|
||||
}
|
||||
|
||||
loopCount = DHTLIB_TIMEOUT;
|
||||
// while(digitalRead(pin) == HIGH)
|
||||
while ((*PIR & bit) != LOW ) // T-reh
|
||||
{
|
||||
if (--loopCount == 0) return DHTLIB_ERROR_ACK_H;
|
||||
if (--loopCount == 0)
|
||||
{
|
||||
interrupts();
|
||||
return DHTLIB_ERROR_ACK_H;
|
||||
}
|
||||
}
|
||||
|
||||
loopCount = DHTLIB_TIMEOUT;
|
||||
@ -212,13 +226,14 @@ int8_t dht::_readSensor(uint8_t pin, uint8_t wakeupDelay, uint8_t leadingZeroBit
|
||||
// Check timeout
|
||||
if (--loopCount == 0)
|
||||
{
|
||||
return DHTLIB_ERROR_TIMEOUT;
|
||||
interrupts();
|
||||
return DHTLIB_ERROR_TIMEOUT;
|
||||
}
|
||||
|
||||
}
|
||||
// pinMode(pin, OUTPUT);
|
||||
// digitalWrite(pin, HIGH);
|
||||
|
||||
interrupts();
|
||||
return DHTLIB_OK;
|
||||
}
|
||||
//
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: dht.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.26
|
||||
// VERSION: 0.1.27
|
||||
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
|
||||
// URL: http://arduino.cc/playground/Main/DHTLib
|
||||
//
|
||||
@ -48,7 +48,7 @@
|
||||
class dht
|
||||
{
|
||||
public:
|
||||
dht() {};
|
||||
dht() { _disableIRQ = false; };
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
@ -70,12 +70,16 @@ public:
|
||||
inline int8_t read2320(uint8_t pin) { return read(pin); };
|
||||
inline int8_t read2322(uint8_t pin) { return read(pin); };
|
||||
|
||||
bool getDisableIRQ() { return _disableIRQ; };
|
||||
void setDisableIRQ(bool b ) { _disableIRQ = b; };
|
||||
|
||||
float humidity;
|
||||
float temperature;
|
||||
|
||||
private:
|
||||
uint8_t bits[5]; // buffer to receive data
|
||||
int8_t _readSensor(uint8_t pin, uint8_t wakeupDelay, uint8_t leadingZeroBits);
|
||||
bool _disableIRQ;
|
||||
};
|
||||
#endif
|
||||
//
|
||||
|
130
libraries/DHTlib/examples/dht22_test_noIRQ/dht22_test_noIRQ.ino
Normal file
130
libraries/DHTlib/examples/dht22_test_noIRQ/dht22_test_noIRQ.ino
Normal file
@ -0,0 +1,130 @@
|
||||
//
|
||||
// FILE: dht22_test_noIRQ.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: DHT library test sketch for DHT22 && Arduino
|
||||
// URL:
|
||||
// HISTORY:
|
||||
// 0.1.0 initial version
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#include <dht.h>
|
||||
|
||||
dht DHT;
|
||||
|
||||
#define DHT22_PIN 5
|
||||
|
||||
struct
|
||||
{
|
||||
uint32_t total;
|
||||
uint32_t ok;
|
||||
uint32_t crc_error;
|
||||
uint32_t time_out;
|
||||
uint32_t connect;
|
||||
uint32_t ack_l;
|
||||
uint32_t ack_h;
|
||||
uint32_t unknown;
|
||||
uint32_t sumtime;
|
||||
uint32_t mintime;
|
||||
} stat = { 0,0,0,0,0,0,0,0, 0, 9999};
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println("dht22_test.ino");
|
||||
Serial.print("LIBRARY VERSION: ");
|
||||
Serial.println(DHT_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Serial.print("IRQ:\t");
|
||||
Serial.println( DHT.getDisableIRQ() );
|
||||
DHT.setDisableIRQ(true);
|
||||
Serial.print("IRQ:\t");
|
||||
Serial.println( DHT.getDisableIRQ() );
|
||||
|
||||
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)\tTime (us)");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// READ DATA
|
||||
Serial.print("DHT22, \t");
|
||||
|
||||
uint32_t start = micros();
|
||||
int chk = DHT.read22(DHT22_PIN);
|
||||
uint32_t stop = micros();
|
||||
|
||||
stat.total++;
|
||||
switch (chk)
|
||||
{
|
||||
case DHTLIB_OK:
|
||||
stat.ok++;
|
||||
Serial.print("OK,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_CHECKSUM:
|
||||
stat.crc_error++;
|
||||
Serial.print("Checksum error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT:
|
||||
stat.time_out++;
|
||||
Serial.print("Time out error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_CONNECT:
|
||||
stat.connect++;
|
||||
Serial.print("Connect error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_ACK_L:
|
||||
stat.ack_l++;
|
||||
Serial.print("Ack Low error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_ACK_H:
|
||||
stat.ack_h++;
|
||||
Serial.print("Ack High error,\t");
|
||||
break;
|
||||
default:
|
||||
stat.unknown++;
|
||||
Serial.print("Unknown error,\t");
|
||||
break;
|
||||
}
|
||||
// DISPLAY DATA
|
||||
Serial.print(DHT.humidity, 1);
|
||||
Serial.print(",\t");
|
||||
Serial.print(DHT.temperature, 1);
|
||||
Serial.print(",\t");
|
||||
uint32_t duration = stop - start;
|
||||
stat.sumtime += duration;
|
||||
stat.mintime = min(stat.mintime, duration);
|
||||
Serial.print(duration);
|
||||
Serial.println();
|
||||
|
||||
if (stat.total % 20 == 0)
|
||||
{
|
||||
Serial.println("\nTOT\tOK\tCRC\tTIMO\tCON\tACKL\tACKH\tAVG\MIN");
|
||||
Serial.print(stat.total);
|
||||
Serial.print("\t");
|
||||
Serial.print(stat.ok);
|
||||
Serial.print("\t");
|
||||
Serial.print(stat.crc_error);
|
||||
Serial.print("\t");
|
||||
Serial.print(stat.time_out);
|
||||
Serial.print("\t");
|
||||
Serial.print(stat.connect);
|
||||
Serial.print("\t");
|
||||
Serial.print(stat.ack_l);
|
||||
Serial.print("\t");
|
||||
Serial.print(stat.ack_h);
|
||||
Serial.print("\t");
|
||||
Serial.print(stat.unknown);
|
||||
Serial.print("\t");
|
||||
Serial.print(1.0 * stat.sumtime / stat.total);
|
||||
Serial.print("\t");
|
||||
Serial.print(1.0 * stat.mintime);
|
||||
Serial.println("\n");
|
||||
}
|
||||
delay(500);
|
||||
}
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
@ -7,7 +7,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Arduino.git"
|
||||
},
|
||||
"version":"0.1.26",
|
||||
"version":"0.1.27",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"export": {
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=DHTlib
|
||||
version=0.1.26
|
||||
version=0.1.27
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Optimized Library for DHT Temperature & Humidity Sensor on AVR only.
|
||||
|
Loading…
Reference in New Issue
Block a user