Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of DHT by
Revision 1:946ecc42b731, committed 2016-11-28
- Comitter:
- javiersing
- Date:
- Mon Nov 28 12:59:39 2016 +0000
- Parent:
- 0:9b5b3200688f
- Commit message:
- This is a Testing library
Changed in this revision
| DHT.cpp | Show annotated file Show diff for this revision Revisions of this file |
| DHT.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/DHT.cpp Mon Jul 09 19:47:43 2012 +0000
+++ b/DHT.cpp Mon Nov 28 12:59:39 2016 +0000
@@ -43,6 +43,21 @@
DHT::~DHT() {
}
+void DHT::printErr(int ErrType) {
+ switch (ErrType) {
+ case 0: printf("ERROR_NONE"); break;
+ case 1: printf("BUS_BUSY"); break;
+ case 2: printf("ERROR_NOT_PRESENT"); break;
+ case 3: printf("ERROR_ACK_TOO_LONG"); break;
+ case 4: printf("ERROR_SYNC_TIMEOUT"); break;
+ case 5: printf("ERROR_DATA_TIMEOUT"); break;
+ case 6: printf("ERROR_CHECKSUM"); break;
+ case 7: printf("ERROR_NO_PATIENCE"); break;
+
+ }
+ printf("\r\n");
+}
+
int DHT::readData() {
int i, j, retryCount,b;
unsigned int bitTimes[DHT_DATA_BIT_COUNT];
@@ -79,9 +94,9 @@
DHT_io.output();
DHT_io = 0;
- wait_ms(18);
+ wait_ms(5);
DHT_io = 1;
- wait_us(40);
+ wait_us(20);
DHT_io.input();
retryCount = 0;
@@ -98,8 +113,8 @@
return err;
}
- wait_us(80);
-
+ wait_us(80); //step 2 wait for High
+
for (i = 0; i < 5; i++) {
for (j = 0; j < 8; j++) {
@@ -149,7 +164,7 @@
float DHT::CalcTemperature() {
int v;
-
+ float outvalue;
switch (_DHTtype) {
case DHT11:
v = DHT_data[2];
@@ -158,10 +173,10 @@
v = DHT_data[2] & 0x7F;
v *= 256;
v += DHT_data[3];
- v /= 10;
+ outvalue=(float) v/10;
if (DHT_data[2] & 0x80)
- v *= -1;
- return float(v);
+ outvalue *= -1;
+ return outvalue;
}
return 0;
}
@@ -215,7 +230,8 @@
float DHT::CalcHumidity() {
int v;
-
+ float outvalue;
+
switch (_DHTtype) {
case DHT11:
v = DHT_data[0];
@@ -224,10 +240,9 @@
v = DHT_data[0];
v *= 256;
v += DHT_data[1];
- v /= 10;
- return float(v);
+ outvalue=(float) v/10;
+ return outvalue;
}
return 0;
}
-
--- a/DHT.h Mon Jul 09 19:47:43 2012 +0000
+++ b/DHT.h Mon Nov 28 12:59:39 2016 +0000
@@ -75,7 +75,7 @@
float ReadTemperature(eScale Scale);
float CalcdewPoint(float celsius, float humidity);
float CalcdewPointFast(float celsius, float humidity);
-
+ void printErr(int ErrType);
private:
time_t _lastReadTime;
float _lastTemperature;
