1
0
mirror of https://github.com/cmur2/python-bme680.git synced 2024-12-22 22:54:29 +01:00

Refactored get_sensor_data

This commit is contained in:
Phil Howard 2017-10-17 12:32:55 +01:00
parent b2f388a335
commit 73e93bc6d7

View File

@ -228,6 +228,12 @@ class BME680(BME680Data):
self.set_power_mode(FORCED_MODE) self.set_power_mode(FORCED_MODE)
for attempt in range(10): for attempt in range(10):
status = self._get_regs(FIELD0_ADDR, 1)
if (status & NEW_DATA_MSK) == 0:
time.sleep(POLL_PERIOD_MS / 1000.0)
continue
regs = self._get_regs(FIELD0_ADDR, FIELD_LENGTH) regs = self._get_regs(FIELD0_ADDR, FIELD_LENGTH)
self.data.status = regs[0] & NEW_DATA_MSK self.data.status = regs[0] & NEW_DATA_MSK
@ -246,17 +252,14 @@ class BME680(BME680Data):
self.data.heat_stable = (self.data.status & HEAT_STAB_MSK) > 0 self.data.heat_stable = (self.data.status & HEAT_STAB_MSK) > 0
if self.data.status & NEW_DATA_MSK: temperature = self._calc_temperature(adc_temp)
temperature = self._calc_temperature(adc_temp) self.data.temperature = temperature / 100.0
self.data.temperature = temperature / 100.0 self.ambient_temperature = temperature # Saved for heater calc
self.ambient_temperature = temperature # Saved for heater calc
self.data.pressure = self._calc_pressure(adc_pres) / 1000.0 self.data.pressure = self._calc_pressure(adc_pres) / 1000.0
self.data.humidity = self._calc_humidity(adc_hum) / 1000.0 self.data.humidity = self._calc_humidity(adc_hum) / 1000.0
self.data.gas_resistance = self._calc_gas_resistance(adc_gas_res, gas_range) self.data.gas_resistance = self._calc_gas_resistance(adc_gas_res, gas_range)
return True return True
else:
time.sleep(POLL_PERIOD_MS / 1000.0)
return False return False