diff --git a/src/Sensors.cpp b/src/Sensors.cpp index d76287bb..65f91946 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -355,7 +355,6 @@ void Sensors::tempRegister(bool isCO2temp) { /** * @brief Set temperature offset for all temperature sensors - * @param offset temperature offset in °C (default 0). * * Positive value for offset to be subtracetd to the temperature. */ @@ -366,6 +365,22 @@ void Sensors::setTempOffset(float offset) { setsen5xTempOffset(toffset); } +/** + * @brief Get temperature offset for Sensirion sensors (from internal sensor in SCD4x and SCD30) + * @return float with the temperature offset. + * Positive value for offset to be subtracetd to the temperature. + */ +float Sensors::getTempOffset() { + float toffset = 0.0; + if (isSensorRegistered(SENSORS::SSCD30)) { + toffset = getSCD30TempOffset(); + } + if (isSensorRegistered(SENSORS::SSCD4X)) { + toffset = getSCD4xTempOffset(); + } + return toffset; +} + /// get Gas resistance value of BMP680 sensor float Sensors::getGas() { return gas; } @@ -1586,6 +1601,8 @@ void Sensors::CO2scd30Init() { #endif delay(10); + sensorRegister(SENSORS::SSCD30); + DEBUG("-->[SLIB] SCD30 Temp offset\t:", String(scd30.getTemperatureOffset()).c_str()); DEBUG("-->[SLIB] SCD30 Altitude offset\t:", String(scd30.getAltitudeOffset()).c_str()); @@ -1595,11 +1612,11 @@ void Sensors::CO2scd30Init() { delay(10); } - if (uint16_t((scd30.getTemperatureOffset() * 100)) != (uint16_t(toffset * 100))) { + if (uint16_t((scd30.getTemperatureOffset())) != (uint16_t(toffset * 100))) { + DEBUG("-->[SLIB] SCD30 Temp offset to\t:", String(toffset).c_str()); setSCD30TempOffset(toffset); delay(10); } - sensorRegister(SENSORS::SSCD30); } /// set SCD30 temperature compensation @@ -1610,6 +1627,16 @@ void Sensors::setSCD30TempOffset(float offset) { } } +/// get SCD30 temperature compensation +float Sensors::getSCD30TempOffset() { + float offset = 0.0; + if (isSensorRegistered(SENSORS::SSCD30)) { + offset = scd30.getTemperatureOffset() / 100.0; + Serial.println("-->[SLIB] SCD30 get temp offset\t: " + String(offset)); + } + return offset; +} + /// set SCD30 altitude compensation void Sensors::setSCD30AltitudeOffset(float offset) { if (isSensorRegistered(SENSORS::SSCD30)) { @@ -1627,6 +1654,7 @@ void Sensors::CO2scd4xInit() { scd4x.begin(Wire); error = scd4x.stopPeriodicMeasurement(); if (error) return; + sensorRegister(SENSORS::SSCD4X); scd4x.getTemperatureOffset(tTemperatureOffset); scd4x.getSensorAltitude(tSensorAltitude); DEBUG("-->[SLIB] SCD4x Temp offset\t:", String(tTemperatureOffset).c_str()); @@ -1637,12 +1665,11 @@ void Sensors::CO2scd4xInit() { offsetDifference = abs((toffset * 100) - (tTemperatureOffset * 100)); if (offsetDifference > 0.5) { // Accounts for SCD4x conversion rounding errors in temperature offset - Serial.println("-->[SLIB] SCD4x new offset\t: Temp offset to" + String(toffset)); + Serial.println("-->[SLIB] SCD4x new offset\t: Temp offset to " + String(toffset)); setSCD4xTempOffset(toffset); } error = scd4x.startPeriodicMeasurement(); if (error) DEBUG("[W][SLIB] SCD4x periodic measure\t: starting error:", String(error).c_str()); - sensorRegister(SENSORS::SSCD4X); } /// set SCD4x temperature compensation @@ -1656,6 +1683,32 @@ void Sensors::setSCD4xTempOffset(float offset) { } } +/// get SCD4x temperature compensation +float Sensors::getSCD4xTempOffset() { + float offset = 0.0; + uint16_t error; + if (isSensorRegistered(SENSORS::SSCD4X)) { + scd4x.stopPeriodicMeasurement(); + if (error) { + DEBUG("[SLIB] SCD4x stopPeriodicMeasurement()\t: error:", String(error).c_str()); + return 0.0; + } else { + DEBUG("[SLIB] SCD4x stopPeriodicMeasurement()\t: done!"); + } + error = scd4x.getTemperatureOffset(offset); + if (error) { + DEBUG("[SLIB] SCD4x get temp offset\t: error:", String(error).c_str()); + return 0.0; + } + error = scd4x.startPeriodicMeasurement(); + if (error) { + DEBUG("[SLIB] SCD4x startPeriodicMeasurement()\t: error:", String(error).c_str()); + return 0.0; + } + } + return offset; +} + /// set SCD4x altitude compensation void Sensors::setSCD4xAltitudeOffset(float offset) { if (isSensorRegistered(SENSORS::SSCD4X)) { diff --git a/src/Sensors.hpp b/src/Sensors.hpp index cb048029..8b78ed58 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -306,6 +306,8 @@ class Sensors { void setTempOffset(float offset); + float getTempOffset(); + void setCO2AltitudeOffset(float altitude); void setSeaLevelPressure(float hpa); @@ -419,6 +421,7 @@ class Sensors { void CO2scd30Init(); void CO2scd30Read(); void setSCD30TempOffset(float offset); + float getSCD30TempOffset(); void setSCD30AltitudeOffset(float offset); void CO2correctionAlt(); float hpaCalculation(float altitude); @@ -426,6 +429,7 @@ class Sensors { void CO2scd4xInit(); void CO2scd4xRead(); void setSCD4xTempOffset(float offset); + float getSCD4xTempOffset(); void setSCD4xAltitudeOffset(float offset); void sen5xInit();