Fixed bug #75
Fixed bug #75, added timeout to "takeForcedMeasurement" and a return value to check the result of the function
This commit is contained in:
parent
2046f417fd
commit
cd435d16fd
|
|
@ -343,21 +343,34 @@ 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() {
|
||||||
|
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());
|
||||||
|
// Store current time to measure the timeout
|
||||||
|
uint32_t timeout_start = millis();
|
||||||
// wait until measurement has been completed, otherwise we would read
|
// wait until measurement has been completed, otherwise we would read
|
||||||
// the values from the last measurement
|
// the values from the last measurement or the timeout occurred after 2 sec.
|
||||||
while (read8(BME280_REGISTER_STATUS) & 0x08)
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Reads the factory-set coefficients
|
* @brief Reads the factory-set coefficients
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
float readTemperature(void);
|
float readTemperature(void);
|
||||||
float readPressure(void);
|
float readPressure(void);
|
||||||
float readHumidity(void);
|
float readHumidity(void);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue