Skip to content

Commit 2052621

Browse files
committed
Switch to using sensor period for T-5sec delay (pollPeriod begin arg)
1 parent b4c83b8 commit 2052621

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
565565
WS_DEBUG_PRINTLN("VEML7700 Initialized Successfully!");
566566
} else if (strcmp("scd40", msgDeviceInitReq->i2c_device_name) == 0) {
567567
_scd40 = new WipperSnapper_I2C_Driver_SCD4X(this->_i2c, i2cAddress);
568-
if (!_scd40->begin()) {
568+
if (!_scd40->begin(msgDeviceInitReq->i2c_device_properties[0].sensor_period)) {
569569
WS_DEBUG_PRINTLN("ERROR: Failed to initialize SCD4x!");
570570
_busStatusResponse =
571571
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;

src/components/i2c/drivers/WipperSnapper_I2C_Driver_SCD4X.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
4747
/*******************************************************************************/
4848
/*!
4949
@brief Initializes the SCD40 sensor and begins I2C.
50+
@param pollPeriod
51+
The sensor's polling period in milliseconds.
5052
@returns True if initialized successfully, False otherwise.
5153
*/
5254
/*******************************************************************************/
53-
bool begin() {
55+
bool begin(ulong pollPeriod) {
5456
_scd = new SensirionI2CScd4x();
5557
_scd->begin(*_i2c);
5658

@@ -65,7 +67,7 @@ class WipperSnapper_I2C_Driver_SCD4X : public WipperSnapper_I2C_Driver {
6567
}
6668

6769
// Takes 5seconds to have data ready, don't queue read until then
68-
ulong currentTime = millis() - 25000uL; // T-25s, so 5s time for 30s polling
70+
ulong currentTime = millis() - (pollPeriod * 1000 - 5000); // 5s time
6971
this->setSensorCO2PeriodPrv(currentTime);
7072
this->setSensorAmbientTempFPeriodPrv(currentTime);
7173
this->setSensorAmbientTempPeriodPrv(currentTime);

0 commit comments

Comments
 (0)