-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIAQ_BME680.cpp
67 lines (58 loc) · 1.61 KB
/
IAQ_BME680.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "Arduino.h"
#include "IAQ_BME680.h"
#define BME680_DEBUG
IAQ_BME680::IAQ_BME680(void)
{
};
bool IAQ_BME680::begin(uint8_t addr)
{
return Adafruit_BME680::begin(addr);
};
bool IAQ_BME680::update(void)
{
if (!performReading()) {
Serial.println(F("bme680 read failure"));
return false;
};
ahumidity = calcAbsHum(temperature, humidity);
dewpoint = calcDewPoint(temperature, humidity);
// no gas reading yet
if (gas_resistance == 0) {
return true;
};
_vocCRes += 0.3 * ((gas_resistance * ahumidity) - _vocCRes);
_vocBase += 0.0001 * (_vocCRes - _vocBase);
// base line correction, low-pass cause of sensor latency
if (_vocBase < _vocCRes && !initialized) {
_vocBase += 0.5 * (_vocCRes - _vocBase);
} else if (_vocBase < _vocCRes && initialized) {
_vocBase += 0.005 * (_vocCRes - _vocBase);
} else if (!initialized) {
initialized = true;
};
float ratio = _vocBase / _vocCRes;
if (ratio < 1) {
ratio = 1;
};
//float tV = (1250 * log(ratio)) + 125;
tvoc = 125 + ((ratio - 1) * 1500);
//Serial.println(_vocBase);
//Serial.println(_vocCRes);
//Serial.println(ratio);
//Serial.println(tV);
//Serial.println(tV * 3.2);
//Serial.println(pressure / 100.0);
return true;
};
float IAQ_BME680::calcAbsHum(float temp, float hum)
{
double sdd, dd;
sdd = 6.1078 * pow(10,(7.5 * temp) / (237.3 + temp));
dd = hum / 100.0 * sdd;
return (float) 216.687 * dd / (273.15 + temp);
};
float IAQ_BME680::calcDewPoint(float temp, float hum)
{
double A = (hum/100) * pow(10, (7.5*temp / (237+temp)));
return (float) 237*log10(A)/(7.5-log10(A));
};