Fork of DHT component - https://os.mbed.com/teams/components/code/DHT/ and update for MbedOS6+

Committer:
Wimpie
Date:
Mon Jul 09 19:47:43 2012 +0000
Revision:
0:9b5b3200688f
Child:
2:df22ddf10d75

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wimpie 0:9b5b3200688f 1 /*
Wimpie 0:9b5b3200688f 2 * DHT Library for Digital-output Humidity and Temperature sensors
Wimpie 0:9b5b3200688f 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)
Wimpie 0:9b5b3200688f 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"
Wimpie 0:9b5b3200688f 37
Wimpie 0:9b5b3200688f 38 enum eType{
Wimpie 0:9b5b3200688f 39 DHT11 = 11,
Wimpie 0:9b5b3200688f 40 SEN11301P = 11,
Wimpie 0:9b5b3200688f 41 RHT01 = 11,
Wimpie 0:9b5b3200688f 42 DHT22 = 22,
Wimpie 0:9b5b3200688f 43 AM2302 = 22,
Wimpie 0:9b5b3200688f 44 SEN51035P = 22,
Wimpie 0:9b5b3200688f 45 RHT02 = 22,
Wimpie 0:9b5b3200688f 46 RHT03 = 22
Wimpie 0:9b5b3200688f 47 } ;
Wimpie 0:9b5b3200688f 48
Wimpie 0:9b5b3200688f 49 enum eError {
Wimpie 0:9b5b3200688f 50 ERROR_NONE = 0,
Wimpie 0:9b5b3200688f 51 BUS_BUSY =1,
Wimpie 0:9b5b3200688f 52 ERROR_NOT_PRESENT =2 ,
Wimpie 0:9b5b3200688f 53 ERROR_ACK_TOO_LONG =3 ,
Wimpie 0:9b5b3200688f 54 ERROR_SYNC_TIMEOUT = 4,
Wimpie 0:9b5b3200688f 55 ERROR_DATA_TIMEOUT =5 ,
Wimpie 0:9b5b3200688f 56 ERROR_CHECKSUM = 6,
Wimpie 0:9b5b3200688f 57 ERROR_NO_PATIENCE =7
Wimpie 0:9b5b3200688f 58 } ;
Wimpie 0:9b5b3200688f 59
Wimpie 0:9b5b3200688f 60 typedef enum {
Wimpie 0:9b5b3200688f 61 CELCIUS =0 ,
Wimpie 0:9b5b3200688f 62 FARENHEIT =1,
Wimpie 0:9b5b3200688f 63 KELVIN=2
Wimpie 0:9b5b3200688f 64 } eScale;
Wimpie 0:9b5b3200688f 65
Wimpie 0:9b5b3200688f 66
Wimpie 0:9b5b3200688f 67 class DHT {
Wimpie 0:9b5b3200688f 68
Wimpie 0:9b5b3200688f 69 public:
Wimpie 0:9b5b3200688f 70
Wimpie 0:9b5b3200688f 71 DHT(PinName pin,int DHTtype);
Wimpie 0:9b5b3200688f 72 ~DHT();
Wimpie 0:9b5b3200688f 73 int readData(void);
Wimpie 0:9b5b3200688f 74 float ReadHumidity(void);
Wimpie 0:9b5b3200688f 75 float ReadTemperature(eScale Scale);
Wimpie 0:9b5b3200688f 76 float CalcdewPoint(float celsius, float humidity);
Wimpie 0:9b5b3200688f 77 float CalcdewPointFast(float celsius, float humidity);
Wimpie 0:9b5b3200688f 78
Wimpie 0:9b5b3200688f 79 private:
Wimpie 0:9b5b3200688f 80 time_t _lastReadTime;
Wimpie 0:9b5b3200688f 81 float _lastTemperature;
Wimpie 0:9b5b3200688f 82 float _lastHumidity;
Wimpie 0:9b5b3200688f 83 PinName _pin;
Wimpie 0:9b5b3200688f 84 bool _firsttime;
Wimpie 0:9b5b3200688f 85 int _DHTtype;
Wimpie 0:9b5b3200688f 86 int DHT_data[6];
Wimpie 0:9b5b3200688f 87 float CalcTemperature();
Wimpie 0:9b5b3200688f 88 float CalcHumidity();
Wimpie 0:9b5b3200688f 89 float ConvertCelciustoFarenheit(float);
Wimpie 0:9b5b3200688f 90 float ConvertCelciustoKelvin(float);
Wimpie 0:9b5b3200688f 91
Wimpie 0:9b5b3200688f 92 };
Wimpie 0:9b5b3200688f 93
Wimpie 0:9b5b3200688f 94 #endif