temperature_sensor: Add generic temperature sensor support

Signed-off-by: Douglas Hammond <wizhippo@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Douglas Hammond 2019-02-25 14:17:05 -05:00 committed by Kevin O'Connor
parent f9968904d6
commit b6589406d4
3 changed files with 44 additions and 6 deletions

View File

@ -1325,7 +1325,22 @@
#min_extrude_temp: #min_extrude_temp:
#min_temp: #min_temp:
#max_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 functionality with support of position capture and restore
#[pause_resume] #[pause_resume]

View File

@ -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)

View File

@ -125,11 +125,7 @@ resistance2: 2000
temperature3: 250 temperature3: 250
resistance3: 3000 resistance3: 3000
[temperature_fan test_custom_resistance_adc] [temperature_sensor test_custom_resistance_adc]
pin: ar17
min_temp: 0
max_temp: 100
control: watermark
sensor_type: my_custom_resistance_adc sensor_type: my_custom_resistance_adc
sensor_pin: analog5 sensor_pin: analog5