9

Dependents:   DISCO-F746NG_office_environment

Committer:
dillerkongen
Date:
Wed Jan 22 09:14:22 2020 +0000
Revision:
1:2a2e808056af
Parent:
0:9b5b3200688f
e

Who changed what in which revision?

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