temperature_sensors: Define default sensors in new config file

Move the default list of sensor modules from heaters.py to a new
temperature_sensors.cfg config file.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-11-01 11:49:55 -04:00
parent 59314d99e0
commit 596cd21751
2 changed files with 47 additions and 8 deletions

View File

@ -3,7 +3,7 @@
# Copyright (C) 2016-2020 Kevin O'Connor <kevin@koconnor.net>
#
# 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(

View File

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