aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/sht3x.py
diff options
context:
space:
mode:
Diffstat (limited to 'klippy/extras/sht3x.py')
-rw-r--r--klippy/extras/sht3x.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/klippy/extras/sht3x.py b/klippy/extras/sht3x.py
index 5a8785e8..79cd7bfe 100644
--- a/klippy/extras/sht3x.py
+++ b/klippy/extras/sht3x.py
@@ -56,6 +56,7 @@ class SHT3X:
self.reactor = self.printer.get_reactor()
self.i2c = bus.MCU_I2C_from_config(
config, default_addr=SHT3X_I2C_ADDR, default_speed=100000)
+ self._error = self.i2c.get_mcu().error
self.report_time = config.getint('sht3x_report_time', 1, minval=1)
self.deviceId = config.get('sensor_type')
self.temp = self.min_temp = self.max_temp = self.humidity = 0.
@@ -105,7 +106,20 @@ class SHT3X:
def _sample_sht3x(self, eventtime):
try:
# Read measurment
- params = self.i2c.i2c_read(SHT3X_CMD['OTHER']['FETCH'], 6)
+ retries = 5
+ params = None
+ error = None
+ while retries > 0 and params is None:
+ try:
+ params = self.i2c.i2c_read(
+ SHT3X_CMD['OTHER']['FETCH'], 6, retry=False
+ )
+ except self._error as e:
+ error = e
+ self.reactor.pause(self.reactor.monotonic() + .5)
+ retries -= 1
+ if params is None:
+ raise error
response = bytearray(params['response'])
rtemp = response[0] << 8