From b23346a521b4b6e671ceecd85ce04ef5a03a644b Mon Sep 17 00:00:00 2001 From: Arksine Date: Fri, 14 Feb 2020 14:22:37 -0500 Subject: [PATCH] bme280: handle read timeout exceptions Signed-off-by: Eric Callahan --- klippy/extras/bme280.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/klippy/extras/bme280.py b/klippy/extras/bme280.py index a5f1bf6f..0809ac6d 100644 --- a/klippy/extras/bme280.py +++ b/klippy/extras/bme280.py @@ -111,13 +111,20 @@ class BME280: meas = self.os_temp << 5 | self.os_pres << 2 | MODE self.write_register('CTRL_MEAS', meas) - # wait until results are ready - status = self.read_register('STATUS', 1)[0] - while status & STATUS_MEASURING: - self.reactor.pause(self.reactor.monotonic() + self.max_sample_time) + try: + # wait until results are ready status = self.read_register('STATUS', 1)[0] + while status & STATUS_MEASURING: + self.reactor.pause( + self.reactor.monotonic() + self.max_sample_time) + status = self.read_register('STATUS', 1)[0] + + data = self.read_register('PRESSURE_MSB', 8) + except Exception: + logging.exception("BME280: Error reading data") + self.temp = self.pressure = self.humidity = .0 + return self.reactor.NEVER - data = self.read_register('PRESSURE_MSB', 8) pressure_raw = (data[0] << 12) | (data[1] << 4) | (data[2] >> 4) temp_raw = (data[3] << 12) | (data[4] << 4) | (data[5] >> 4) humid_raw = (data[6] << 8) | data[7]