From 7d897d84d773654a8beaf56012e0bf8285db8206 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 12 Jul 2018 22:26:32 -0400 Subject: [PATCH] klippy: No need to pass printer reference to add_printer_objects() The config reference already stores a reference to the printer object. Signed-off-by: Kevin O'Connor --- klippy/extruder.py | 3 ++- klippy/heater.py | 8 ++++---- klippy/klippy.py | 4 ++-- klippy/mcu.py | 15 ++++++++------- klippy/pins.py | 4 ++-- klippy/toolhead.py | 4 ++-- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/klippy/extruder.py b/klippy/extruder.py index 609cabe6..8e564d62 100644 --- a/klippy/extruder.py +++ b/klippy/extruder.py @@ -231,7 +231,8 @@ class DummyExtruder: def lookahead(self, moves, flush_count, lazy): return flush_count -def add_printer_objects(printer, config): +def add_printer_objects(config): + printer = config.get_printer() for i in range(99): section = 'extruder%d' % (i,) if not config.has_section(section): diff --git a/klippy/heater.py b/klippy/heater.py index 7bbe4a82..919e1088 100644 --- a/klippy/heater.py +++ b/klippy/heater.py @@ -216,8 +216,8 @@ class ControlPID: ###################################################################### class PrinterHeaters: - def __init__(self, printer, config): - self.printer = printer + def __init__(self, config): + self.printer = config.get_printer() self.sensors = {} self.heaters = {} def add_sensor(self, sensor_type, sensor_factory): @@ -249,5 +249,5 @@ class PrinterHeaters: sensor_type,)) return self.sensors[sensor_type](config) -def add_printer_objects(printer, config): - printer.add_object('heater', PrinterHeaters(printer, config)) +def add_printer_objects(config): + config.get_printer().add_object('heater', PrinterHeaters(config)) diff --git a/klippy/klippy.py b/klippy/klippy.py index 588666f6..03d71eff 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -213,11 +213,11 @@ class Printer: # Create printer components config = ConfigWrapper(self, fileconfig, 'printer') for m in [pins, heater, mcu]: - m.add_printer_objects(self, config) + m.add_printer_objects(config) for section in fileconfig.sections(): self.try_load_module(config, section) for m in [toolhead, extruder]: - m.add_printer_objects(self, config) + m.add_printer_objects(config) # Validate that there are no undefined parameters in the config file valid_sections = { s: 1 for s, o in self.all_config_options } for section_name in fileconfig.sections(): diff --git a/klippy/mcu.py b/klippy/mcu.py index 64c5eae6..c059623f 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -399,10 +399,10 @@ class MCU_adc: class MCU: error = error - def __init__(self, printer, config, clocksync): - self._printer = printer + def __init__(self, config, clocksync): + self._printer = config.get_printer() self._clocksync = clocksync - self._reactor = printer.get_reactor() + self._reactor = self._printer.get_reactor() self._name = config.get_name() if self._name.startswith('mcu '): self._name = self._name[4:] @@ -425,7 +425,7 @@ class MCU: self._is_shutdown = self._is_timeout = False self._shutdown_msg = "" # Config building - printer.lookup_object('pins').register_chip(self._name, self) + self._printer.lookup_object('pins').register_chip(self._name, self) self._oid_count = 0 self._config_objects = [] self._init_cmds = [] @@ -775,13 +775,14 @@ def error_help(msg): return help_msg return "" -def add_printer_objects(printer, config): +def add_printer_objects(config): + printer = config.get_printer() reactor = printer.get_reactor() mainsync = clocksync.ClockSync(reactor) - printer.add_object('mcu', MCU(printer, config.getsection('mcu'), mainsync)) + printer.add_object('mcu', MCU(config.getsection('mcu'), mainsync)) for s in config.get_prefix_sections('mcu '): printer.add_object(s.section, MCU( - printer, s, clocksync.SecondarySync(reactor, mainsync))) + s, clocksync.SecondarySync(reactor, mainsync))) def get_printer_mcu(printer, name): if name == 'mcu': diff --git a/klippy/pins.py b/klippy/pins.py index ac8fd8bd..3d9d9ccf 100644 --- a/klippy/pins.py +++ b/klippy/pins.py @@ -247,5 +247,5 @@ class PrinterPins: raise error("Duplicate chip name '%s'" % (chip_name,)) self.chips[chip_name] = chip -def add_printer_objects(printer, config): - printer.add_object('pins', PrinterPins()) +def add_printer_objects(config): + config.get_printer().add_object('pins', PrinterPins()) diff --git a/klippy/toolhead.py b/klippy/toolhead.py index ba6319a1..6b0058d3 100644 --- a/klippy/toolhead.py +++ b/klippy/toolhead.py @@ -442,5 +442,5 @@ class ToolHead: accel = gcode.get_float('S', params, above=0.) self.max_accel = min(accel, self.config_max_accel) -def add_printer_objects(printer, config): - printer.add_object('toolhead', ToolHead(config)) +def add_printer_objects(config): + config.get_printer().add_object('toolhead', ToolHead(config))