@@ -81,7 +81,7 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
8181 @brief Checks if sensor was read within last 1s, or is the first read.
8282 @returns True if the sensor was recently read, False otherwise.
8383 */
84- bool hasBeenReadInLastSecond () {
84+ bool HasBeenReadInLastSecond () {
8585 return _lastRead != 0 && millis () - _lastRead < 1000 ;
8686 }
8787
@@ -91,18 +91,16 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
9191 @returns True if the sensor is ready, False otherwise.
9292 */
9393 /* ******************************************************************************/
94- bool isSensorReady () {
94+ bool IsSensorReady () {
9595 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 ;
103100 }
101+ delay (100 );
104102 }
105- return true ;
103+ return false ;
106104 }
107105
108106 /* ******************************************************************************/
@@ -111,13 +109,13 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
111109 @returns True if the sensor was read successfully, False otherwise.
112110 */
113111 /* ******************************************************************************/
114- bool readSensorData () {
112+ bool ReadSensorData () {
115113 // dont read sensor more than once per second
116- if (hasBeenReadInLastSecond ()) {
114+ if (HasBeenReadInLastSecond ()) {
117115 return true ;
118116 }
119117
120- if (!isSensorReady ()) {
118+ if (!IsSensorReady ()) {
121119 return false ;
122120 }
123121
@@ -142,7 +140,7 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
142140 */
143141 /* ******************************************************************************/
144142 bool getEventAmbientTemp (sensors_event_t *tempEvent) {
145- if (!readSensorData () || _ambientTemperature == NAN) {
143+ if (!ReadSensorData () || _ambientTemperature == NAN) {
146144 return false ;
147145 }
148146 tempEvent->temperature = _ambientTemperature;
@@ -159,7 +157,7 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
159157 */
160158 /* ******************************************************************************/
161159 bool getEventRelativeHumidity (sensors_event_t *humidEvent) {
162- if (!readSensorData () || _ambientHumidity == NAN) {
160+ if (!ReadSensorData () || _ambientHumidity == NAN) {
163161 return false ;
164162 }
165163 humidEvent->relative_humidity = _ambientHumidity;
@@ -179,7 +177,7 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
179177 */
180178 /* ******************************************************************************/
181179 bool getEventNOxIndex (sensors_event_t *noxIndexEvent) {
182- if (!readSensorData () || _noxIndex == NAN) {
180+ if (!ReadSensorData () || _noxIndex == NAN) {
183181 return false ;
184182 }
185183 noxIndexEvent->nox_index = _noxIndex;
@@ -196,7 +194,7 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
196194 */
197195 /* ******************************************************************************/
198196 bool getEventVOCIndex (sensors_event_t *vocIndexEvent) {
199- if (!readSensorData () || _vocIndex == NAN) {
197+ if (!ReadSensorData () || _vocIndex == NAN) {
200198 return false ;
201199 }
202200 vocIndexEvent->voc_index = _vocIndex;
@@ -213,7 +211,7 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
213211 */
214212 /* ******************************************************************************/
215213 bool getEventPM10_STD (sensors_event_t *pm10StdEvent) {
216- if (!readSensorData () || _massConcentrationPm1p0 == NAN ||
214+ if (!ReadSensorData () || _massConcentrationPm1p0 == NAN ||
217215 _massConcentrationPm1p0 == OVERFLOW_SEN55) {
218216 return false ;
219217 }
@@ -231,7 +229,7 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
231229 */
232230 /* ******************************************************************************/
233231 bool getEventPM25_STD (sensors_event_t *pm25StdEvent) {
234- if (!readSensorData () || _massConcentrationPm2p5 == NAN ||
232+ if (!ReadSensorData () || _massConcentrationPm2p5 == NAN ||
235233 _massConcentrationPm2p5 == OVERFLOW_SEN55) {
236234 return false ;
237235 }
@@ -249,7 +247,7 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
249247 */
250248 /* ******************************************************************************/
251249 bool getEventPM40_STD (sensors_event_t *pm40StdEvent) {
252- if (!readSensorData () || _massConcentrationPm4p0 == NAN ||
250+ if (!ReadSensorData () || _massConcentrationPm4p0 == NAN ||
253251 _massConcentrationPm4p0 == OVERFLOW_SEN55) {
254252 return false ;
255253 }
@@ -267,7 +265,7 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
267265 */
268266 /* ******************************************************************************/
269267 bool getEventPM100_STD (sensors_event_t *pm100StdEvent) {
270- if (!readSensorData () || _massConcentrationPm10p0 == NAN ||
268+ if (!ReadSensorData () || _massConcentrationPm10p0 == NAN ||
271269 _massConcentrationPm10p0 == OVERFLOW_SEN55) {
272270 return false ;
273271 }
@@ -277,9 +275,14 @@ class WipperSnapper_I2C_Driver_SEN5X : public WipperSnapper_I2C_Driver {
277275
278276protected:
279277 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
283286 ulong _lastRead = 0uL; // /< Last time the sensor was read
284287};
285288
0 commit comments