Skip to content

Commit ef712e9

Browse files
authored
Merge pull request #115 from adafruit/dont-return-nans-unnecessarily
Return NaN only if sampling is disabled
2 parents ea299e5 + ba0fe3d commit ef712e9

File tree

5 files changed

+14
-17
lines changed

5 files changed

+14
-17
lines changed

Adafruit_BME280.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ bool Adafruit_BME280::init() {
132132
/*!
133133
* @brief setup sensor with given parameters / settings
134134
*
135-
* This is simply a overload to the normal begin()-function, so SPI users
136-
* don't get confused about the library requiring an address.
137135
* @param mode the power mode to use for the sensor
138136
* @param tempSampling the temp samping rate to use
139137
* @param pressSampling the pressure sampling rate to use
@@ -336,14 +334,14 @@ bool Adafruit_BME280::isReadingCalibration(void) {
336334

337335
/*!
338336
* @brief Returns the temperature from the sensor
339-
* @returns the temperature read from the device
337+
* @returns the temperature read from the device or NaN if sampling off
340338
*/
341339
float Adafruit_BME280::readTemperature(void) {
342340
int32_t var1, var2;
341+
if (_measReg.osrs_t == sensor_sampling::SAMPLING_NONE)
342+
return NAN;
343343

344344
int32_t adc_T = read24(BME280_REGISTER_TEMPDATA);
345-
if (adc_T == 0x800000) // value in case temp measurement was disabled
346-
return NAN;
347345
adc_T >>= 4;
348346

349347
var1 = (int32_t)((adc_T / 8) - ((int32_t)_bme280_calib.dig_T1 * 2));
@@ -360,16 +358,16 @@ float Adafruit_BME280::readTemperature(void) {
360358

361359
/*!
362360
* @brief Returns the pressure from the sensor
363-
* @returns the pressure value (in Pascal) read from the device
361+
* @returns the pressure value (in Pascal) or NaN if sampling off
364362
*/
365363
float Adafruit_BME280::readPressure(void) {
366364
int64_t var1, var2, var3, var4;
365+
if (_measReg.osrs_p == sensor_sampling::SAMPLING_NONE)
366+
return NAN;
367367

368368
readTemperature(); // must be done first to get t_fine
369369

370370
int32_t adc_P = read24(BME280_REGISTER_PRESSUREDATA);
371-
if (adc_P == 0x800000) // value in case pressure measurement was disabled
372-
return NAN;
373371
adc_P >>= 4;
374372

375373
var1 = ((int64_t)t_fine) - 128000;
@@ -399,17 +397,16 @@ float Adafruit_BME280::readPressure(void) {
399397

400398
/*!
401399
* @brief Returns the humidity from the sensor
402-
* @returns the humidity value read from the device
400+
* @returns the humidity value read from the device or NaN if sampling off
403401
*/
404402
float Adafruit_BME280::readHumidity(void) {
405403
int32_t var1, var2, var3, var4, var5;
404+
if (_humReg.osrs_h == sensor_sampling::SAMPLING_NONE)
405+
return NAN;
406406

407407
readTemperature(); // must be done first to get t_fine
408408

409409
int32_t adc_H = read16(BME280_REGISTER_HUMIDDATA);
410-
if (adc_H == 0x8000) // value in case humidity measurement was disabled
411-
return NAN;
412-
413410
var1 = t_fine - ((int32_t)76800);
414411
var2 = (int32_t)(adc_H * 16384);
415412
var3 = (int32_t)(((int32_t)_bme280_calib.dig_H4) * 1048576);

Adafruit_BME280.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,14 @@ class Adafruit_BME280 {
354354
/// unused - don't set
355355
unsigned int none : 5;
356356

357-
// pressure oversampling
357+
// humidity oversampling
358358
// 000 = skipped
359359
// 001 = x1
360360
// 010 = x2
361361
// 011 = x4
362362
// 100 = x8
363363
// 101 and above = x16
364-
unsigned int osrs_h : 3; ///< pressure oversampling
364+
unsigned int osrs_h : 3; ///< humidity oversampling
365365

366366
/// @return combined ctrl hum register
367367
unsigned int get() { return (osrs_h); }

examples/advancedsettings/advancedsettings.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
This is a library for the BME280 humidity, temperature & pressure sensor
33
44
Designed specifically to work with the Adafruit BME280 Breakout
5-
----> http://www.adafruit.com/products/2650
5+
----> http://www.adafruit.com/products/2652
66
77
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
88
to interface. The device's I2C address is either 0x76 or 0x77.

examples/bme280test/bme280test.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
This is a library for the BME280 humidity, temperature & pressure sensor
33
44
Designed specifically to work with the Adafruit BME280 Breakout
5-
----> http://www.adafruit.com/products/2650
5+
----> http://www.adafruit.com/products/2652
66
77
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
88
to interface. The device's I2C address is either 0x76 or 0x77.

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Adafruit BME280 Library
2-
version=2.2.4
2+
version=2.3.0
33
author=Adafruit
44
maintainer=Adafruit <info@adafruit.com>
55
sentence=Arduino library for BME280 sensors.

0 commit comments

Comments
 (0)