diff --git a/klippy/extras/adc_temperature.py b/klippy/extras/adc_temperature.py index 0ec13776..f00ba778 100644 --- a/klippy/extras/adc_temperature.py +++ b/klippy/extras/adc_temperature.py @@ -273,7 +273,7 @@ PT1000 = [ def load_config(config): # Register default sensors - pheater = config.get_printer().lookup_object("heater") + pheaters = config.get_printer().try_load_module(config, "heaters") for sensor_type, params in [("AD595", AD595), ("AD8494", AD8494), ("AD8495", AD8495), @@ -282,17 +282,17 @@ def load_config(config): ("PT100 INA826", PT100)]: func = (lambda config, params=params: PrinterADCtoTemperature(config, LinearVoltage(config, params))) - pheater.add_sensor_factory(sensor_type, func) + pheaters.add_sensor_factory(sensor_type, func) for sensor_type, params in [("PT1000", PT1000)]: func = (lambda config, params=params: PrinterADCtoTemperature(config, LinearResistance(config, params))) - pheater.add_sensor_factory(sensor_type, func) + pheaters.add_sensor_factory(sensor_type, func) def load_config_prefix(config): if config.get("resistance1", None) is None: custom_sensor = CustomLinearVoltage(config) else: custom_sensor = CustomLinearResistance(config) - pheater = config.get_printer().lookup_object("heater") - pheater.add_sensor_factory(custom_sensor.name, custom_sensor.create) + pheaters = config.get_printer().try_load_module(config, "heaters") + pheaters.add_sensor_factory(custom_sensor.name, custom_sensor.create) diff --git a/klippy/extras/bme280.py b/klippy/extras/bme280.py index 0809ac6d..f5fba66e 100644 --- a/klippy/extras/bme280.py +++ b/klippy/extras/bme280.py @@ -198,5 +198,5 @@ class BME280: def load_config(config): # Register sensor - pheater = config.get_printer().lookup_object("heater") - pheater.add_sensor_factory("BME280", BME280) + pheaters = config.get_printer().try_load_module(config, "heaters") + pheaters.add_sensor_factory("BME280", BME280) diff --git a/klippy/extras/controller_fan.py b/klippy/extras/controller_fan.py index adf78ccc..ccd617a2 100644 --- a/klippy/extras/controller_fan.py +++ b/klippy/extras/controller_fan.py @@ -14,6 +14,7 @@ class ControllerFan: self.stepper_names = [] self.stepper_enable = self.printer.try_load_module(config, 'stepper_enable') + self.printer.try_load_module(config, 'heaters') self.heaters = [] self.fan = fan.PrinterFan(config) self.mcu = self.fan.mcu_fan.get_mcu() @@ -27,8 +28,8 @@ class ControllerFan: self.heater_name = config.get("heater", "extruder") self.last_on = self.idle_timeout def handle_ready(self): - pheater = self.printer.lookup_object('heater') - self.heaters = [pheater.lookup_heater(n.strip()) + pheaters = self.printer.lookup_object('heaters') + self.heaters = [pheaters.lookup_heater(n.strip()) for n in self.heater_name.split(',')] kin = self.printer.lookup_object('toolhead').get_kinematics() self.stepper_names = [s.get_name() for s in kin.get_steppers()] diff --git a/klippy/extras/heater_bed.py b/klippy/extras/heater_bed.py index c3505528..c2f56a99 100644 --- a/klippy/extras/heater_bed.py +++ b/klippy/extras/heater_bed.py @@ -7,8 +7,8 @@ class PrinterHeaterBed: def __init__(self, config): self.printer = config.get_printer() - pheater = self.printer.lookup_object('heater') - self.heater = pheater.setup_heater(config, 'B') + pheaters = self.printer.try_load_module(config, 'heaters') + self.heater = pheaters.setup_heater(config, 'B') self.get_status = self.heater.get_status self.stats = self.heater.stats # Register commands @@ -21,8 +21,8 @@ class PrinterHeaterBed: temp = gcode.get_float('S', params, 0.) self.heater.set_temp(temp) if wait and temp: - pheater = self.printer.lookup_object('heater') - pheater.wait_for_temperature(self.heater) + pheaters = self.printer.lookup_object('heaters') + pheaters.wait_for_temperature(self.heater) def cmd_M190(self, params): # Set Bed Temperature and Wait self.cmd_M140(params, wait=True) diff --git a/klippy/extras/heater_fan.py b/klippy/extras/heater_fan.py index 337dcc09..4a3ace84 100644 --- a/klippy/extras/heater_fan.py +++ b/klippy/extras/heater_fan.py @@ -10,6 +10,7 @@ PIN_MIN_TIME = 0.100 class PrinterHeaterFan: def __init__(self, config): self.printer = config.get_printer() + self.printer.try_load_module(config, 'heaters') self.printer.register_event_handler("klippy:ready", self.handle_ready) self.heater_name = config.get("heater", "extruder") self.heater_temp = config.getfloat("heater_temp", 50.0) @@ -18,8 +19,8 @@ class PrinterHeaterFan: self.mcu = self.fan.mcu_fan.get_mcu() self.fan_speed = config.getfloat("fan_speed", 1., minval=0., maxval=1.) def handle_ready(self): - pheater = self.printer.lookup_object('heater') - self.heaters = [pheater.lookup_heater(n.strip()) + pheaters = self.printer.lookup_object('heaters') + self.heaters = [pheaters.lookup_heater(n.strip()) for n in self.heater_name.split(',')] reactor = self.printer.get_reactor() reactor.register_timer(self.callback, reactor.NOW) diff --git a/klippy/extras/heater_generic.py b/klippy/extras/heater_generic.py index fbe13edc..564e4179 100644 --- a/klippy/extras/heater_generic.py +++ b/klippy/extras/heater_generic.py @@ -5,4 +5,5 @@ # This file may be distributed under the terms of the GNU GPLv3 license. def load_config_prefix(config): - return config.get_printer().lookup_object('heater').setup_heater(config) + pheaters = config.get_printer().try_load_module(config, 'heaters') + return pheaters.setup_heater(config) diff --git a/klippy/heater.py b/klippy/extras/heaters.py similarity index 98% rename from klippy/heater.py rename to klippy/extras/heaters.py index 4914c767..29fb5d6e 100644 --- a/klippy/heater.py +++ b/klippy/extras/heaters.py @@ -1,6 +1,6 @@ -# Printer heater support +# Tracking of PWM controlled heaters and their temperature control # -# Copyright (C) 2016-2018 Kevin O'Connor +# Copyright (C) 2016-2020 Kevin O'Connor # # This file may be distributed under the terms of the GNU GPLv3 license. import logging, threading @@ -323,5 +323,5 @@ class PrinterHeaters: gcode.respond_raw(self._get_temp(eventtime)) eventtime = reactor.pause(eventtime + 1.) -def add_printer_objects(config): - config.get_printer().add_object('heater', PrinterHeaters(config)) +def load_config(config): + return PrinterHeaters(config) diff --git a/klippy/extras/homing_heaters.py b/klippy/extras/homing_heaters.py index 6433869f..673b7f8d 100644 --- a/klippy/extras/homing_heaters.py +++ b/klippy/extras/homing_heaters.py @@ -19,12 +19,12 @@ class HomingHeaters: self.disable_heaters = [] self.steppers_needing_quiet = config.get("steppers", "") self.flaky_steppers = [] - self.pheater = self.printer.lookup_object('heater') + self.pheaters = self.printer.try_load_module(config, 'heaters') self.target_save = {} def handle_connect(self): # heaters to disable - all_heaters = self.pheater.get_all_heaters() + all_heaters = self.pheaters.get_all_heaters() self.disable_heaters = [n.strip() for n in self.heaters_to_disable.split(',')] if self.disable_heaters == [""]: @@ -56,14 +56,14 @@ class HomingHeaters: if not self.check_eligible(endstops): return for heater_name in self.disable_heaters: - heater = self.pheater.lookup_heater(heater_name) + heater = self.pheaters.lookup_heater(heater_name) self.target_save[heater_name] = heater.get_temp(0)[1] heater.set_temp(0.) def handle_homing_move_end(self, endstops): if not self.check_eligible(endstops): return for heater_name in self.disable_heaters: - heater = self.pheater.lookup_heater(heater_name) + heater = self.pheaters.lookup_heater(heater_name) heater.set_temp(self.target_save[heater_name]) def load_config(config): diff --git a/klippy/extras/pid_calibrate.py b/klippy/extras/pid_calibrate.py index 49ae3bb4..b5dbc773 100644 --- a/klippy/extras/pid_calibrate.py +++ b/klippy/extras/pid_calibrate.py @@ -18,9 +18,9 @@ class PIDCalibrate: heater_name = self.gcode.get_str('HEATER', params) target = self.gcode.get_float('TARGET', params) write_file = self.gcode.get_int('WRITE_FILE', params, 0) - pheater = self.printer.lookup_object('heater') + pheaters = self.printer.lookup_object('heaters') try: - heater = pheater.lookup_heater(heater_name) + heater = pheaters.lookup_heater(heater_name) except self.printer.config_error as e: raise self.gcode.error(str(e)) self.printer.lookup_object('toolhead').get_last_move_time() @@ -31,7 +31,7 @@ class PIDCalibrate: except self.printer.command_error as e: heater.set_control(old_control) raise - pheater.wait_for_temperature(heater) + pheaters.wait_for_temperature(heater) heater.set_control(old_control) if write_file: calibrate.write_file('/tmp/heattest.txt') diff --git a/klippy/extras/spi_temperature.py b/klippy/extras/spi_temperature.py index 74cf9505..606a317e 100644 --- a/klippy/extras/spi_temperature.py +++ b/klippy/extras/spi_temperature.py @@ -336,6 +336,6 @@ Sensors = { def load_config(config): # Register sensors - pheater = config.get_printer().lookup_object("heater") + pheaters = config.get_printer().try_load_module(config, "heaters") for name, klass in Sensors.items(): - pheater.add_sensor_factory(name, klass) + pheaters.add_sensor_factory(name, klass) diff --git a/klippy/extras/temperature_fan.py b/klippy/extras/temperature_fan.py index 6fc2893b..cebeee1f 100644 --- a/klippy/extras/temperature_fan.py +++ b/klippy/extras/temperature_fan.py @@ -18,10 +18,11 @@ class TemperatureFan: self.gcode = self.printer.lookup_object('gcode') self.min_temp = config.getfloat('min_temp', minval=KELVIN_TO_CELSIUS) self.max_temp = config.getfloat('max_temp', above=self.min_temp) - self.sensor = self.printer.lookup_object('heater').setup_sensor(config) + pheaters = self.printer.try_load_module(config, 'heaters') + self.sensor = pheaters.setup_sensor(config) 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) + pheaters.register_sensor(config, self) self.speed_delay = self.sensor.get_report_time_delta() self.max_speed = config.getfloat('max_speed', 1., above=0., maxval=1.) self.min_speed = config.getfloat('min_speed', 0.3, minval=0., maxval=1.) diff --git a/klippy/extras/temperature_sensor.py b/klippy/extras/temperature_sensor.py index 62b7afef..94779a85 100644 --- a/klippy/extras/temperature_sensor.py +++ b/klippy/extras/temperature_sensor.py @@ -9,14 +9,15 @@ KELVIN_TO_CELSIUS = -273.15 class PrinterSensorGeneric: def __init__(self, config): self.printer = config.get_printer() - self.sensor = self.printer.lookup_object('heater').setup_sensor(config) + pheaters = self.printer.try_load_module(config, 'heaters') + self.sensor = pheaters.setup_sensor(config) self.min_temp = config.getfloat('min_temp', KELVIN_TO_CELSIUS, minval=KELVIN_TO_CELSIUS) 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) + pheaters.register_sensor(config, self) self.last_temp = 0. def temperature_callback(self, read_time, temp): self.last_temp = temp diff --git a/klippy/extras/thermistor.py b/klippy/extras/thermistor.py index f43c0a99..7e3aa3aa 100644 --- a/klippy/extras/thermistor.py +++ b/klippy/extras/thermistor.py @@ -116,12 +116,12 @@ Sensors = { def load_config(config): # Register default thermistor types - pheater = config.get_printer().lookup_object("heater") + pheaters = config.get_printer().try_load_module(config, "heaters") for sensor_type, params in Sensors.items(): func = (lambda config, params=params: PrinterThermistor(config, params)) - pheater.add_sensor_factory(sensor_type, func) + pheaters.add_sensor_factory(sensor_type, func) def load_config_prefix(config): thermistor = CustomThermistor(config) - pheater = config.get_printer().lookup_object("heater") - pheater.add_sensor_factory(thermistor.name, thermistor.create) + pheaters = config.get_printer().try_load_module(config, "heaters") + pheaters.add_sensor_factory(thermistor.name, thermistor.create) diff --git a/klippy/extras/verify_heater.py b/klippy/extras/verify_heater.py index a76646f5..8c5360d5 100644 --- a/klippy/extras/verify_heater.py +++ b/klippy/extras/verify_heater.py @@ -35,8 +35,8 @@ class HeaterCheck: if self.printer.get_start_args().get('debugoutput') is not None: # Disable verify_heater if outputting to a debug file return - pheater = self.printer.lookup_object('heater') - self.heater = pheater.lookup_heater(self.heater_name) + pheaters = self.printer.lookup_object('heaters') + self.heater = pheaters.lookup_heater(self.heater_name) logging.info("Starting heater checks for %s", self.heater_name) reactor = self.printer.get_reactor() self.check_timer = reactor.register_timer(self.check_event, reactor.NOW) diff --git a/klippy/kinematics/extruder.py b/klippy/kinematics/extruder.py index c7884932..2921ef0a 100644 --- a/klippy/kinematics/extruder.py +++ b/klippy/kinematics/extruder.py @@ -11,12 +11,12 @@ class PrinterExtruder: self.printer = config.get_printer() self.name = config.get_name() shared_heater = config.get('shared_heater', None) - pheater = self.printer.lookup_object('heater') + pheaters = self.printer.try_load_module(config, 'heaters') gcode_id = 'T%d' % (extruder_num,) if shared_heater is None: - self.heater = pheater.setup_heater(config, gcode_id) + self.heater = pheaters.setup_heater(config, gcode_id) else: - self.heater = pheater.lookup_heater(shared_heater) + self.heater = pheaters.lookup_heater(shared_heater) self.stepper = stepper.PrinterStepper(config) self.nozzle_diameter = config.getfloat('nozzle_diameter', above=0.) filament_diameter = config.getfloat( @@ -167,7 +167,7 @@ class PrinterExtruder: heater = extruder.get_heater() heater.set_temp(temp) if wait and temp: - self.printer.lookup_object('heater').wait_for_temperature(heater) + self.printer.lookup_object('heaters').wait_for_temperature(heater) def cmd_M109(self, params): # Set Extruder Temperature and Wait self.cmd_M104(params, wait=True) diff --git a/klippy/klippy.py b/klippy/klippy.py index becbe113..d03e25a5 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -6,7 +6,7 @@ # This file may be distributed under the terms of the GNU GPLv3 license. import sys, os, optparse, logging, time, threading, collections, importlib import util, reactor, queuelogger, msgproto, homing -import gcode, configfile, pins, heater, mcu, toolhead +import gcode, configfile, pins, mcu, toolhead message_ready = "Printer is ready" @@ -123,7 +123,7 @@ class Printer: if self.bglogger is not None: pconfig.log_config(config) # Create printer components - for m in [pins, heater, mcu]: + for m in [pins, mcu]: m.add_printer_objects(config) for section_config in config.get_prefix_sections(''): self.try_load_module(config, section_config.get_name())