From 66d2a808bccb246c375ef27ee90d8a590b9b5300 Mon Sep 17 00:00:00 2001 From: alchemyEngine Date: Sat, 24 Feb 2024 14:50:35 +0100 Subject: [PATCH 1/2] z_thermal_adjust: fix min_temp reporting Fix perpetual 0.0degC min_temp. Used by front end clients Mainsail and Fluidd. Signed-off-by: Robert Pazdzior --- klippy/extras/z_thermal_adjust.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/klippy/extras/z_thermal_adjust.py b/klippy/extras/z_thermal_adjust.py index 0fa0bff0d..99ea3c006 100644 --- a/klippy/extras/z_thermal_adjust.py +++ b/klippy/extras/z_thermal_adjust.py @@ -42,7 +42,8 @@ class ZThermalAdjuster: pheaters.register_sensor(config, self) self.last_temp = 0. - self.measured_min = self.measured_max = 0. + self.measured_min = 99999999. + self.measured_max = 0. self.smoothed_temp = 0. self.last_temp_time = 0. self.ref_temperature = 0. From ec0af898a233dac3eb68f1fe4741b268f434f563 Mon Sep 17 00:00:00 2001 From: alchemyEngine Date: Sat, 24 Feb 2024 18:54:49 +0100 Subject: [PATCH 2/2] z_thermal_adjust: fix temp initialization Fix initial 0.0degC reading influencing smoothed temperature and initial adjust. Signed-off-by: Robert Pazdzior --- klippy/extras/z_thermal_adjust.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/klippy/extras/z_thermal_adjust.py b/klippy/extras/z_thermal_adjust.py index 99ea3c006..ca9785eb3 100644 --- a/klippy/extras/z_thermal_adjust.py +++ b/klippy/extras/z_thermal_adjust.py @@ -136,15 +136,16 @@ class ZThermalAdjuster: def temperature_callback(self, read_time, temp): 'Called everytime the Z adjust thermistor is read' - with self.lock: - time_diff = read_time - self.last_temp_time - self.last_temp = temp - self.last_temp_time = read_time - temp_diff = temp - self.smoothed_temp - adj_time = min(time_diff * self.inv_smooth_time, 1.) - self.smoothed_temp += temp_diff * adj_time - self.measured_min = min(self.measured_min, self.smoothed_temp) - self.measured_max = max(self.measured_max, self.smoothed_temp) + if temp: + with self.lock: + time_diff = read_time - self.last_temp_time + self.last_temp = temp + self.last_temp_time = read_time + temp_diff = temp - self.smoothed_temp + adj_time = min(time_diff * self.inv_smooth_time, 1.) + self.smoothed_temp += temp_diff * adj_time + self.measured_min = min(self.measured_min, self.smoothed_temp) + self.measured_max = max(self.measured_max, self.smoothed_temp) def get_temp(self, eventtime): return self.smoothed_temp, 0.