Skip to content

Commit 272c1fc

Browse files
committed
style changes
1 parent bcd3bd7 commit 272c1fc

File tree

5 files changed

+81
-76
lines changed

5 files changed

+81
-76
lines changed

src/components/i2c/drivers/WipperSnapper_I2C_Driver_HDC302X.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class WipperSnapper_I2C_Driver_HDC302X : public WipperSnapper_I2C_Driver {
6868
@returns True if the data was read successfully, False otherwise.
6969
*/
7070
/*******************************************************************************/
71-
bool readSensorData() {
71+
bool ReadSensorData() {
7272
uint16_t status = _hdc302x->readStatus();
7373
if (status & 0x0010) {
7474
WS_DEBUG_PRINTLN(F("Device Reset Detected"));
@@ -99,7 +99,7 @@ class WipperSnapper_I2C_Driver_HDC302X : public WipperSnapper_I2C_Driver {
9999
*/
100100
/*******************************************************************************/
101101
bool getEventAmbientTemp(sensors_event_t *tempEvent) {
102-
if (readSensorData() == false)
102+
if (ReadSensorData() == false)
103103
return false;
104104
tempEvent->temperature = _temp;
105105
return true;
@@ -115,7 +115,7 @@ class WipperSnapper_I2C_Driver_HDC302X : public WipperSnapper_I2C_Driver {
115115
*/
116116
/*******************************************************************************/
117117
bool getEventRelativeHumidity(sensors_event_t *humidEvent) {
118-
if (readSensorData() == false)
118+
if (ReadSensorData() == false)
119119
return false;
120120
humidEvent->relative_humidity = _humidity;
121121
return true;

src/components/i2c/drivers/WipperSnapper_I2C_Driver_SCD30.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class WipperSnapper_I2C_Driver_SCD30 : public WipperSnapper_I2C_Driver {
5858
@brief Checks if sensor was read within last 1s, or is the first read.
5959
@returns True if the sensor was recently read, False otherwise.
6060
*/
61-
bool hasBeenReadInLastSecond() {
61+
bool HasBeenReadInLastSecond() {
6262
return _lastRead != 0 && millis() - _lastRead < 1000;
6363
}
6464

@@ -68,7 +68,7 @@ class WipperSnapper_I2C_Driver_SCD30 : public WipperSnapper_I2C_Driver {
6868
@returns True if the sensor is ready, False otherwise.
6969
*/
7070
/*******************************************************************************/
71-
bool isSensorReady() {
71+
bool IsSensorReady() {
7272
if (!_scd->dataReady()) {
7373
// failed, one more quick attempt
7474
delay(100);
@@ -85,13 +85,13 @@ class WipperSnapper_I2C_Driver_SCD30 : public WipperSnapper_I2C_Driver {
8585
@returns True if the sensor was read successfully, False otherwise.
8686
*/
8787
/*******************************************************************************/
88-
bool readSensorData() {
88+
bool ReadSensorData() {
8989
// dont read sensor more than once per second
90-
if (hasBeenReadInLastSecond()) {
90+
if (HasBeenReadInLastSecond()) {
9191
return true;
9292
}
9393

94-
if (!isSensorReady()) {
94+
if (!IsSensorReady()) {
9595
return false;
9696
}
9797

@@ -114,7 +114,7 @@ class WipperSnapper_I2C_Driver_SCD30 : public WipperSnapper_I2C_Driver {
114114
/*******************************************************************************/
115115
bool getEventAmbientTemp(sensors_event_t *tempEvent) {
116116
// check if sensor is enabled and data is available
117-
if (!readSensorData()) {
117+
if (!ReadSensorData()) {
118118
return false;
119119
}
120120

@@ -133,7 +133,7 @@ class WipperSnapper_I2C_Driver_SCD30 : public WipperSnapper_I2C_Driver {
133133
/*******************************************************************************/
134134
bool getEventRelativeHumidity(sensors_event_t *humidEvent) {
135135
// check if sensor is enabled and data is available
136-
if (!readSensorData()) {
136+
if (!ReadSensorData()) {
137137
return false;
138138
}
139139

@@ -152,7 +152,7 @@ class WipperSnapper_I2C_Driver_SCD30 : public WipperSnapper_I2C_Driver {
152152
/*******************************************************************************/
153153
bool getEventCO2(sensors_event_t *co2Event) {
154154
// check if sensor is enabled and data is available
155-
if (!readSensorData()) {
155+
if (!ReadSensorData()) {
156156
return false;
157157
}
158158

src/components/i2c/drivers/WipperSnapper_I2C_Driver_SCD4X.h

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
7272
@brief Checks if sensor was read within last 1s, or is the first read.
7373
@returns True if the sensor was recently read, False otherwise.
7474
*/
75-
bool hasBeenReadInLastSecond() {
75+
/*******************************************************************************/
76+
bool HasBeenReadInLastSecond() {
7677
return _lastRead != 0 && millis() - _lastRead < 1000;
7778
}
7879

@@ -82,18 +83,16 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
8283
@returns True if the sensor is ready, False otherwise.
8384
*/
8485
/*******************************************************************************/
85-
bool isSensorReady() {
86+
bool IsSensorReady() {
8687
bool isDataReady = false;
87-
uint16_t error = _scd->getDataReadyStatus(isDataReady);
88-
if (error != 0 || !isDataReady) {
89-
// failed, one more quick attempt
90-
delay(100);
91-
error = _scd->getDataReadyStatus(isDataReady);
92-
if (error != 0 || !isDataReady) {
93-
return false;
88+
for (int i = 0; i < 2; i++) {
89+
uint16_t error = _scd->getDataReadyStatus(isDataReady);
90+
if (error == 0 && isDataReady) {
91+
return true;
9492
}
93+
delay(100);
9594
}
96-
return true;
95+
return false;
9796
}
9897

9998
/*******************************************************************************/
@@ -102,13 +101,13 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
102101
@returns True if the sensor was read successfully, False otherwise.
103102
*/
104103
/*******************************************************************************/
105-
bool readSensorData() {
104+
bool ReadSensorData() {
106105
// dont read sensor more than once per second
107-
if (hasBeenReadInLastSecond()) {
106+
if (HasBeenReadInLastSecond()) {
108107
return true;
109108
}
110109

111-
if (!isSensorReady()) {
110+
if (!IsSensorReady()) {
112111
return false;
113112
}
114113

@@ -138,7 +137,7 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
138137
/*******************************************************************************/
139138
bool getEventAmbientTemp(sensors_event_t *tempEvent) {
140139
// read all sensor measurements
141-
if (!readSensorData()) {
140+
if (!ReadSensorData()) {
142141
return false;
143142
}
144143

@@ -157,7 +156,7 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
157156
/*******************************************************************************/
158157
bool getEventRelativeHumidity(sensors_event_t *humidEvent) {
159158
// read all sensor measurements
160-
if (!readSensorData()) {
159+
if (!ReadSensorData()) {
161160
return false;
162161
}
163162

@@ -176,7 +175,7 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
176175
/*******************************************************************************/
177176
bool getEventCO2(sensors_event_t *co2Event) {
178177
// read all sensor measurements
179-
if (!readSensorData()) {
178+
if (!ReadSensorData()) {
180179
return false;
181180
}
182181

src/components/i2c/drivers/WipperSnapper_I2C_Driver_SEN5X.h

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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

278276
protected:
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

Comments
 (0)