aboutsummaryrefslogtreecommitdiffstats
path: root/klippy
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2024-06-18 13:01:34 -0400
committerKevin O'Connor <kevin@koconnor.net>2024-06-21 15:32:30 -0400
commitd89722056bf58103dc7fc06bc310ac39afa6aaa0 (patch)
tree7a758d84365dce6ad210a0263d0ad702d9901c20 /klippy
parent9fa0fb1a0ebca3ed4be887417b255b26fc99bbfd (diff)
downloadkutter-d89722056bf58103dc7fc06bc310ac39afa6aaa0.tar.gz
kutter-d89722056bf58103dc7fc06bc310ac39afa6aaa0.tar.xz
kutter-d89722056bf58103dc7fc06bc310ac39afa6aaa0.zip
mcu: Rename setup_minmax() to setup_adc_sample()
Rename this method so that it is more distinct from the the common temperature setup_minmax() method. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy')
-rw-r--r--klippy/extras/adc_scaled.py6
-rw-r--r--klippy/extras/adc_temperature.py8
-rw-r--r--klippy/extras/buttons.py2
-rw-r--r--klippy/extras/hall_filament_width_sensor.py4
-rw-r--r--klippy/extras/temperature_mcu.py23
-rw-r--r--klippy/extras/tsl1401cl_filament_width_sensor.py2
-rw-r--r--klippy/mcu.py4
7 files changed, 24 insertions, 25 deletions
diff --git a/klippy/extras/adc_scaled.py b/klippy/extras/adc_scaled.py
index c2d2cb87..80ea452f 100644
--- a/klippy/extras/adc_scaled.py
+++ b/klippy/extras/adc_scaled.py
@@ -7,7 +7,6 @@
SAMPLE_TIME = 0.001
SAMPLE_COUNT = 8
REPORT_TIME = 0.300
-RANGE_CHECK_COUNT = 4
class MCU_scaled_adc:
def __init__(self, main, pin_params):
@@ -18,7 +17,7 @@ class MCU_scaled_adc:
qname = main.name + ":" + pin_params['pin']
query_adc.register_adc(qname, self._mcu_adc)
self._callback = None
- self.setup_minmax = self._mcu_adc.setup_minmax
+ self.setup_adc_sample = self._mcu_adc.setup_adc_sample
self.get_mcu = self._mcu_adc.get_mcu
def _handle_callback(self, read_time, read_value):
max_adc = self._main.last_vref[1]
@@ -54,8 +53,7 @@ class PrinterADCScaled:
ppins = self.printer.lookup_object('pins')
mcu_adc = ppins.setup_pin('adc', pin_name)
mcu_adc.setup_adc_callback(REPORT_TIME, callback)
- mcu_adc.setup_minmax(SAMPLE_TIME, SAMPLE_COUNT, minval=0., maxval=1.,
- range_check_count=RANGE_CHECK_COUNT)
+ mcu_adc.setup_adc_sample(SAMPLE_TIME, SAMPLE_COUNT)
query_adc = config.get_printer().load_object(config, 'query_adc')
query_adc.register_adc(self.name + ":" + name, mcu_adc)
return mcu_adc
diff --git a/klippy/extras/adc_temperature.py b/klippy/extras/adc_temperature.py
index b76e8c66..260fe281 100644
--- a/klippy/extras/adc_temperature.py
+++ b/klippy/extras/adc_temperature.py
@@ -32,10 +32,10 @@ class PrinterADCtoTemperature:
temp = self.adc_convert.calc_temp(read_value)
self.temperature_callback(read_time + SAMPLE_COUNT * SAMPLE_TIME, temp)
def setup_minmax(self, min_temp, max_temp):
- adc_range = [self.adc_convert.calc_adc(t) for t in [min_temp, max_temp]]
- self.mcu_adc.setup_minmax(SAMPLE_TIME, SAMPLE_COUNT,
- minval=min(adc_range), maxval=max(adc_range),
- range_check_count=RANGE_CHECK_COUNT)
+ arange = [self.adc_convert.calc_adc(t) for t in [min_temp, max_temp]]
+ self.mcu_adc.setup_adc_sample(SAMPLE_TIME, SAMPLE_COUNT,
+ minval=min(arange), maxval=max(arange),
+ range_check_count=RANGE_CHECK_COUNT)
######################################################################
diff --git a/klippy/extras/buttons.py b/klippy/extras/buttons.py
index 70d76a60..daa998a9 100644
--- a/klippy/extras/buttons.py
+++ b/klippy/extras/buttons.py
@@ -104,7 +104,7 @@ class MCU_ADC_buttons:
self.max_value = 0.
ppins = printer.lookup_object('pins')
self.mcu_adc = ppins.setup_pin('adc', self.pin)
- self.mcu_adc.setup_minmax(ADC_SAMPLE_TIME, ADC_SAMPLE_COUNT)
+ self.mcu_adc.setup_adc_sample(ADC_SAMPLE_TIME, ADC_SAMPLE_COUNT)
self.mcu_adc.setup_adc_callback(ADC_REPORT_TIME, self.adc_callback)
query_adc = printer.lookup_object('query_adc')
query_adc.register_adc('adc_button:' + pin.strip(), self.mcu_adc)
diff --git a/klippy/extras/hall_filament_width_sensor.py b/klippy/extras/hall_filament_width_sensor.py
index e0802887..8dab3522 100644
--- a/klippy/extras/hall_filament_width_sensor.py
+++ b/klippy/extras/hall_filament_width_sensor.py
@@ -49,10 +49,10 @@ class HallFilamentWidthSensor:
# Start adc
self.ppins = self.printer.lookup_object('pins')
self.mcu_adc = self.ppins.setup_pin('adc', self.pin1)
- self.mcu_adc.setup_minmax(ADC_SAMPLE_TIME, ADC_SAMPLE_COUNT)
+ self.mcu_adc.setup_adc_sample(ADC_SAMPLE_TIME, ADC_SAMPLE_COUNT)
self.mcu_adc.setup_adc_callback(ADC_REPORT_TIME, self.adc_callback)
self.mcu_adc2 = self.ppins.setup_pin('adc', self.pin2)
- self.mcu_adc2.setup_minmax(ADC_SAMPLE_TIME, ADC_SAMPLE_COUNT)
+ self.mcu_adc2.setup_adc_sample(ADC_SAMPLE_TIME, ADC_SAMPLE_COUNT)
self.mcu_adc2.setup_adc_callback(ADC_REPORT_TIME, self.adc2_callback)
# extrude factor updating
self.extrude_factor_update_timer = self.reactor.register_timer(
diff --git a/klippy/extras/temperature_mcu.py b/klippy/extras/temperature_mcu.py
index 585ec4c1..02d91a3a 100644
--- a/klippy/extras/temperature_mcu.py
+++ b/klippy/extras/temperature_mcu.py
@@ -35,26 +35,27 @@ class PrinterTemperatureMCU:
query_adc.register_adc(config.get_name(), self.mcu_adc)
# Register callbacks
if self.printer.get_start_args().get('debugoutput') is not None:
- self.mcu_adc.setup_minmax(SAMPLE_TIME, SAMPLE_COUNT,
- range_check_count=RANGE_CHECK_COUNT)
+ self.mcu_adc.setup_adc_sample(SAMPLE_TIME, SAMPLE_COUNT)
return
self.printer.register_event_handler("klippy:mcu_identify",
- self._mcu_identify)
+ self.handle_mcu_identify)
+ # Temperature interface
def setup_callback(self, temperature_callback):
self.temperature_callback = temperature_callback
def get_report_time_delta(self):
return REPORT_TIME
- 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 setup_minmax(self, min_temp, max_temp):
self.min_temp = min_temp
self.max_temp = max_temp
+ # Internal code
+ 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_adc(self, temp):
return (temp - self.base_temperature) / self.slope
def calc_base(self, temp, adc):
return temp - adc * self.slope
- def _mcu_identify(self):
+ def handle_mcu_identify(self):
# Obtain mcu information
mcu = self.mcu_adc.get_mcu()
self.debug_read_cmd = mcu.lookup_query_command(
@@ -89,10 +90,10 @@ class PrinterTemperatureMCU:
self.slope = (self.temp2 - self.temp1) / (self.adc2 - self.adc1)
self.base_temperature = self.calc_base(self.temp1, self.adc1)
# Setup min/max checks
- adc_range = [self.calc_adc(t) for t in [self.min_temp, self.max_temp]]
- self.mcu_adc.setup_minmax(SAMPLE_TIME, SAMPLE_COUNT,
- minval=min(adc_range), maxval=max(adc_range),
- range_check_count=RANGE_CHECK_COUNT)
+ arange = [self.calc_adc(t) for t in [self.min_temp, self.max_temp]]
+ self.mcu_adc.setup_adc_sample(SAMPLE_TIME, SAMPLE_COUNT,
+ minval=min(arange), maxval=max(arange),
+ range_check_count=RANGE_CHECK_COUNT)
def config_unknown(self):
raise self.printer.config_error("MCU temperature not supported on %s"
% (self.mcu_type,))
diff --git a/klippy/extras/tsl1401cl_filament_width_sensor.py b/klippy/extras/tsl1401cl_filament_width_sensor.py
index fb2d9713..83480f46 100644
--- a/klippy/extras/tsl1401cl_filament_width_sensor.py
+++ b/klippy/extras/tsl1401cl_filament_width_sensor.py
@@ -33,7 +33,7 @@ class FilamentWidthSensor:
# Start adc
self.ppins = self.printer.lookup_object('pins')
self.mcu_adc = self.ppins.setup_pin('adc', self.pin)
- self.mcu_adc.setup_minmax(ADC_SAMPLE_TIME, ADC_SAMPLE_COUNT)
+ self.mcu_adc.setup_adc_sample(ADC_SAMPLE_TIME, ADC_SAMPLE_COUNT)
self.mcu_adc.setup_adc_callback(ADC_REPORT_TIME, self.adc_callback)
# extrude factor updating
self.extrude_factor_update_timer = self.reactor.register_timer(
diff --git a/klippy/mcu.py b/klippy/mcu.py
index feb4856a..1122ff86 100644
--- a/klippy/mcu.py
+++ b/klippy/mcu.py
@@ -496,8 +496,8 @@ class MCU_adc:
self._inv_max_adc = 0.
def get_mcu(self):
return self._mcu
- def setup_minmax(self, sample_time, sample_count,
- minval=0., maxval=1., range_check_count=0):
+ def setup_adc_sample(self, sample_time, sample_count,
+ minval=0., maxval=1., range_check_count=0):
self._sample_time = sample_time
self._sample_count = sample_count
self._min_sample = minval