aboutsummaryrefslogtreecommitdiffstats
path: root/klippy
diff options
context:
space:
mode:
authorfunctionpointer <suspendfunction@gmail.com>2022-06-05 14:26:51 +0200
committerKevin O'Connor <kevin@koconnor.net>2022-06-08 12:39:12 -0400
commit2dc20c011dc0ce7f798ca543b96e93e5014b407b (patch)
tree2c2d337bdcc99cc163d788df0aa35db7db70c451 /klippy
parentb0da191bee873d51590664e261a767a06391df13 (diff)
downloadkutter-2dc20c011dc0ce7f798ca543b96e93e5014b407b.tar.gz
kutter-2dc20c011dc0ce7f798ca543b96e93e5014b407b.tar.xz
kutter-2dc20c011dc0ce7f798ca543b96e93e5014b407b.zip
ds18b20: Allow some read errors
Allows a limited number of DS18B20 read failures before stopping the printer. This is designed to tolerate spurious read errors, while still stopping for serious issues. The printer will stop when the sensor fails to report a value five times in a row. Implementation works as follows: The MCU reports any read errors using a new "fault" parameter in its answers. The Python code tracks the number of errors and triggers the shutdown. This paves the way for more sophisticated error handling in the future, as well as an example for other sensors to follow. Signed-off-by: Lorenzo Pfeifer <Lorenzo.Pfeifer+github@googlemail.com>
Diffstat (limited to 'klippy')
-rw-r--r--klippy/extras/ds18b20.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/klippy/extras/ds18b20.py b/klippy/extras/ds18b20.py
index 749ae520..76e38532 100644
--- a/klippy/extras/ds18b20.py
+++ b/klippy/extras/ds18b20.py
@@ -10,6 +10,7 @@ DS18_REPORT_TIME = 3.0
# Temperature can be sampled at any time but conversion time is ~750ms, so
# setting the time too low will not make the reports come faster.
DS18_MIN_REPORT_TIME = 1.0
+DS18_MAX_CONSECUTIVE_ERRORS = 4
class DS18B20:
def __init__(self, config):
@@ -32,7 +33,7 @@ class DS18B20:
def _build_config(self):
sid = "".join(["%02x" % (x,) for x in self.sensor_id])
self._mcu.add_config_cmd("config_ds18b20 oid=%d serial=%s"
- % (self.oid, sid))
+ % (self.oid, sid, DS18_MAX_CONSECUTIVE_ERRORS))
clock = self._mcu.get_query_slot(self.oid)
self._report_clock = self._mcu.seconds_to_clock(self.report_time)
@@ -44,7 +45,9 @@ class DS18B20:
def _handle_ds18b20_response(self, params):
temp = params['value'] / 1000.0
- if temp < self.min_temp or temp > self.max_temp:
+ if params["fault"] != 0:
+ temp = 0 # read error! report 0C and don't check temp range
+ elif temp < self.min_temp or temp > self.max_temp:
self.printer.invoke_shutdown(
"DS18B20 temperature %0.1f outside range of %0.1f:%.01f"
% (temp, self.min_temp, self.max_temp))