-
Notifications
You must be signed in to change notification settings - Fork 1
/
VOCSensor.cpp
53 lines (48 loc) · 1.61 KB
/
VOCSensor.cpp
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
#include "VOCSensor.h"
VOCSensor::VOCSensor(gas_measurement *m) { this->measurement = m; }
bool VOCSensor::init() {
if (!this->sgp.begin()) {
return false;
}
// sgp.setIAQBaseline(0x8E68, 0x8F41);
return true;
}
void VOCSensor::update() {
this->sgp.IAQmeasure();
this->updateVOCRange();
this->updateCO2Range();
}
void VOCSensor::updateVOCRange() {
// VOC range from https://www.airthings.com/what-is-voc
this->measurement->tvoc.value = this->sgp.TVOC;
if (this->sgp.TVOC < 250) {
this->measurement->tvoc.libelle = "Low";
this->measurement->tvoc.color = 0x07E0;
} else if (this->sgp.TVOC < 2000) {
this->measurement->tvoc.libelle = "Moderate";
this->measurement->tvoc.color = 0xFFE0;
} else {
this->measurement->tvoc.libelle = "High";
this->measurement->tvoc.color = 0xF800;
}
}
void VOCSensor::updateCO2Range() {
// CO2 Range from https://www.kane.co.uk/knowledge-centre/what-are-safe-levels-of-co-and-co2-in-rooms
this->measurement->eco2.value = this->sgp.eCO2;
if (this->sgp.eCO2 < 500) {
this->measurement->eco2.libelle = "Normal";
this->measurement->eco2.color = 0x07E0;
} else if (this->sgp.eCO2 < 1000) {
this->measurement->eco2.libelle = "Fair";
this->measurement->eco2.color = 0xFFE0;
} else if (this->sgp.eCO2 < 2000) {
this->measurement->eco2.libelle = "High";
this->measurement->eco2.color = 0xFDA0;
} else if (this->sgp.eCO2 < 5000) {
this->measurement->eco2.libelle = "Very high";
this->measurement->eco2.color = 0xF800;
} else {
this->measurement->eco2.libelle = "Dangerous";
this->measurement->eco2.color = 0x7800;
}
}