SCD40 ready for virtual I2C (#22443)

This commit is contained in:
s-hadinger 2024-11-07 21:21:01 +01:00 committed by GitHub
parent 94c45689a6
commit a571ca1db5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 11 deletions

View File

@ -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

View File

@ -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
@ -173,13 +173,13 @@ 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;
@ -187,7 +187,7 @@ void Scd40Update(void)
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;
}
@ -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 {
@ -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;