1 step for smart green house

Dependencies:   mbed

Committer:
belloula
Date:
Wed May 22 22:28:10 2019 +0000
Revision:
0:fcce3b1e1dec
for smart green house

Who changed what in which revision?

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