diff --git a/Adafruit_BME280.cpp b/Adafruit_BME280.cpp index 3be3280..1fab41b 100644 --- a/Adafruit_BME280.cpp +++ b/Adafruit_BME280.cpp @@ -419,7 +419,7 @@ float Adafruit_BME280::readTemperature(void) { ((int32_t)_bme280_calib.dig_T3)) >> 14; - t_fine = var1 + var2; + t_fine = var1 + var2 + t_fine_adjust; float T = (t_fine * 5 + 128) >> 8; return T / 100; @@ -540,6 +540,24 @@ float Adafruit_BME280::seaLevelForAltitude(float altitude, float atmospheric) { */ uint32_t Adafruit_BME280::sensorID(void) { return _sensorID; } +/*! + * Returns the current temperature compensation value in degrees Celcius + * @returns the current temperature compensation value in degrees Celcius + */ +float Adafruit_BME280::getTemperatureAdjustment(void) { + return 0.0; +}; + +/*! + * Sets a value to be added to each temperature reading. This adjusted + * temperature is used in pressure and humidity readings. + * @params adjustment Value to be added to each tempature reading in Celcius + */ +void Adafruit_BME280::setTemperatureAdjustment(float adjustment) { + // convert the value in C into and adjustment to t_fine + t_fine_adjust = ((int32_t(adjustment * 100) << 8)) / 5; +}; + /*! @brief Gets an Adafruit Unified Sensor object for the temp sensor component @return Adafruit_Sensor pointer to temperature sensor diff --git a/Adafruit_BME280.h b/Adafruit_BME280.h index 5721a9a..85b3873 100644 --- a/Adafruit_BME280.h +++ b/Adafruit_BME280.h @@ -234,6 +234,9 @@ public: float seaLevelForAltitude(float altitude, float pressure); uint32_t sensorID(void); + float getTemperatureAdjustment(void); + void setTemperatureAdjustment(float); + Adafruit_Sensor *getTemperatureSensor(void); Adafruit_Sensor *getPressureSensor(void); Adafruit_Sensor *getHumiditySensor(void); @@ -274,6 +277,9 @@ protected: int8_t _miso; //!< for the SPI interface int8_t _sck; //!< for the SPI interface + int32_t t_fine_adjust; //!< add to compensate temp readings and in turn to + //!< pressure and humidity readings + bme280_calib_data _bme280_calib; //!< here calibration data is stored /**************************************************************************/