Fork

Dependents:   DHT11_and_DHT22_MbedOS5_Example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DHT.h Source File

DHT.h

00001 /*
00002  *  DHT Library for  Digital-output Humidity and Temperature sensors
00003  *
00004  *  Works with DHT11, DHT21, DHT22
00005  *             SEN11301P,  Grove - Temperature&Humidity Sensor     (Seeed Studio)
00006  *             SEN51035P,  Grove - Temperature&Humidity Sensor Pro (Seeed Studio)
00007  *             AM2302   ,  temperature-humidity sensor
00008  *             RHT01,RHT02, RHT03    ,  Humidity and Temperature Sensor         (Sparkfun)
00009  *
00010  *  Copyright (C) Wim De Roeve
00011  *                based on DHT22 sensor library by HO WING KIT
00012  *                Arduino DHT11 library
00013  *
00014  * Permission is hereby granted, free of charge, to any person obtaining a copy
00015  * of this software and associated documnetation files (the "Software"), to deal
00016  * in the Software without restriction, including without limitation the rights
00017  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00018  * copies of the Software, and to permit persons to  whom the Software is
00019  * furished to do so, subject to the following conditions:
00020  *
00021  * The above copyright notice and this permission notice shall be included in
00022  * all copies or substantial portions of the Software.
00023  *
00024  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00025  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00026  * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00027  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00028  * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00029  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00030  * THE SOFTWARE.
00031  */
00032 
00033 #ifndef MBED_DHT_H
00034 #define MBED_DHT_H
00035 
00036 #include "mbed.h"
00037 
00038 typedef enum {
00039     DHT11     = 11,
00040     SEN11301P = 11,
00041     RHT01     = 11,
00042     DHT22     = 22,
00043     AM2302    = 22,
00044     SEN51035P = 22,
00045     RHT02     = 22,
00046     RHT03     = 22
00047 }eType;
00048 
00049 typedef enum {
00050     ERROR_NONE = 0,
00051     BUS_BUSY,
00052     ERROR_NOT_PRESENT,
00053     ERROR_ACK_TOO_LONG,
00054     ERROR_SYNC_TIMEOUT,
00055     ERROR_DATA_TIMEOUT,
00056     ERROR_CHECKSUM,
00057     ERROR_NO_PATIENCE
00058 }eError;
00059 
00060 typedef enum {
00061     CELCIUS = 0,
00062     FARENHEIT,
00063     KELVIN
00064 }eScale;
00065 
00066 
00067 class DHT
00068 {
00069 
00070 public:
00071 
00072     DHT(PinName pin, eType DHTtype);
00073     ~DHT();
00074     eError readData(void);
00075     float ReadHumidity(void);
00076     float ReadTemperature(eScale const Scale);
00077     float CalcdewPoint(float const celsius, float const humidity);
00078     float CalcdewPointFast(float const celsius, float const humidity);
00079 
00080 private:
00081     time_t  _lastReadTime;
00082     float _lastTemperature;
00083     float _lastHumidity;
00084     PinName _pin;
00085     bool _firsttime;
00086     eType _DHTtype;
00087     uint8_t DHT_data[5];
00088     float CalcTemperature();
00089     float CalcHumidity();
00090     float ConvertCelciustoFarenheit(float const);
00091     float ConvertCelciustoKelvin(float const);
00092     eError stall(DigitalInOut &io, int const level, int const max_time);
00093 
00094 };
00095 
00096 #endif