Skip to content

Commit 281e41d

Browse files
committed
sgp30 / sgp40 integer values
also added sgp30 averaging option
1 parent 5cbb3d5 commit 281e41d

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

src/components/i2c/drivers/WipperSnapper_I2C_Driver_SGP30.h

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,33 @@ class WipperSnapper_I2C_Driver_SGP30 : public WipperSnapper_I2C_Driver {
5959
return true;
6060
}
6161

62-
bool getEventECO2(sensors_event_t *senseEvent) override {
63-
if (!_sgp30)
64-
return false;
65-
bool ok = _sgp30->IAQmeasure();
66-
if (ok)
67-
senseEvent->eCO2 = _sgp30->eCO2;
68-
return ok;
62+
bool getEventECO2(sensors_event_t *senseEvent) override {
63+
if (!_sgp30) return false;
64+
if (_n > 0) {
65+
senseEvent->eCO2 = (uint16_t)(_eco2Sum / _n);
66+
_eco2Sum = 0; _tvocSum = 0; _n = 0;
67+
return true;
68+
}
69+
if (_sgp30->IAQmeasure()) {
70+
senseEvent->eCO2 = (uint16_t)_sgp30->eCO2;
71+
return true;
6972
}
73+
return false;
74+
}
7075

71-
bool getEventTVOC(sensors_event_t *senseEvent) override {
72-
if (!_sgp30)
73-
return false;
74-
bool ok = _sgp30->IAQmeasure();
75-
if (ok)
76-
senseEvent->tvoc = _sgp30->TVOC;
77-
return ok;
76+
bool getEventTVOC(sensors_event_t *senseEvent) override {
77+
if (!_sgp30) return false;
78+
if (_n > 0) {
79+
senseEvent->tvoc = (uint16_t)(_tvocSum / _n);
80+
_eco2Sum = 0; _tvocSum = 0; _n = 0;
81+
return true;
82+
}
83+
if (_sgp30->IAQmeasure()) {
84+
senseEvent->tvoc = (uint16_t)_sgp30->TVOC;
85+
return true;
7886
}
87+
return false;
88+
}
7989

8090
void fastTick() override {
8191
if (!iaqEnabled())

src/components/i2c/drivers/WipperSnapper_I2C_Driver_SGP40.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ class WipperSnapper_I2C_Driver_SGP40 : public WipperSnapper_I2C_Driver {
113113
if (!_sgp40)
114114
return false;
115115
if (_n > 0) {
116-
vocIndexEvent->voc_index = _vocSum / (float)_n;
116+
vocIndexEvent->voc_index = (uint16_t)(_vocSum / (float)_n);
117117
_rawSum = 0;
118118
_vocSum = 0.0f;
119119
_n = 0;
120120
return true;
121121
}
122-
vocIndexEvent->voc_index = (float)_sgp40->measureVocIndex();
122+
vocIndexEvent->voc_index = (uint16_t)_sgp40->measureVocIndex();
123123
return true;
124124
}
125125

0 commit comments

Comments
 (0)