From 6e79152f47b67a7090d57efe93cb6b7219a9ea55 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 1 Feb 2021 11:30:27 -0500 Subject: [PATCH] htu21d: Implement support for min_temp/max_temp checks Signed-off-by: Kevin O'Connor --- klippy/extras/htu21d.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/klippy/extras/htu21d.py b/klippy/extras/htu21d.py index 2a7237da..571642de 100644 --- a/klippy/extras/htu21d.py +++ b/klippy/extras/htu21d.py @@ -92,7 +92,7 @@ class HTU21D: raise config.error("Invalid HTU21D Resolution. Valid are %s" % '|'.join(HTU21D_RESOLUTIONS.keys())) self.deviceId = config.get('sensor_type') - self.temp = self.humidity = 0. + self.temp = self.min_temp = self.max_temp = self.humidity = 0. self.sample_timer = self.reactor.register_timer(self._sample_htu21d) self.printer.add_object("htu21d " + self.name, self) self.printer.register_event_handler("klippy:connect", @@ -103,7 +103,8 @@ class HTU21D: self.reactor.update_timer(self.sample_timer, self.reactor.NOW) def setup_minmax(self, min_temp, max_temp): - pass + self.min_temp = min_temp + self.max_temp = max_temp def setup_callback(self, cb): self._callback = cb @@ -211,6 +212,11 @@ class HTU21D: self.temp = self.humidity = .0 return self.reactor.NEVER + if self.temp < self.min_temp or self.temp > self.max_temp: + self.printer.invoke_shutdown( + "HTU21D temperature %0.1f outside range of %0.1f:%.01f" + % (self.temp, self.min_temp, self.max_temp)) + measured_time = self.reactor.monotonic() print_time = self.i2c.get_mcu().estimated_print_time(measured_time) self._callback(print_time, self.temp)