-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTHP.h
90 lines (62 loc) · 3.04 KB
/
THP.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
uint32_t activeTimeout = 5*60*1000 ; //5мин
struct DigooData{
uint32_t updated = 0;
float temperature = 0;
double humidity = 100;
bool isNew[2] = {true, true};
float pressure = 760.00;
};
CUSTOM_CHAR(Pressure, E863F10F-079E-48FF-8F27-9C2605A29F52, PR+EV, FLOAT, 760, 600, 1200, true);
struct THP : Service::TemperatureSensor { // First we create a derived class from the HomeSpan
SpanCharacteristic *CurrentTemperature; // here we create a generic pointer to a SpanCharacteristic
SpanCharacteristic *StatusActive;
DigooData* Data;
SpanCharacteristic *AirPressure;
THP(DigooData* Data) : Service::TemperatureSensor(){
LOG1("Constructing digoo…\n");
this->Data = Data;
CurrentTemperature=new Characteristic::CurrentTemperature(25);
CurrentTemperature->setRange(-50, 100, 0.1);
StatusActive=new Characteristic::StatusActive(true);
AirPressure = new Characteristic::Pressure(760);
LOG1(this->Data->humidity);
LOG1("Constructing Digoo successful!\n");
new THP_h(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]){
Data->isNew[0] = false;
AirPressure->setVal(Data->pressure);
//if (CurrentTemperature->getVal() != Data->temperature) {CurrentTemperature->setVal(Data->temperature);LOG1("sensor T update\n");}
CurrentTemperature->setVal(Data->temperature);
if ( !(StatusActive -> getVal()) ) {StatusActive->setVal(true);}
}
} // loop
struct THP_h : Service::HumiditySensor { // First we create a derived class from the HomeSpan
SpanCharacteristic *CurrentRelativeHumidity; // here we create a generic pointer to a SpanCharacteristic
SpanCharacteristic *StatusActive;
DigooData* DataH;
THP_h(DigooData* Data) : Service::HumiditySensor(){
this->DataH = Data;
CurrentRelativeHumidity=new Characteristic::CurrentRelativeHumidity(0);// 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);
} // end constructor
void loop(){ // loop() method
if ( (millis() - DataH->updated) > activeTimeout ){
if (StatusActive -> getVal()) {StatusActive->setVal(false);}
return;
}
if (DataH->isNew[1]){
DataH->isNew[1] = false;
//if (CurrentRelativeHumidity->getVal() != DataH->humidity) {CurrentRelativeHumidity->setVal(DataH->humidity);LOG1("sensor H update\n");}
CurrentRelativeHumidity->setVal(DataH->humidity);
if ( !(StatusActive -> getVal()) ) {StatusActive->setVal(true);}
}
} // loop
};
};