aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/temperature_mcu.py
diff options
context:
space:
mode:
Diffstat (limited to 'klippy/extras/temperature_mcu.py')
-rw-r--r--klippy/extras/temperature_mcu.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/klippy/extras/temperature_mcu.py b/klippy/extras/temperature_mcu.py
index 02d91a3a..be2cd145 100644
--- a/klippy/extras/temperature_mcu.py
+++ b/klippy/extras/temperature_mcu.py
@@ -1,10 +1,11 @@
# Support for micro-controller chip based temperature sensors
#
-# Copyright (C) 2020 Kevin O'Connor <kevin@koconnor.net>
+# Copyright (C) 2020-2024 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
import mcu
+from . import adc_temperature
SAMPLE_TIME = 0.001
SAMPLE_COUNT = 8
@@ -31,8 +32,8 @@ class PrinterTemperatureMCU:
self.mcu_adc = ppins.setup_pin('adc',
'%s:ADC_TEMPERATURE' % (mcu_name,))
self.mcu_adc.setup_adc_callback(REPORT_TIME, self.adc_callback)
- query_adc = config.get_printer().load_object(config, 'query_adc')
- query_adc.register_adc(config.get_name(), self.mcu_adc)
+ self.diag_helper = adc_temperature.HelperTemperatureDiagnostics(
+ config, self.mcu_adc, self.calc_temp)
# Register callbacks
if self.printer.get_start_args().get('debugoutput') is not None:
self.mcu_adc.setup_adc_sample(SAMPLE_TIME, SAMPLE_COUNT)
@@ -51,6 +52,8 @@ class PrinterTemperatureMCU:
def adc_callback(self, read_time, read_value):
temp = self.base_temperature + read_value * self.slope
self.temperature_callback(read_time + SAMPLE_COUNT * SAMPLE_TIME, temp)
+ def calc_temp(self, adc):
+ return self.base_temperature + adc * self.slope
def calc_adc(self, temp):
return (temp - self.base_temperature) / self.slope
def calc_base(self, temp, adc):
@@ -91,9 +94,12 @@ class PrinterTemperatureMCU:
self.base_temperature = self.calc_base(self.temp1, self.adc1)
# Setup min/max checks
arange = [self.calc_adc(t) for t in [self.min_temp, self.max_temp]]
+ min_adc, max_adc = sorted(arange)
self.mcu_adc.setup_adc_sample(SAMPLE_TIME, SAMPLE_COUNT,
- minval=min(arange), maxval=max(arange),
+ minval=min_adc, maxval=max_adc,
range_check_count=RANGE_CHECK_COUNT)
+ self.diag_helper.setup_diag_minmax(self.min_temp, self.max_temp,
+ min_adc, max_adc)
def config_unknown(self):
raise self.printer.config_error("MCU temperature not supported on %s"
% (self.mcu_type,))