Fork
Dependents: DHT11_and_DHT22_MbedOS5_Example
DHT.h@4:1b4e37ce64f8, 2019-11-08 (annotated)
- Committer:
- Daniel_Lee
- Date:
- Fri Nov 08 04:21:13 2019 +0000
- Revision:
- 4:1b4e37ce64f8
- Parent:
- 2:df22ddf10d75
- Child:
- 5:cd2c41384ab8
Fixed compile error;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove | 2:df22ddf10d75 | 1 | /* |
sam_grove | 2:df22ddf10d75 | 2 | * DHT Library for Digital-output Humidity and Temperature sensors |
sam_grove | 2:df22ddf10d75 | 3 | * |
Wimpie | 0:9b5b3200688f | 4 | * Works with DHT11, DHT21, DHT22 |
Wimpie | 0:9b5b3200688f | 5 | * SEN11301P, Grove - Temperature&Humidity Sensor (Seeed Studio) |
Wimpie | 0:9b5b3200688f | 6 | * SEN51035P, Grove - Temperature&Humidity Sensor Pro (Seeed Studio) |
sam_grove | 2:df22ddf10d75 | 7 | * AM2302 , temperature-humidity sensor |
Wimpie | 0:9b5b3200688f | 8 | * RHT01,RHT02, RHT03 , Humidity and Temperature Sensor (Sparkfun) |
Wimpie | 0:9b5b3200688f | 9 | * |
Wimpie | 0:9b5b3200688f | 10 | * Copyright (C) Wim De Roeve |
Wimpie | 0:9b5b3200688f | 11 | * based on DHT22 sensor library by HO WING KIT |
Wimpie | 0:9b5b3200688f | 12 | * Arduino DHT11 library |
Wimpie | 0:9b5b3200688f | 13 | * |
Wimpie | 0:9b5b3200688f | 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
Wimpie | 0:9b5b3200688f | 15 | * of this software and associated documnetation files (the "Software"), to deal |
Wimpie | 0:9b5b3200688f | 16 | * in the Software without restriction, including without limitation the rights |
Wimpie | 0:9b5b3200688f | 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
Wimpie | 0:9b5b3200688f | 18 | * copies of the Software, and to permit persons to whom the Software is |
Wimpie | 0:9b5b3200688f | 19 | * furished to do so, subject to the following conditions: |
Wimpie | 0:9b5b3200688f | 20 | * |
Wimpie | 0:9b5b3200688f | 21 | * The above copyright notice and this permission notice shall be included in |
Wimpie | 0:9b5b3200688f | 22 | * all copies or substantial portions of the Software. |
Wimpie | 0:9b5b3200688f | 23 | * |
Wimpie | 0:9b5b3200688f | 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Wimpie | 0:9b5b3200688f | 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Wimpie | 0:9b5b3200688f | 26 | * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
Wimpie | 0:9b5b3200688f | 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Wimpie | 0:9b5b3200688f | 28 | * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Wimpie | 0:9b5b3200688f | 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
Wimpie | 0:9b5b3200688f | 30 | * THE SOFTWARE. |
Wimpie | 0:9b5b3200688f | 31 | */ |
Wimpie | 0:9b5b3200688f | 32 | |
Wimpie | 0:9b5b3200688f | 33 | #ifndef MBED_DHT_H |
Wimpie | 0:9b5b3200688f | 34 | #define MBED_DHT_H |
Wimpie | 0:9b5b3200688f | 35 | |
Wimpie | 0:9b5b3200688f | 36 | #include "mbed.h" |
sam_grove | 2:df22ddf10d75 | 37 | typedef enum eType eType; |
sam_grove | 2:df22ddf10d75 | 38 | enum eType { |
sam_grove | 2:df22ddf10d75 | 39 | DHT11 = 11, |
sam_grove | 2:df22ddf10d75 | 40 | SEN11301P = 11, |
sam_grove | 2:df22ddf10d75 | 41 | RHT01 = 11, |
sam_grove | 2:df22ddf10d75 | 42 | DHT22 = 22, |
sam_grove | 2:df22ddf10d75 | 43 | AM2302 = 22, |
sam_grove | 2:df22ddf10d75 | 44 | SEN51035P = 22, |
sam_grove | 2:df22ddf10d75 | 45 | RHT02 = 22, |
sam_grove | 2:df22ddf10d75 | 46 | RHT03 = 22 |
sam_grove | 2:df22ddf10d75 | 47 | }; |
Daniel_Lee | 4:1b4e37ce64f8 | 48 | /* |
Daniel_Lee | 4:1b4e37ce64f8 | 49 | typedef enum{ |
Daniel_Lee | 4:1b4e37ce64f8 | 50 | DHT11 = 11, |
Daniel_Lee | 4:1b4e37ce64f8 | 51 | SEN11301P = 11, |
Daniel_Lee | 4:1b4e37ce64f8 | 52 | RHT01 = 11, |
Daniel_Lee | 4:1b4e37ce64f8 | 53 | DHT22 = 22, |
Daniel_Lee | 4:1b4e37ce64f8 | 54 | AM2302 = 22, |
Daniel_Lee | 4:1b4e37ce64f8 | 55 | SEN51035P = 22, |
Daniel_Lee | 4:1b4e37ce64f8 | 56 | RHT02 = 22, |
Daniel_Lee | 4:1b4e37ce64f8 | 57 | RHT03 = 22 |
Daniel_Lee | 4:1b4e37ce64f8 | 58 | }eType; |
Daniel_Lee | 4:1b4e37ce64f8 | 59 | */ |
Daniel_Lee | 4:1b4e37ce64f8 | 60 | typedef enum eError { |
Wimpie | 0:9b5b3200688f | 61 | ERROR_NONE = 0, |
sam_grove | 2:df22ddf10d75 | 62 | BUS_BUSY, |
sam_grove | 2:df22ddf10d75 | 63 | ERROR_NOT_PRESENT, |
sam_grove | 2:df22ddf10d75 | 64 | ERROR_ACK_TOO_LONG, |
sam_grove | 2:df22ddf10d75 | 65 | ERROR_SYNC_TIMEOUT, |
sam_grove | 2:df22ddf10d75 | 66 | ERROR_DATA_TIMEOUT, |
sam_grove | 2:df22ddf10d75 | 67 | ERROR_CHECKSUM, |
sam_grove | 2:df22ddf10d75 | 68 | ERROR_NO_PATIENCE |
sam_grove | 2:df22ddf10d75 | 69 | }; |
Wimpie | 0:9b5b3200688f | 70 | |
Daniel_Lee | 4:1b4e37ce64f8 | 71 | typedef enum eScale { |
sam_grove | 2:df22ddf10d75 | 72 | CELCIUS = 0, |
sam_grove | 2:df22ddf10d75 | 73 | FARENHEIT, |
sam_grove | 2:df22ddf10d75 | 74 | KELVIN |
sam_grove | 2:df22ddf10d75 | 75 | }; |
Wimpie | 0:9b5b3200688f | 76 | |
Wimpie | 0:9b5b3200688f | 77 | |
sam_grove | 2:df22ddf10d75 | 78 | class DHT |
sam_grove | 2:df22ddf10d75 | 79 | { |
Wimpie | 0:9b5b3200688f | 80 | |
Wimpie | 0:9b5b3200688f | 81 | public: |
Wimpie | 0:9b5b3200688f | 82 | |
sam_grove | 2:df22ddf10d75 | 83 | DHT(PinName pin, eType DHTtype); |
Wimpie | 0:9b5b3200688f | 84 | ~DHT(); |
sam_grove | 2:df22ddf10d75 | 85 | eError readData(void); |
Wimpie | 0:9b5b3200688f | 86 | float ReadHumidity(void); |
sam_grove | 2:df22ddf10d75 | 87 | float ReadTemperature(eScale const Scale); |
sam_grove | 2:df22ddf10d75 | 88 | float CalcdewPoint(float const celsius, float const humidity); |
sam_grove | 2:df22ddf10d75 | 89 | float CalcdewPointFast(float const celsius, float const humidity); |
Wimpie | 0:9b5b3200688f | 90 | |
Wimpie | 0:9b5b3200688f | 91 | private: |
Wimpie | 0:9b5b3200688f | 92 | time_t _lastReadTime; |
Wimpie | 0:9b5b3200688f | 93 | float _lastTemperature; |
Wimpie | 0:9b5b3200688f | 94 | float _lastHumidity; |
Wimpie | 0:9b5b3200688f | 95 | PinName _pin; |
Wimpie | 0:9b5b3200688f | 96 | bool _firsttime; |
sam_grove | 2:df22ddf10d75 | 97 | eType _DHTtype; |
sam_grove | 2:df22ddf10d75 | 98 | uint8_t DHT_data[5]; |
Wimpie | 0:9b5b3200688f | 99 | float CalcTemperature(); |
Wimpie | 0:9b5b3200688f | 100 | float CalcHumidity(); |
sam_grove | 2:df22ddf10d75 | 101 | float ConvertCelciustoFarenheit(float const); |
sam_grove | 2:df22ddf10d75 | 102 | float ConvertCelciustoKelvin(float const); |
sam_grove | 2:df22ddf10d75 | 103 | eError stall(DigitalInOut &io, int const level, int const max_time); |
Wimpie | 0:9b5b3200688f | 104 | |
Wimpie | 0:9b5b3200688f | 105 | }; |
Wimpie | 0:9b5b3200688f | 106 | |
Wimpie | 0:9b5b3200688f | 107 | #endif |