bme680: fix infinite data wait

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
This commit is contained in:
Timofey Titovets
2025-10-24 01:18:30 +02:00
committed by KevinOConnor
parent 39ac48339a
commit edaa61471f

View File

@@ -87,8 +87,8 @@ MODE_PERIODIC = 3
RUN_GAS = 1 << 4 RUN_GAS = 1 << 4
NB_CONV_0 = 0 NB_CONV_0 = 0
EAS_NEW_DATA = 1 << 7 EAS_NEW_DATA = 1 << 7
GAS_DONE = 1 << 6 GAS_IN_PROGRESS = 1 << 6
MEASURE_DONE = 1 << 5 MEASURE_IN_PROGRESS = 1 << 5
RESET_CHIP_VALUE = 0xB6 RESET_CHIP_VALUE = 0xB6
BME_CHIPS = { BME_CHIPS = {
@@ -511,14 +511,6 @@ class BME280:
return comp_press return comp_press
def _sample_bme680(self, eventtime): def _sample_bme680(self, eventtime):
def data_ready(stat, run_gas):
new_data = (stat & EAS_NEW_DATA)
gas_done = not (stat & GAS_DONE)
meas_done = not (stat & MEASURE_DONE)
if not run_gas:
gas_done = True
return new_data and gas_done and meas_done
run_gas = False run_gas = False
# Check VOC once a while # Check VOC once a while
if self.reactor.monotonic() - self.last_gas_time > 3: if self.reactor.monotonic() - self.last_gas_time > 3:
@@ -536,11 +528,14 @@ class BME280:
try: try:
# wait until results are ready # wait until results are ready
status = self.read_register('EAS_STATUS_0', 1)[0] status = self.read_register('EAS_STATUS_0', 1)[0]
while not data_ready(status, run_gas): while status & MEASURE_IN_PROGRESS:
self.reactor.pause( self.reactor.pause(
self.reactor.monotonic() + self.max_sample_time) self.reactor.monotonic() + self.max_sample_time)
status = self.read_register('EAS_STATUS_0', 1)[0] status = self.read_register('EAS_STATUS_0', 1)[0]
# Nothing in progress and no new data
if not status & EAS_NEW_DATA:
return self.reactor.monotonic() + REPORT_TIME
data = self.read_register('PRESSURE_MSB', 8) data = self.read_register('PRESSURE_MSB', 8)
gas_data = [0, 0] gas_data = [0, 0]
if run_gas: if run_gas: