diff --git a/config/example-extras.cfg b/config/example-extras.cfg index 7aea28ee..7e239f09 100644 --- a/config/example-extras.cfg +++ b/config/example-extras.cfg @@ -1325,7 +1325,22 @@ #min_extrude_temp: #min_temp: #max_temp: -# See the example.cfg for the definition of the above parameters. +# See the heater section in example.cfg for the definition of the +# above parameters. + +# Temperature sensors. One can define any number of temperature +# sensors. Their values are reported via the M105 command. +#[temperature_sensor my_sensor] +#sensor_type: +#sensor_pin: +#min_temp: +#max_temp: +# See the heater section in example.cfg for the definition of the +# above parameters. +#gcode_id: +# See the heater_generic section above for the definition of this +# parameter. + # Pause/Resume functionality with support of position capture and restore #[pause_resume] diff --git a/klippy/extras/temperature_sensor.py b/klippy/extras/temperature_sensor.py new file mode 100644 index 00000000..c4f2c9e0 --- /dev/null +++ b/klippy/extras/temperature_sensor.py @@ -0,0 +1,27 @@ +# Support generic temperature sensors +# +# Copyright (C) 2019 Kevin O'Connor +# +# This file may be distributed under the terms of the GNU GPLv3 license. + +KELVIN_TO_CELCIUS = -273.15 + +class PrinterSensorGeneric: + def __init__(self, config): + self.printer = config.get_printer() + self.sensor = self.printer.lookup_object('heater').setup_sensor(config) + self.min_temp = config.getfloat('min_temp', KELVIN_TO_CELCIUS, + minval=KELVIN_TO_CELCIUS) + self.max_temp = config.getfloat('max_temp', 99999999.9, + above=self.min_temp) + self.sensor.setup_minmax(self.min_temp, self.max_temp) + self.sensor.setup_callback(self.temperature_callback) + self.printer.lookup_object('heater').register_sensor(config, self) + self.last_temp = 0. + def temperature_callback(self, read_time, temp): + self.last_temp = temp + def get_temp(self, eventtime): + return self.last_temp, 0. + +def load_config_prefix(config): + return PrinterSensorGeneric(config) diff --git a/test/klippy/temperature.cfg b/test/klippy/temperature.cfg index b4a75e3c..a1e28541 100644 --- a/test/klippy/temperature.cfg +++ b/test/klippy/temperature.cfg @@ -125,11 +125,7 @@ resistance2: 2000 temperature3: 250 resistance3: 3000 -[temperature_fan test_custom_resistance_adc] -pin: ar17 -min_temp: 0 -max_temp: 100 -control: watermark +[temperature_sensor test_custom_resistance_adc] sensor_type: my_custom_resistance_adc sensor_pin: analog5