Merge pull request #90 from kimi1991/Bugfix-#75

Fixed bug #75
This commit is contained in:
siddacious 2020-10-30 17:06:26 -07:00 committed by GitHub
commit 7da8c0d7d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View File

@ -343,20 +343,32 @@ uint32_t Adafruit_BME280::read24(byte reg) {
/*! /*!
* @brief Take a new measurement (only possible in forced mode) * @brief Take a new measurement (only possible in forced mode)
@returns true in case of success else false
*/ */
void Adafruit_BME280::takeForcedMeasurement() { bool Adafruit_BME280::takeForcedMeasurement(void) {
bool return_value = false;
// If we are in forced mode, the BME sensor goes back to sleep after each // If we are in forced mode, the BME sensor goes back to sleep after each
// measurement and we need to set it to forced mode once at this point, so // measurement and we need to set it to forced mode once at this point, so
// it will take the next measurement and then return to sleep again. // it will take the next measurement and then return to sleep again.
// In normal mode simply does new measurements periodically. // In normal mode simply does new measurements periodically.
if (_measReg.mode == MODE_FORCED) { if (_measReg.mode == MODE_FORCED) {
return_value = true;
// set to forced mode, i.e. "take next measurement" // set to forced mode, i.e. "take next measurement"
write8(BME280_REGISTER_CONTROL, _measReg.get()); write8(BME280_REGISTER_CONTROL, _measReg.get());
// wait until measurement has been completed, otherwise we would read // Store current time to measure the timeout
// the values from the last measurement uint32_t timeout_start = millis();
while (read8(BME280_REGISTER_STATUS) & 0x08) // wait until measurement has been completed, otherwise we would read the
// the values from the last measurement or the timeout occurred after 2 sec.
while (read8(BME280_REGISTER_STATUS) & 0x08) {
// In case of a timeout, stop the while loop
if ((millis() - timeout_start) > 2000) {
return_value = false;
break;
}
delay(1); delay(1);
}
} }
return return_value;
} }
/*! /*!

View File

@ -225,7 +225,7 @@ public:
sensor_filter filter = FILTER_OFF, sensor_filter filter = FILTER_OFF,
standby_duration duration = STANDBY_MS_0_5); standby_duration duration = STANDBY_MS_0_5);
void takeForcedMeasurement(); bool takeForcedMeasurement(void);
float readTemperature(void); float readTemperature(void);
float readPressure(void); float readPressure(void);
float readHumidity(void); float readHumidity(void);