@@ -81,7 +81,7 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
81
81
@brief Checks if sensor was read within last 1s, or is the first read.
82
82
@returns True if the sensor was recently read, False otherwise.
83
83
*/
84
- bool hasBeenReadInLastSecond () {
84
+ bool HasBeenReadInLastSecond () {
85
85
return _lastRead != 0 && millis () - _lastRead < 1000 ;
86
86
}
87
87
@@ -91,18 +91,16 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
91
91
@returns True if the sensor is ready, False otherwise.
92
92
*/
93
93
/* ******************************************************************************/
94
- bool isSensorReady () {
94
+ bool IsSensorReady () {
95
95
bool isDataReady = false ;
96
- uint16_t error = _sen->readDataReady (isDataReady);
97
- if (error != 0 || !isDataReady) {
98
- // failed, one more quick attempt
99
- delay (100 );
100
- error = _sen->readDataReady (isDataReady);
101
- if (error != 0 || !isDataReady) {
102
- return false ;
96
+ for (int i = 0 ; i < 2 ; i++) {
97
+ uint16_t error = _sen->readDataReady (isDataReady);
98
+ if (error == 0 && isDataReady) {
99
+ return true ;
103
100
}
101
+ delay (100 );
104
102
}
105
- return true ;
103
+ return false ;
106
104
}
107
105
108
106
/* ******************************************************************************/
@@ -111,13 +109,13 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
111
109
@returns True if the sensor was read successfully, False otherwise.
112
110
*/
113
111
/* ******************************************************************************/
114
- bool readSensorData () {
112
+ bool ReadSensorData () {
115
113
// dont read sensor more than once per second
116
- if (hasBeenReadInLastSecond ()) {
114
+ if (HasBeenReadInLastSecond ()) {
117
115
return true ;
118
116
}
119
117
120
- if (!isSensorReady ()) {
118
+ if (!IsSensorReady ()) {
121
119
return false ;
122
120
}
123
121
@@ -142,7 +140,7 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
142
140
*/
143
141
/* ******************************************************************************/
144
142
bool getEventAmbientTemp (sensors_event_t *tempEvent) {
145
- if (!readSensorData () || _ambientTemperature == NAN) {
143
+ if (!ReadSensorData () || _ambientTemperature == NAN) {
146
144
return false ;
147
145
}
148
146
tempEvent->temperature = _ambientTemperature;
@@ -159,7 +157,7 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
159
157
*/
160
158
/* ******************************************************************************/
161
159
bool getEventRelativeHumidity (sensors_event_t *humidEvent) {
162
- if (!readSensorData () || _ambientHumidity == NAN) {
160
+ if (!ReadSensorData () || _ambientHumidity == NAN) {
163
161
return false ;
164
162
}
165
163
humidEvent->relative_humidity = _ambientHumidity;
@@ -179,7 +177,7 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
179
177
*/
180
178
/* ******************************************************************************/
181
179
bool getEventNOxIndex (sensors_event_t *noxIndexEvent) {
182
- if (!readSensorData () || _noxIndex == NAN) {
180
+ if (!ReadSensorData () || _noxIndex == NAN) {
183
181
return false ;
184
182
}
185
183
noxIndexEvent->nox_index = _noxIndex;
@@ -196,7 +194,7 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
196
194
*/
197
195
/* ******************************************************************************/
198
196
bool getEventVOCIndex (sensors_event_t *vocIndexEvent) {
199
- if (!readSensorData () || _vocIndex == NAN) {
197
+ if (!ReadSensorData () || _vocIndex == NAN) {
200
198
return false ;
201
199
}
202
200
vocIndexEvent->voc_index = _vocIndex;
@@ -213,7 +211,7 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
213
211
*/
214
212
/* ******************************************************************************/
215
213
bool getEventPM10_STD (sensors_event_t *pm10StdEvent) {
216
- if (!readSensorData () || _massConcentrationPm1p0 == NAN ||
214
+ if (!ReadSensorData () || _massConcentrationPm1p0 == NAN ||
217
215
_massConcentrationPm1p0 == OVERFLOW_SEN55) {
218
216
return false ;
219
217
}
@@ -231,7 +229,7 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
231
229
*/
232
230
/* ******************************************************************************/
233
231
bool getEventPM25_STD (sensors_event_t *pm25StdEvent) {
234
- if (!readSensorData () || _massConcentrationPm2p5 == NAN ||
232
+ if (!ReadSensorData () || _massConcentrationPm2p5 == NAN ||
235
233
_massConcentrationPm2p5 == OVERFLOW_SEN55) {
236
234
return false ;
237
235
}
@@ -249,7 +247,7 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
249
247
*/
250
248
/* ******************************************************************************/
251
249
bool getEventPM40_STD (sensors_event_t *pm40StdEvent) {
252
- if (!readSensorData () || _massConcentrationPm4p0 == NAN ||
250
+ if (!ReadSensorData () || _massConcentrationPm4p0 == NAN ||
253
251
_massConcentrationPm4p0 == OVERFLOW_SEN55) {
254
252
return false ;
255
253
}
@@ -267,7 +265,7 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
267
265
*/
268
266
/* ******************************************************************************/
269
267
bool getEventPM100_STD (sensors_event_t *pm100StdEvent) {
270
- if (!readSensorData () || _massConcentrationPm10p0 == NAN ||
268
+ if (!ReadSensorData () || _massConcentrationPm10p0 == NAN ||
271
269
_massConcentrationPm10p0 == OVERFLOW_SEN55) {
272
270
return false ;
273
271
}
@@ -277,9 +275,14 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
277
275
278
276
protected:
279
277
SensirionI2CSen5x *_sen = nullptr ; // /< SEN5X driver object
280
- float _massConcentrationPm1p0, _massConcentrationPm2p5,
281
- _massConcentrationPm4p0, _massConcentrationPm10p0, _ambientHumidity,
282
- _ambientTemperature, _vocIndex, _noxIndex; // /< Sensor values
278
+ float _massConcentrationPm1p0; // /< PM1.0 mass concentration
279
+ float _massConcentrationPm2p5; // /< PM2.5 mass concentration
280
+ float _massConcentrationPm4p0; // /< PM4.0 mass concentration
281
+ float _massConcentrationPm10p0; // /< PM10.0 mass concentration
282
+ float _ambientHumidity; // /< Ambient humidity
283
+ float _ambientTemperature; // /< Ambient temperature
284
+ float _vocIndex; // /< VOC index
285
+ float _noxIndex; // /< NOx index
283
286
ulong _lastRead = 0uL; // /< Last time the sensor was read
284
287
};
285
288
0 commit comments