From 626dc5b0bdf48df8474fd6040f5f3e5e84ace106 Mon Sep 17 00:00:00 2001 From: Jason Mansfield Date: Sat, 1 Aug 2020 23:14:32 -0700 Subject: [PATCH 1/6] Provide temperature compensation #84 --- Adafruit_BME280.cpp | 20 +++++++++++++++++++- Adafruit_BME280.h | 6 ++++++ 2 files changed, 25 insertions(+), 1 deletion(-) 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 /**************************************************************************/ From 643b75ffa3f65f8b45d5edf42e365f8b2ed94580 Mon Sep 17 00:00:00 2001 From: Jason Mansfield Date: Sat, 1 Aug 2020 23:34:21 -0700 Subject: [PATCH 2/6] complete t_fine_adjust getter --- Adafruit_BME280.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_BME280.cpp b/Adafruit_BME280.cpp index 1fab41b..8886360 100644 --- a/Adafruit_BME280.cpp +++ b/Adafruit_BME280.cpp @@ -545,7 +545,7 @@ uint32_t Adafruit_BME280::sensorID(void) { return _sensorID; } * @returns the current temperature compensation value in degrees Celcius */ float Adafruit_BME280::getTemperatureAdjustment(void) { - return 0.0; + return float(((t_fine_adjust*5)>>8)/100); }; /*! From 938e0990063c5fd5f68817c3265376cf19e02987 Mon Sep 17 00:00:00 2001 From: Jason Mansfield Date: Sun, 2 Aug 2020 17:40:12 -0700 Subject: [PATCH 3/6] temperature adjustment: rename getter/setter adjustment -> compensation --- Adafruit_BME280.cpp | 4 ++-- Adafruit_BME280.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Adafruit_BME280.cpp b/Adafruit_BME280.cpp index 8886360..f55e234 100644 --- a/Adafruit_BME280.cpp +++ b/Adafruit_BME280.cpp @@ -544,7 +544,7 @@ 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) { +float Adafruit_BME280::getTemperatureCompensation(void) { return float(((t_fine_adjust*5)>>8)/100); }; @@ -553,7 +553,7 @@ float Adafruit_BME280::getTemperatureAdjustment(void) { * 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) { +void Adafruit_BME280::setTemperatureCompensation(float adjustment) { // convert the value in C into and adjustment to t_fine t_fine_adjust = ((int32_t(adjustment * 100) << 8)) / 5; }; diff --git a/Adafruit_BME280.h b/Adafruit_BME280.h index 85b3873..a11ce9e 100644 --- a/Adafruit_BME280.h +++ b/Adafruit_BME280.h @@ -234,8 +234,8 @@ public: float seaLevelForAltitude(float altitude, float pressure); uint32_t sensorID(void); - float getTemperatureAdjustment(void); - void setTemperatureAdjustment(float); + float getTemperatureCompensation(void); + void setTemperatureCompensation(float); Adafruit_Sensor *getTemperatureSensor(void); Adafruit_Sensor *getPressureSensor(void); From 4e70835d58b84574453ee93a7467242b6ff861ae Mon Sep 17 00:00:00 2001 From: Jason Mansfield Date: Sun, 2 Aug 2020 20:20:01 -0700 Subject: [PATCH 4/6] format files with `clang-format -i` --- Adafruit_BME280.cpp | 2 +- Adafruit_BME280.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_BME280.cpp b/Adafruit_BME280.cpp index f55e234..4c22646 100644 --- a/Adafruit_BME280.cpp +++ b/Adafruit_BME280.cpp @@ -545,7 +545,7 @@ uint32_t Adafruit_BME280::sensorID(void) { return _sensorID; } * @returns the current temperature compensation value in degrees Celcius */ float Adafruit_BME280::getTemperatureCompensation(void) { - return float(((t_fine_adjust*5)>>8)/100); + return float(((t_fine_adjust * 5) >> 8) / 100); }; /*! diff --git a/Adafruit_BME280.h b/Adafruit_BME280.h index a11ce9e..30bac3e 100644 --- a/Adafruit_BME280.h +++ b/Adafruit_BME280.h @@ -278,7 +278,7 @@ protected: 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 + //!< pressure and humidity readings bme280_calib_data _bme280_calib; //!< here calibration data is stored From 9ef406a5309ffa6035da4f94297f35120be0c1a0 Mon Sep 17 00:00:00 2001 From: Jason Mansfield Date: Mon, 3 Aug 2020 13:57:10 -0700 Subject: [PATCH 5/6] initialize t_fine_adjust to 0 --- Adafruit_BME280.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_BME280.h b/Adafruit_BME280.h index 30bac3e..eec27da 100644 --- a/Adafruit_BME280.h +++ b/Adafruit_BME280.h @@ -277,8 +277,8 @@ 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 + int32_t t_fine_adjust = 0; //!< add to compensate temp readings and in turn + //!< to pressure and humidity readings bme280_calib_data _bme280_calib; //!< here calibration data is stored From 25f8d5e5558f8fbd3ae81f47dd11c1d2c47ad338 Mon Sep 17 00:00:00 2001 From: Jason Mansfield Date: Mon, 3 Aug 2020 23:21:57 -0700 Subject: [PATCH 6/6] Fix @params -> @param --- Adafruit_BME280.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_BME280.cpp b/Adafruit_BME280.cpp index 4c22646..6d58509 100644 --- a/Adafruit_BME280.cpp +++ b/Adafruit_BME280.cpp @@ -551,7 +551,7 @@ float Adafruit_BME280::getTemperatureCompensation(void) { /*! * 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 + * @param adjustment Value to be added to each tempature reading in Celcius */ void Adafruit_BME280::setTemperatureCompensation(float adjustment) { // convert the value in C into and adjustment to t_fine