Skip to content

Commit

Permalink
SCD40 ready for virtual I2C (#22443)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-hadinger authored Nov 7, 2024
1 parent 94c4568 commit a571ca1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ All notable changes to this project will be documented in this file.
### Changed
- AHT1X/AHT2X/AHT3X ready for virtual I2C
- SGP4X ready for virtual I2C
- SCD40 reduce logging levels
- SCD40 ready for virtual I2C

### Fixed
- ESP32S3 UART output mode for Tx
Expand Down
22 changes: 11 additions & 11 deletions tasmota/tasmota_xsns_sensor/xsns_92_scd40.ino
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void Scd40Detect(void)
{
if (!I2cSetDevice(SCD40_ADDRESS)) { return; }

scd40.begin();
scd40.begin(&I2cGetWire());

// don't stop in case of error, try to continue
delay(10); // not sure whether this is needed
Expand Down Expand Up @@ -173,21 +173,21 @@ void Scd40Update(void)

case ERROR_SCD40_NO_DATA:
scd40DataNotAvailable_count++;
AddLog(LOG_LEVEL_DEBUG, PSTR("SCD40: no data available."));
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SCD40: no data available."));
break;

case ERROR_SCD40_CRC_ERROR:
scd40CrcError_count++;
#ifdef SCD40_DEBUG
AddLog(LOG_LEVEL_ERROR, PSTR("SCD40: CRC error, CRC error: %ld, good: %ld, no data: %ld, sc30_reset: %ld, i2c_reset: %ld"),
AddLog(LOG_LEVEL_INFO, PSTR("SCD40: CRC error, CRC error: %ld, good: %ld, no data: %ld, sc30_reset: %ld, i2c_reset: %ld"),
scd40CrcError_count, scd40GoodMeas_count, scd40DataNotAvailable_count, scd40Reset_count, scd40i2cReset_count);
#endif
break;

default: {
scd40ErrorState = SCD40_STATE_ERROR_READ_MEAS;
#ifdef SCD40_DEBUG
AddLog(LOG_LEVEL_ERROR, PSTR("SCD40: Update: ReadMeasurement error: 0x%lX, counter: %ld"), error, scd40Loop_count);
AddLog(LOG_LEVEL_INFO, PSTR("SCD40: Update: ReadMeasurement error: 0x%lX, counter: %ld"), error, scd40Loop_count);
#endif
return;
}
Expand All @@ -198,22 +198,22 @@ void Scd40Update(void)

case SCD40_STATE_ERROR_READ_MEAS: {
#ifdef SCD40_DEBUG
AddLog(LOG_LEVEL_ERROR, PSTR("SCD40: (rd) in error state: %d, good: %ld, no data: %ld, sc30 reset: %ld, i2c reset: %ld"),
AddLog(LOG_LEVEL_INFO, PSTR("SCD40: (rd) in error state: %d, good: %ld, no data: %ld, sc30 reset: %ld, i2c reset: %ld"),
scd40ErrorState, scd40GoodMeas_count, scd40DataNotAvailable_count, scd40Reset_count, scd40i2cReset_count);
AddLog(LOG_LEVEL_ERROR, PSTR("SCD40: not answering, sending soft reset, counter: %ld"), scd40Loop_count);
AddLog(LOG_LEVEL_INFO, PSTR("SCD40: not answering, sending soft reset, counter: %ld"), scd40Loop_count);
#endif
scd40Reset_count++;
error = scd40.stopPeriodicMeasurement();
if (error) {
scd40ErrorState = SCD40_STATE_ERROR_SOFT_RESET;
#ifdef SCD40_DEBUG
AddLog(LOG_LEVEL_ERROR, PSTR("SCD40: stopPeriodicMeasurement got error: 0x%lX"), error);
AddLog(LOG_LEVEL_INFO, PSTR("SCD40: stopPeriodicMeasurement got error: 0x%lX"), error);
#endif
} else {
error = scd40.reinit();
if (error) {
#ifdef SCD40_DEBUG
AddLog(LOG_LEVEL_ERROR, PSTR("SCD40: resetting got error: 0x%lX"), error);
AddLog(LOG_LEVEL_INFO, PSTR("SCD40: resetting got error: 0x%lX"), error);
#endif
scd40ErrorState = SCD40_STATE_ERROR_SOFT_RESET;
} else {
Expand All @@ -225,16 +225,16 @@ void Scd40Update(void)

case SCD40_STATE_ERROR_SOFT_RESET: {
#ifdef SCD40_DEBUG
AddLog(LOG_LEVEL_ERROR, PSTR("SCD40: (rst) in error state: %d, good: %ld, no data: %ld, sc30 reset: %ld, i2c reset: %ld"),
AddLog(LOG_LEVEL_INFO, PSTR("SCD40: (rst) in error state: %d, good: %ld, no data: %ld, sc30 reset: %ld, i2c reset: %ld"),
scd40ErrorState, scd40GoodMeas_count, scd40DataNotAvailable_count, scd40Reset_count, scd40i2cReset_count);
AddLog(LOG_LEVEL_ERROR, PSTR("SCD40: clearing i2c bus"));
AddLog(LOG_LEVEL_INFO, PSTR("SCD40: clearing i2c bus"));
#endif
scd40i2cReset_count++;
error = scd40.clearI2CBus();
if (error) {
scd40ErrorState = SCD40_STATE_ERROR_I2C_RESET;
#ifdef SCD40_DEBUG
AddLog(LOG_LEVEL_ERROR, PSTR("SCD40: error clearing i2c bus: 0x%lX"), error);
AddLog(LOG_LEVEL_INFO, PSTR("SCD40: error clearing i2c bus: 0x%lX"), error);
#endif
} else {
scd40ErrorState = ERROR_SCD40_NO_ERROR;
Expand Down

0 comments on commit a571ca1

Please sign in to comment.