diff --git a/klippy/extras/heaters.py b/klippy/extras/heaters.py index e80c5d0c..00c0e593 100644 --- a/klippy/extras/heaters.py +++ b/klippy/extras/heaters.py @@ -3,7 +3,7 @@ # Copyright (C) 2016-2020 Kevin O'Connor # # This file may be distributed under the terms of the GNU GPLv3 license. -import logging, threading +import os, logging, threading ###################################################################### @@ -230,7 +230,7 @@ class PrinterHeaters: self.gcode_id_to_sensor = {} self.available_heaters = [] self.available_sensors = [] - self.has_started = False + self.has_started = self.have_load_sensors = False self.printer.register_event_handler("klippy:ready", self._handle_ready) self.printer.register_event_handler("gcode:request_restart", self.turn_off_all_heaters) @@ -241,6 +241,18 @@ class PrinterHeaters: gcode.register_command("M105", self.cmd_M105, when_not_ready=True) gcode.register_command("TEMPERATURE_WAIT", self.cmd_TEMPERATURE_WAIT, desc=self.cmd_TEMPERATURE_WAIT_help) + def load_config(self, config): + self.have_load_sensors = True + # Load default temperature sensors + pconfig = self.printer.lookup_object('configfile') + dir_name = os.path.dirname(__file__) + filename = os.path.join(dir_name, 'temperature_sensors.cfg') + try: + dconfig = pconfig.read_config(filename) + except Exception: + raise config.config_error("Cannot load config '%s'" % (filename,)) + for c in dconfig.get_prefix_sections(''): + self.printer.load_object(dconfig, c.get_name()) def add_sensor_factory(self, sensor_type, sensor_factory): self.sensor_factories[sensor_type] = sensor_factory def setup_heater(self, config, gcode_id=None): @@ -262,12 +274,8 @@ class PrinterHeaters: "Unknown heater '%s'" % (heater_name,)) return self.heaters[heater_name] def setup_sensor(self, config): - modules = ["thermistor", "adc_temperature", "spi_temperature", - "bme280", "htu21d", "lm75", "temperature_host", - "temperature_mcu", "ds18b20"] - - for module_name in modules: - self.printer.load_object(config, module_name) + if not self.have_load_sensors: + self.load_config(config) sensor_type = config.get('sensor_type') if sensor_type not in self.sensor_factories: raise self.printer.config_error( diff --git a/klippy/extras/temperature_sensors.cfg b/klippy/extras/temperature_sensors.cfg new file mode 100644 index 00000000..db828378 --- /dev/null +++ b/klippy/extras/temperature_sensors.cfg @@ -0,0 +1,31 @@ +# This file loads the default temperature sensors. + +# Load "PT1000", "PT100 INA826", "AD595", "AD597", "AD8494", "AD8495", +# "AD8496", and "AD8497" sensors +[adc_temperature] + +# Load "BME280" sensor +[bme280] + +# Load "DS18B20" sensor +[ds18b20] + +# Load "SI7013", "SI7020", "SI7021", "SHT21", and "HTU21D" sensors +[htu21d] + +# Load "LM75" sensor +[lm75] + +# Load "MAX6675", "MAX31855", "MAX31856", and "MAX31865" sensors +[spi_temperature] + +# Load "temperature_host" sensor +[temperature_host] + +# Load "temperature_mcu" sensor +[temperature_mcu] + +# Load "EPCOS 100K B57560G104F", "ATC Semitec 104GT-2", "NTC 100K beta 3950", +# "Honeywell 100K 135-104LAG-J01", "NTC 100K MGB18-104F39050L32", +# "SliceEngineering 450", and "TDK NTCG104LH104JT1" sensors +[thermistor]