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