PRAWIRA

Committer:
alienbernamaihsan
Date:
Mon Sep 16 10:07:29 2019 +0000
Revision:
0:1a8163abbb7d
PRAWIRA

Who changed what in which revision?

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