@@ -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 */
341339float 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 */
365363float 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 */
404402float 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 );
0 commit comments