From 5a2fd1009d327b8d7b3a1a00bb8bf9eec3208911 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 14 Feb 2026 12:43:28 -0500 Subject: [PATCH] mcu: Change MCU_adc.get_last_value() to return (time, value) Change the get_last_value() method to return time first then value (instead of value, then time). This makes get_last_value() match the order of parameters that is used in the adc update callback. This also fixes ads1x1x to return the "print_time" instead of a system time. Signed-off-by: Kevin O'Connor --- klippy/extras/adc_scaled.py | 2 +- klippy/extras/adc_temperature.py | 2 +- klippy/extras/ads1x1x.py | 8 ++++---- klippy/extras/query_adc.py | 2 +- klippy/mcu.py | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/klippy/extras/adc_scaled.py b/klippy/extras/adc_scaled.py index 80ea452f3..4fe83b984 100644 --- a/klippy/extras/adc_scaled.py +++ b/klippy/extras/adc_scaled.py @@ -23,7 +23,7 @@ class MCU_scaled_adc: max_adc = self._main.last_vref[1] min_adc = self._main.last_vssa[1] scaled_val = (read_value - min_adc) / (max_adc - min_adc) - self._last_state = (scaled_val, read_time) + self._last_state = (read_time, scaled_val) self._callback(read_time, scaled_val) def setup_adc_callback(self, report_time, callback): self._callback = callback diff --git a/klippy/extras/adc_temperature.py b/klippy/extras/adc_temperature.py index c53ae7056..7915502b8 100644 --- a/klippy/extras/adc_temperature.py +++ b/klippy/extras/adc_temperature.py @@ -57,7 +57,7 @@ class HelperTemperatureDiagnostics: def _clarify_adc_range(self, msg, details): if self.min_temp is None: return None - last_value, last_read_time = self.mcu_adc.get_last_value() + last_read_time, last_value = self.mcu_adc.get_last_value() if not last_read_time: return None if last_value >= self.min_adc and last_value <= self.max_adc: diff --git a/klippy/extras/ads1x1x.py b/klippy/extras/ads1x1x.py index bcdbaf698..4c9caa377 100644 --- a/klippy/extras/ads1x1x.py +++ b/klippy/extras/ads1x1x.py @@ -361,10 +361,10 @@ class ADS1X1X_pin: self.invalid_count = 0 # Publish result - measured_time = self._reactor.monotonic() - self._last_state = (target_value, measured_time) - self.callback(self.chip.mcu.estimated_print_time(measured_time), - target_value) + systime = self._reactor.monotonic() + measured_time = self.chip.mcu.estimated_print_time(systime) + self._last_state = (measured_time, target_value) + self.callback(measured_time, target_value) else: self.invalid_count = self.invalid_count + 1 self.check_invalid() diff --git a/klippy/extras/query_adc.py b/klippy/extras/query_adc.py index 2102aaf8f..55e509a0f 100644 --- a/klippy/extras/query_adc.py +++ b/klippy/extras/query_adc.py @@ -21,7 +21,7 @@ class QueryADC: msg = "Available ADC objects: %s" % (', '.join(objs),) gcmd.respond_info(msg) return - value, timestamp = self.adc[name].get_last_value() + timestamp, value = self.adc[name].get_last_value() msg = 'ADC object "%s" has value %.6f (timestamp %.3f)' % ( name, value, timestamp) pullup = gcmd.get_float('PULLUP', None, above=0.) diff --git a/klippy/mcu.py b/klippy/mcu.py index 02c17a067..879817116 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -601,7 +601,7 @@ class MCU_adc: next_clock = self._mcu.clock32_to_clock64(params['next_clock']) last_read_clock = next_clock - self._report_clock last_read_time = self._mcu.clock_to_print_time(last_read_clock) - self._last_state = (last_value, last_read_time) + self._last_state = (last_read_time, last_value) if self._callback is not None: self._callback(last_read_time, last_value) def _handle_analog_in_state(self, params): @@ -610,7 +610,7 @@ class MCU_adc: next_clock = self._mcu.clock32_to_clock64(params['next_clock']) last_read_clock = next_clock - self._report_clock last_read_time = self._mcu.clock_to_print_time(last_read_clock) - self._last_state = (last_value, last_read_time) + self._last_state = (last_read_time, last_value) if self._callback is not None: self._callback(last_read_time, last_value)