From 955e77d73e57de9844cdf1e4cf21603f8d9a68f2 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Mon, 8 Apr 2024 11:27:42 +0200 Subject: [PATCH 1/6] Update mcu.py --- klippy/mcu.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/klippy/mcu.py b/klippy/mcu.py index a1af42d4c..e34228705 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -829,6 +829,22 @@ def _handle_shutdown(self, params): "max_temp": heater.max_temp, } ) + sensor_names = [ + sensor + for sensor in self._printer.objects + if sensor.startswith("temperature_sensor") + ] + for sensor_name in sensor_names: + sensor = self._printer.lookup_object(sensor_name) + if sensor.is_adc_faulty(): + append_msgs.append( + { + "sensor": sensor.name, + "last_temp": "{:.2f}".format(sensor.last_temp), + "min_temp": sensor.min_temp, + "max_temp": sensor.max_temp, + } + ) self._printer.invoke_async_shutdown( prefix + msg + error_help(msg=msg, append_msgs=append_msgs) From d9a19e34c15749d4ade651bbccc2e14d56cce9c7 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Mon, 8 Apr 2024 11:44:57 +0200 Subject: [PATCH 2/6] Include Temperature_fan --- klippy/extras/temperature_fan.py | 5 +++++ klippy/extras/temperature_sensor.py | 5 +++++ klippy/mcu.py | 18 +++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/klippy/extras/temperature_fan.py b/klippy/extras/temperature_fan.py index da9bc719a..4ad9a7bc9 100644 --- a/klippy/extras/temperature_fan.py +++ b/klippy/extras/temperature_fan.py @@ -91,6 +91,11 @@ def get_status(self, eventtime): status["target"] = self.target_temp return status + def is_adc_faulty(self): + if self.last_temp > self.max_temp or self.last_temp < self.min_temp: + return True + return False + cmd_SET_TEMPERATURE_FAN_TARGET_help = ( "Sets a temperature fan target and fan speed limits" ) diff --git a/klippy/extras/temperature_sensor.py b/klippy/extras/temperature_sensor.py index 873ba3644..0e99e4f7a 100644 --- a/klippy/extras/temperature_sensor.py +++ b/klippy/extras/temperature_sensor.py @@ -45,6 +45,11 @@ def get_status(self, eventtime): "measured_max_temp": round(self.measured_max, 2), } + def is_adc_faulty(self): + if self.last_temp > self.max_temp or self.last_temp < self.min_temp: + return True + return False + def load_config_prefix(config): return PrinterSensorGeneric(config) diff --git a/klippy/mcu.py b/klippy/mcu.py index e34228705..6756e2585 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -832,7 +832,7 @@ def _handle_shutdown(self, params): sensor_names = [ sensor for sensor in self._printer.objects - if sensor.startswith("temperature_sensor") + if (sensor.startswith("temperature_sensor")) ] for sensor_name in sensor_names: sensor = self._printer.lookup_object(sensor_name) @@ -845,6 +845,22 @@ def _handle_shutdown(self, params): "max_temp": sensor.max_temp, } ) + fan_names = [ + fan + for fan in self._printer.objects + if (fan.startswith("temperature_fan")) + ] + for fan_name in fan_names: + fan = self._printer.lookup_object(fan_name) + if fan.is_adc_faulty(): + append_msgs.append( + { + "fan": fan.name, + "last_temp": "{:.2f}".format(fan.last_temp), + "min_temp": fan.min_temp, + "max_temp": fan.max_temp, + } + ) self._printer.invoke_async_shutdown( prefix + msg + error_help(msg=msg, append_msgs=append_msgs) From 50ded4e132f13f12e2ea8c1bfde6968edc526bcd Mon Sep 17 00:00:00 2001 From: Zeanon Date: Mon, 8 Apr 2024 11:46:47 +0200 Subject: [PATCH 3/6] removed ununsed paranthesis --- klippy/mcu.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/klippy/mcu.py b/klippy/mcu.py index 6756e2585..9606123a6 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -832,7 +832,7 @@ def _handle_shutdown(self, params): sensor_names = [ sensor for sensor in self._printer.objects - if (sensor.startswith("temperature_sensor")) + if sensor.startswith("temperature_sensor") ] for sensor_name in sensor_names: sensor = self._printer.lookup_object(sensor_name) @@ -848,7 +848,7 @@ def _handle_shutdown(self, params): fan_names = [ fan for fan in self._printer.objects - if (fan.startswith("temperature_fan")) + if fan.startswith("temperature_fan") ] for fan_name in fan_names: fan = self._printer.lookup_object(fan_name) From 05430ca3736d93d374eb4c23af28b15d4fbc8891 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Mon, 8 Apr 2024 11:48:50 +0200 Subject: [PATCH 4/6] cleaned up the code and removed loops --- klippy/mcu.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/klippy/mcu.py b/klippy/mcu.py index 9606123a6..f04ef6f0e 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -832,35 +832,26 @@ def _handle_shutdown(self, params): sensor_names = [ sensor for sensor in self._printer.objects - if sensor.startswith("temperature_sensor") + if ( + sensor.startswith("temperature_sensor") + or sensor.startswith("temperature_fan") + ) ] for sensor_name in sensor_names: sensor = self._printer.lookup_object(sensor_name) if sensor.is_adc_faulty(): append_msgs.append( { - "sensor": sensor.name, + ( + "sensor" + if sensor_name.starts_with("temperature_sensor") + else "fan" + ): sensor.name, "last_temp": "{:.2f}".format(sensor.last_temp), "min_temp": sensor.min_temp, "max_temp": sensor.max_temp, } ) - fan_names = [ - fan - for fan in self._printer.objects - if fan.startswith("temperature_fan") - ] - for fan_name in fan_names: - fan = self._printer.lookup_object(fan_name) - if fan.is_adc_faulty(): - append_msgs.append( - { - "fan": fan.name, - "last_temp": "{:.2f}".format(fan.last_temp), - "min_temp": fan.min_temp, - "max_temp": fan.max_temp, - } - ) self._printer.invoke_async_shutdown( prefix + msg + error_help(msg=msg, append_msgs=append_msgs) From 4e87e8f5afd2748ceeab41dd92dba1aaf935fbf6 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Mon, 8 Apr 2024 11:58:29 +0200 Subject: [PATCH 5/6] Added Thermocouples --- klippy/mcu.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/klippy/mcu.py b/klippy/mcu.py index f04ef6f0e..1f51cf127 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -813,8 +813,8 @@ def _handle_shutdown(self, params): append_msgs = [] if ( msg.startswith("ADC out of range") - and not get_danger_options.adc_ignore_limits - ): + or msg.startswith("Thermocouple reader fault") + ) and not get_danger_options.adc_ignore_limits: pheaters = self._printer.lookup_object("heaters") heaters = [ pheaters.lookup_heater(n) for n in pheaters.available_heaters @@ -1351,6 +1351,7 @@ def stats(self, eventtime): communication failure between micro-controller and host.""", ( "ADC out of range", + "Thermocouple reader fault", ): """ This generally occurs when a heater temperature exceeds its configured min_temp or max_temp.""", From 74fe607d44733ac9e60c1e74221a98109fbbec1e Mon Sep 17 00:00:00 2001 From: Zeanon Date: Tue, 9 Apr 2024 17:35:29 +0200 Subject: [PATCH 6/6] code cleanup --- klippy/mcu.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/klippy/mcu.py b/klippy/mcu.py index 1f51cf127..33897717d 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -842,11 +842,7 @@ def _handle_shutdown(self, params): if sensor.is_adc_faulty(): append_msgs.append( { - ( - "sensor" - if sensor_name.starts_with("temperature_sensor") - else "fan" - ): sensor.name, + sensor_name.split(" ")[0]: sensor.name, "last_temp": "{:.2f}".format(sensor.last_temp), "min_temp": sensor.min_temp, "max_temp": sensor.max_temp,