Skip to content

Commit

Permalink
Switch to using sensor period for T-5sec delay (pollPeriod begin arg)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyeth committed Nov 7, 2024
1 parent b4c83b8 commit 2052621
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/i2c/WipperSnapper_I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/components/i2c/drivers/WipperSnapper_I2C_Driver_SCD4X.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down

0 comments on commit 2052621

Please sign in to comment.