forked from oseiler2/CO2Monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.cpp
More file actions
139 lines (119 loc) · 3.39 KB
/
Copy pathmodel.cpp
File metadata and controls
139 lines (119 loc) · 3.39 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <model.h>
#include <configManager.h>
// Local logging tag
static const char TAG[] = __FILE__;
Model::Model(modelUpdatedEvt_t _modelUpdatedEvt) {
this->temperature = NaN;
this->humidity = NaN;
this->co2 = 0;
this->pressure = 0;
this->iaq = 0;
this->pm0_5 = 0;
this->pm1 = 0;
this->pm2_5 = 0;
this->pm4 = 0;
this->pm10 = 0;
this->modelUpdatedEvt = _modelUpdatedEvt;
this->status = OFF;
}
Model::~Model() {}
void Model::updateStatus() {
TrafficLightStatus co2Status = OFF;
if (this->co2 != 0) {
if (this->co2 <= config.co2GreenThreshold) {
co2Status = OFF;
} else if (this->co2 <= config.co2YellowThreshold) {
co2Status = GREEN;
} else if (this->co2 <= config.co2RedThreshold) {
co2Status = YELLOW;
} else if (this->co2 <= config.co2DarkRedThreshold) {
co2Status = RED;
} else {
co2Status = DARK_RED;
}
}
TrafficLightStatus iaqStatus = OFF;
if (iaq != 0) {
if (iaq <= config.iaqGreenThreshold) {
iaqStatus = OFF;
} else if (iaq <= config.iaqYellowThreshold) {
iaqStatus = GREEN;
} else if (iaq <= config.iaqRedThreshold) {
iaqStatus = YELLOW;
} else if (iaq <= config.iaqDarkRedThreshold) {
iaqStatus = RED;
} else {
iaqStatus = DARK_RED;
}
}
this->status = max(co2Status, iaqStatus);
// ESP_LOGD(TAG, "UpdateStatus CO2: %i (%u), IAQ: %i (%u) ==> %i", co2Status, this->co2, iaqStatus, this->iaq, this->status);
}
void Model::updateModel(uint16_t _co2) {
this->co2 = _co2;
TrafficLightStatus oldStatus = this->status;
this->updateStatus();
modelUpdatedEvt((_co2 != 0 ? M_CO2 : M_NONE), oldStatus, this->status);
}
void Model::updateModel(uint16_t _co2, float _temperature, float _humidity) {
this->co2 = _co2;
this->temperature = _temperature;
this->humidity = _humidity;
TrafficLightStatus oldStatus = this->status;
this->updateStatus();
modelUpdatedEvt((_co2 != 0 ? M_CO2 : M_NONE) | M_TEMPERATURE | M_HUMIDITY, oldStatus, this->status);
}
void Model::updateModel(float _temperature, float _humidity, uint16_t _pressure, uint16_t _iaq) {
this->temperature = _temperature;
this->humidity = _humidity;
this->pressure = _pressure;
this->iaq = _iaq;
TrafficLightStatus oldStatus = this->status;
this->updateStatus();
modelUpdatedEvt(M_TEMPERATURE | M_HUMIDITY | M_PRESSURE | (_iaq != 0 ? M_IAQ : M_NONE), oldStatus, this->status);
}
void Model::updateModel(uint16_t _pm0_5, uint16_t _pm1, uint16_t _pm2_5, uint16_t _pm4, uint16_t _pm10) {
this->pm0_5 = _pm0_5;
this->pm1 = _pm1;
this->pm2_5 = _pm2_5;
this->pm4 = _pm4;
this->pm10 = _pm10;
modelUpdatedEvt(M_PM0_5 | M_PM1_0 | M_PM2_5 | M_PM4 | M_PM10, this->status, this->status);
}
void Model::configurationChanged() {
updateStatus();
modelUpdatedEvt(M_CONFIG_CHANGED, this->status, this->status);
}
TrafficLightStatus Model::getStatus() {
return this->status;
}
uint16_t Model::getCo2() {
return this->co2;
}
float Model::getTemperature() {
return this->temperature;
}
float Model::getHumidity() {
return this->humidity;
}
uint16_t Model::getPressure() {
return this->pressure;
}
uint16_t Model::getIAQ() {
return this->iaq;
}
uint16_t Model::getPM0_5() {
return this->pm0_5;
}
uint16_t Model::getPM1() {
return this->pm1;
}
uint16_t Model::getPM2_5() {
return this->pm2_5;
}
uint16_t Model::getPM4() {
return this->pm4;
}
uint16_t Model::getPM10() {
return this->pm10;
}