@@ -42,13 +42,16 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
4242 : WipperSnapper_I2C_Driver(i2c, sensorAddress) {
4343 _i2c = i2c;
4444 _sensorAddress = sensorAddress;
45+ _lastRead = 0 ;
46+ _temperature = 20.0 ;
47+ _humidity = 50.0 ;
4548 }
4649
4750 /* ******************************************************************************/
4851 /* !
4952 @brief Initializes the SCD40 sensor and begins I2C.
5053 @param pollPeriod
51- The sensor's polling period in milliseconds .
54+ The sensor's polling period in seconds .
5255 @returns True if initialized successfully, False otherwise.
5356 */
5457 /* ******************************************************************************/
@@ -67,7 +70,7 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
6770 }
6871
6972 // 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
7174 this ->setSensorCO2PeriodPrv (currentTime);
7275 this ->setSensorAmbientTempFPeriodPrv (currentTime);
7376 this ->setSensorAmbientTempPeriodPrv (currentTime);
@@ -80,7 +83,7 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
8083 @brief Checks if sensor was read within last 1s, or is the first read.
8184 @returns True if the sensor was recently read, False otherwise.
8285 */
83- bool alreadyRecentlyRead () {
86+ bool hasBeenReadInLastSecond () {
8487 return _lastRead != 0 && millis () - _lastRead < 1000 ;
8588 }
8689
@@ -90,7 +93,7 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
9093 @returns True if the sensor is ready, False otherwise.
9194 */
9295 /* ******************************************************************************/
93- bool sensorReady () {
96+ bool isSensorReady () {
9497 bool isDataReady = false ;
9598 uint16_t error = _scd->getDataReadyFlag (isDataReady);
9699 if (error != 0 || !isDataReady) {
@@ -112,11 +115,11 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
112115 /* ******************************************************************************/
113116 bool readSensorData () {
114117 // dont read sensor more than once per second
115- if (alreadyRecentlyRead ()) {
118+ if (hasBeenReadInLastSecond ()) {
116119 return true ;
117120 }
118121
119- if (!sensorReady ()) {
122+ if (!isSensorReady ()) {
120123 return false ;
121124 }
122125
@@ -189,9 +192,9 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
189192protected:
190193 SensirionI2CScd4x *_scd = nullptr ; // /< SCD4x driver object
191194 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
195198};
196199
197200#endif // WipperSnapper_I2C_Driver_SCD4X
0 commit comments