-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDigooTH.h
94 lines (70 loc) · 3.52 KB
/
DigooTH.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
uint32_t activeTimeout = 5*60*1000 ; //5мин
struct DigooData{
uint32_t updated = 0;
float temperature = 0;
double humidity = 0;
uint8_t batt = 0;
bool isNew[2] = {false, false};
uint8_t id = 0;
};
struct Digoo : Service::TemperatureSensor { // First we create a derived class from the HomeSpan
SpanCharacteristic *CurrentTemperature; // here we create a generic pointer to a SpanCharacteristic
SpanCharacteristic *StatusActive;
SpanCharacteristic *StatusLowBattery;
DigooData* Data;
Digoo(DigooData* Data) : Service::TemperatureSensor(){
LOG1("Constructing digoo…\n");
this->Data = Data;
CurrentTemperature=new Characteristic::CurrentTemperature(25, true);// this is where we create the On Characterstic we had previously defined in setup(). Save this in the pointer created above, for use below
CurrentTemperature->setRange(-50, 100, 0.1);
StatusActive=new Characteristic::StatusActive(true, true);
StatusLowBattery=new Characteristic::StatusLowBattery(1, true);
LOG1(this->Data->humidity);
LOG1("Constructing Digoo successful!\n");
new DigooH(this->Data);
} // end constructor
void loop(){ // loop() method
if ( (millis() - Data->updated) > activeTimeout ){
//LOG1("sensor timeout\n");
if (StatusActive -> getVal()) {StatusActive->setVal(false);}
return;
}
if (Data->isNew[0]){
LOG1("temp sensor update\n");
Data->isNew[0] = false;
if (CurrentTemperature->getVal() != Data->temperature) {CurrentTemperature->setVal(Data->temperature);}
//CurrentTemperature->setVal(Data->temperature);
if (StatusLowBattery->getVal() != Data->batt) {StatusLowBattery->setVal(Data->batt);}
if ( !(StatusActive -> getVal()) ) {StatusActive->setVal(true);}
}
} // loop
struct DigooH : Service::HumiditySensor { // First we create a derived class from the HomeSpan
SpanCharacteristic *CurrentRelativeHumidity; // here we create a generic pointer to a SpanCharacteristic
SpanCharacteristic *StatusActive;
SpanCharacteristic *StatusLowBattery;
DigooData* DataH;
DigooH(DigooData* Data) : Service::HumiditySensor(){
LOG1("Constructing digooH…\n");
this->DataH = Data;
CurrentRelativeHumidity=new Characteristic::CurrentRelativeHumidity(0, true);// this is where we create the On Characterstic we had previously defined in setup(). Save this in the pointer created above, for use below
StatusActive=new Characteristic::StatusActive(true, true);
StatusLowBattery=new Characteristic::StatusLowBattery(1, true);
LOG1(this->DataH->humidity);
LOG1("Constructing Digoo successful!\n");
} // end constructor
void loop(){ // loop() method
if ( (millis() - DataH->updated) > activeTimeout ){
if (StatusActive -> getVal()) {StatusActive->setVal(false);}
return;
}
if (DataH->isNew[1]){
LOG1("hum sensor update\n");
DataH->isNew[1] = false;
if (CurrentRelativeHumidity->getVal() != DataH->humidity) {CurrentRelativeHumidity->setVal(DataH->humidity);}
//CurrentRelativeHumidity->setVal(DataH->humidity);
if (StatusLowBattery->getVal() != DataH->batt) {StatusLowBattery->setVal(DataH->batt);}
if ( !(StatusActive -> getVal()) ) {StatusActive->setVal(true);}
}
} // loop
};
};