File tree Expand file tree Collapse file tree 2 files changed +26
-16
lines changed
src/components/i2c/drivers Expand file tree Collapse file tree 2 files changed +26
-16
lines changed Original file line number Diff line number Diff line change @@ -59,23 +59,33 @@ class WipperSnapper_I2C_Driver_SGP30 : public WipperSnapper_I2C_Driver {
59
59
return true ;
60
60
}
61
61
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 ;
69
72
}
73
+ return false ;
74
+ }
70
75
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 ;
78
86
}
87
+ return false ;
88
+ }
79
89
80
90
void fastTick () override {
81
91
if (!iaqEnabled ())
Original file line number Diff line number Diff line change @@ -113,13 +113,13 @@ class WipperSnapper_I2C_Driver_SGP40 : public WipperSnapper_I2C_Driver {
113
113
if (!_sgp40)
114
114
return false ;
115
115
if (_n > 0 ) {
116
- vocIndexEvent->voc_index = _vocSum / (float )_n;
116
+ vocIndexEvent->voc_index = ( uint16_t )( _vocSum / (float )_n) ;
117
117
_rawSum = 0 ;
118
118
_vocSum = 0 .0f ;
119
119
_n = 0 ;
120
120
return true ;
121
121
}
122
- vocIndexEvent->voc_index = (float )_sgp40->measureVocIndex ();
122
+ vocIndexEvent->voc_index = (uint16_t )_sgp40->measureVocIndex ();
123
123
return true ;
124
124
}
125
125
You can’t perform that action at this time.
0 commit comments