-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdhtComponent.h
43 lines (36 loc) · 862 Bytes
/
dhtComponent.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
#include "DHT22.h"
#include "./scheduler.h"
#define DHT_PERIOD 3000
class Dht22Component {
public:
struct Args {
float* outHumidity;
float* outTemperature;
uint8_t pin;
Scheduler* timer;
};
Dht22Component(Args args)
: dht(args.pin) {
this->args = args;
this->initialized = false;
args.timer->schedule(DHT_PERIOD, true, &this->update, this);
}
private:
Args args;
DHT22 dht;
bool initialized;
bool update() {
if(!this->initialized) {
this->initialized = true;
}
auto err = dht.readData();
if(err != 0) {
//Serial.print("dht error: ");
//Serial.println(err);
return;
}
*(args.outHumidity) = this->dht.getHumidity();
*(args.outTemperature) = this->dht.getTemperatureC();
return true;
}
};