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