diff --git a/src/components/i2c/WipperSnapper_I2C.cpp b/src/components/i2c/WipperSnapper_I2C.cpp index 3c82369b..03056ec1 100644 --- a/src/components/i2c/WipperSnapper_I2C.cpp +++ b/src/components/i2c/WipperSnapper_I2C.cpp @@ -565,7 +565,7 @@ bool WipperSnapper_Component_I2C::initI2CDevice( WS_DEBUG_PRINTLN("VEML7700 Initialized Successfully!"); } else if (strcmp("scd40", msgDeviceInitReq->i2c_device_name) == 0) { _scd40 = new WipperSnapper_I2C_Driver_SCD4X(this->_i2c, i2cAddress); - if (!_scd40->begin()) { + if (!_scd40->begin(msgDeviceInitReq->i2c_device_properties[0].sensor_period)) { WS_DEBUG_PRINTLN("ERROR: Failed to initialize SCD4x!"); _busStatusResponse = wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL; diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_SCD4X.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_SCD4X.h index 53dc04f0..b48deb24 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_SCD4X.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_SCD4X.h @@ -47,10 +47,12 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver { /*******************************************************************************/ /*! @brief Initializes the SCD40 sensor and begins I2C. + @param pollPeriod + The sensor's polling period in milliseconds. @returns True if initialized successfully, False otherwise. */ /*******************************************************************************/ - bool begin() { + bool begin(ulong pollPeriod) { _scd = new SensirionI2CScd4x(); _scd->begin(*_i2c); @@ -65,7 +67,7 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver { } // Takes 5seconds to have data ready, don't queue read until then - ulong currentTime = millis() - 25000uL; // T-25s, so 5s time for 30s polling + ulong currentTime = millis() - (pollPeriod * 1000 - 5000); // 5s time this->setSensorCO2PeriodPrv(currentTime); this->setSensorAmbientTempFPeriodPrv(currentTime); this->setSensorAmbientTempPeriodPrv(currentTime);