dht library

Dependents:   prog_envoyer_B_v3

Fork of DHT by Wim De Roeve

Committer:
guillouhouede
Date:
Sat May 13 16:27:52 2017 +0000
Revision:
1:a2bc4effa732
Parent:
0:9b5b3200688f
dht;

Who changed what in which revision?

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