Skip to content

Commit

Permalink
Merge pull request #75 from FoamyGuy/dont_block_forever
Browse files Browse the repository at this point in the history
timeout if we don't receive new data after too long
  • Loading branch information
ladyada authored Nov 7, 2024
2 parents b369946 + a04e9ed commit 4c14417
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions adafruit_bme680.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,13 @@ def _perform_reading(self) -> None:
ctrl = (ctrl & 0xFC) | 0x01 # enable single shot!
self._write(_BME680_REG_CTRL_MEAS, [ctrl])
new_data = False
start_time = time.monotonic()
while not new_data:
data = self._read(_BME680_REG_MEAS_STATUS, 17)
new_data = data[0] & 0x80 != 0
time.sleep(0.005)
if start_time >= time.monotonic() - 3.0:
raise RuntimeError("Timeout while reading sensor data")
self._last_reading = time.monotonic()

self._adc_pres = _read24(data[2:5]) / 16
Expand Down

2 comments on commit 4c14417

@mtetcs
Copy link

@mtetcs mtetcs commented on 4c14417 Nov 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this will raise immediately. Should this be:

        timeout = time.monotonic() + 3
        while not new_data:
            data = self._read(_BME680_REG_MEAS_STATUS, 17)
            new_data = data[0] & 0x80 != 0
            time.sleep(0.005)
            if time.monotonic() >= timeout:
                raise RuntimeError("Timeout while reading sensor data")

@caternuson
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was fixed in a subsequent PR:
#77

Please sign in to comment.