-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDHTSensor.h
48 lines (42 loc) · 1.07 KB
/
DHTSensor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef _DHTSENSORMEASUREMENT_h
#define _DHTSENSORMEASUREMENT_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
class DHTSensorMeasurement
{
public:
static DHTSensorMeasurement WithError();
static DHTSensorMeasurement WithReadings(float humidity, float temperatureCelsius);
bool HasError();
float Humidity();
float TemperatureInCelsius();
float TemperatureInFahrenheit();
float TemperatureInKelvin();
private:
float _humidity;
float _temperatureCelsius;
bool _hasError;
};
class DHTSensor
{
public:
DHTSensor(uint8_t dataPin);
DHTSensor(uint8_t dataPin, uint8_t powerPin);
DHTSensorMeasurement Read();
private:
uint8_t _dataPin;
unsigned long _samplingTimeout = 1 * 1000000;//one second
bool BeginSensorRead();
bool ReadSensorData(uint8_t* sensorData);
DHTSensorMeasurement ProduceResult(uint8_t* sensorData);
unsigned long MeasureLineHighTime();
unsigned long MeasureLineLowTime();
bool LineIsHigh();
bool LineIsLow();
bool HasTimedOut(unsigned long samplingStart);
bool IsChecksumValid(uint8_t* dataArray);
};
#endif