aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Hammond <wizhippo@gmail.com>2019-02-25 14:17:05 -0500
committerKevin O'Connor <kevin@koconnor.net>2019-02-26 13:15:56 -0500
commitb6589406d46186bc9ae76a3db49363c5168e30e9 (patch)
tree0e4cbbe8f4fa5635e836da4cc040e3242e39a559
parentf9968904d6c9013b29d77dcdda95f0735308fadd (diff)
downloadkutter-b6589406d46186bc9ae76a3db49363c5168e30e9.tar.gz
kutter-b6589406d46186bc9ae76a3db49363c5168e30e9.tar.xz
kutter-b6589406d46186bc9ae76a3db49363c5168e30e9.zip
temperature_sensor: Add generic temperature sensor support
Signed-off-by: Douglas Hammond <wizhippo@gmail.com> Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--config/example-extras.cfg17
-rw-r--r--klippy/extras/temperature_sensor.py27
-rw-r--r--test/klippy/temperature.cfg6
3 files changed, 44 insertions, 6 deletions
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 <kevin@koconnor.net>
+#
+# 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