@@ -42,13 +42,16 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
42
42
: WipperSnapper_I2C_Driver(i2c, sensorAddress) {
43
43
_i2c = i2c;
44
44
_sensorAddress = sensorAddress;
45
+ _lastRead = 0 ;
46
+ _temperature = 20.0 ;
47
+ _humidity = 50.0 ;
45
48
}
46
49
47
50
/* ******************************************************************************/
48
51
/* !
49
52
@brief Initializes the SCD40 sensor and begins I2C.
50
53
@param pollPeriod
51
- The sensor's polling period in milliseconds .
54
+ The sensor's polling period in seconds .
52
55
@returns True if initialized successfully, False otherwise.
53
56
*/
54
57
/* ******************************************************************************/
@@ -67,7 +70,7 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
67
70
}
68
71
69
72
// Takes 5seconds to have data ready, don't queue read until then
70
- ulong currentTime = millis () - (pollPeriod * 1000 - 5000 ); // 5s time
73
+ long currentTime = ( long ) millis () - (( pollPeriod * 1000 ) - 5000 ); // 5s time
71
74
this ->setSensorCO2PeriodPrv (currentTime);
72
75
this ->setSensorAmbientTempFPeriodPrv (currentTime);
73
76
this ->setSensorAmbientTempPeriodPrv (currentTime);
@@ -80,7 +83,7 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
80
83
@brief Checks if sensor was read within last 1s, or is the first read.
81
84
@returns True if the sensor was recently read, False otherwise.
82
85
*/
83
- bool alreadyRecentlyRead () {
86
+ bool hasBeenReadInLastSecond () {
84
87
return _lastRead != 0 && millis () - _lastRead < 1000 ;
85
88
}
86
89
@@ -90,7 +93,7 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
90
93
@returns True if the sensor is ready, False otherwise.
91
94
*/
92
95
/* ******************************************************************************/
93
- bool sensorReady () {
96
+ bool isSensorReady () {
94
97
bool isDataReady = false ;
95
98
uint16_t error = _scd->getDataReadyFlag (isDataReady);
96
99
if (error != 0 || !isDataReady) {
@@ -112,11 +115,11 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
112
115
/* ******************************************************************************/
113
116
bool readSensorData () {
114
117
// dont read sensor more than once per second
115
- if (alreadyRecentlyRead ()) {
118
+ if (hasBeenReadInLastSecond ()) {
116
119
return true ;
117
120
}
118
121
119
- if (!sensorReady ()) {
122
+ if (!isSensorReady ()) {
120
123
return false ;
121
124
}
122
125
@@ -189,9 +192,9 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
189
192
protected:
190
193
SensirionI2CScd4x *_scd = nullptr ; // /< SCD4x driver object
191
194
uint16_t _co2 = 0 ; // /< SCD4x co2 reading
192
- float _temperature = 20 . 0f ; // /< SCD4x temperature reading
193
- float _humidity = 50 . 0f ; // /< SCD4x humidity reading
194
- ulong _lastRead = 0 ; // /< Last time the sensor was read
195
+ float _temperature; // /< SCD4x temperature reading
196
+ float _humidity; // /< SCD4x humidity reading
197
+ ulong _lastRead; // /< Last time the sensor was read
195
198
};
196
199
197
200
#endif // WipperSnapper_I2C_Driver_SCD4X
0 commit comments