aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--klippy/extruder.py5
-rw-r--r--klippy/fan.py4
-rw-r--r--klippy/heater.py5
-rw-r--r--klippy/klippy.py19
-rw-r--r--klippy/toolhead.py3
5 files changed, 25 insertions, 11 deletions
diff --git a/klippy/extruder.py b/klippy/extruder.py
index 0a77902b..a4d6bd5a 100644
--- a/klippy/extruder.py
+++ b/klippy/extruder.py
@@ -210,3 +210,8 @@ class DummyExtruder:
return move.max_cruise_v2
def lookahead(self, moves, flush_count, lazy):
return flush_count
+
+def add_printer_objects(printer, config):
+ if config.has_section('extruder'):
+ printer.add_object('extruder', PrinterExtruder(
+ printer, config.getsection('extruder')))
diff --git a/klippy/fan.py b/klippy/fan.py
index 9b78d6ab..bd66f7b5 100644
--- a/klippy/fan.py
+++ b/klippy/fan.py
@@ -30,3 +30,7 @@ class PrinterFan:
self.mcu_fan.set_pwm(mcu_time, value)
self.last_fan_time = mcu_time
self.last_fan_value = value
+
+def add_printer_objects(printer, config):
+ if config.has_section('fan'):
+ printer.add_object('fan', PrinterFan(printer, config.getsection('fan')))
diff --git a/klippy/heater.py b/klippy/heater.py
index c4e0a715..21624cb0 100644
--- a/klippy/heater.py
+++ b/klippy/heater.py
@@ -308,3 +308,8 @@ class ControlBumpTest:
return True
self.heater.control = self.old_control
return False
+
+def add_printer_objects(printer, config):
+ if config.has_section('heater_bed'):
+ printer.add_object('heater_bed', PrinterHeater(
+ printer, config.getsection('heater_bed')))
diff --git a/klippy/klippy.py b/klippy/klippy.py
index 58898374..ba5d1762 100644
--- a/klippy/klippy.py
+++ b/klippy/klippy.py
@@ -105,6 +105,8 @@ class ConfigWrapper:
return choices[c]
def getsection(self, section):
return ConfigWrapper(self.printer, section)
+ def has_section(self, section):
+ return self.printer.fileconfig.has_section(section)
class ConfigLogger():
def __init__(self, cfg, bglogger):
@@ -159,6 +161,8 @@ class Printer:
out.append(self.mcu.stats(eventtime))
logging.info("Stats %.1f: %s" % (eventtime, ' '.join(out)))
return eventtime + 1.
+ def add_object(self, name, obj):
+ self.objects[name] = obj
def load_config(self):
self.fileconfig = ConfigParser.RawConfigParser()
res = self.fileconfig.read(self.conffile)
@@ -170,17 +174,10 @@ class Printer:
self.mcu = mcu.MCU(self, ConfigWrapper(self, 'mcu'))
if self.debugoutput is not None:
self.mcu.connect_file(self.debugoutput, self.dictionary)
- if self.fileconfig.has_section('extruder'):
- self.objects['extruder'] = extruder.PrinterExtruder(
- self, ConfigWrapper(self, 'extruder'))
- if self.fileconfig.has_section('fan'):
- self.objects['fan'] = fan.PrinterFan(
- self, ConfigWrapper(self, 'fan'))
- if self.fileconfig.has_section('heater_bed'):
- self.objects['heater_bed'] = heater.PrinterHeater(
- self, ConfigWrapper(self, 'heater_bed'))
- self.objects['toolhead'] = toolhead.ToolHead(
- self, ConfigWrapper(self, 'printer'))
+ # Create printer components
+ config = ConfigWrapper(self, 'printer')
+ for m in [extruder, fan, heater, toolhead]:
+ m.add_printer_objects(self, 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 in self.fileconfig.sections():
diff --git a/klippy/toolhead.py b/klippy/toolhead.py
index 4329a712..7b25c7e5 100644
--- a/klippy/toolhead.py
+++ b/klippy/toolhead.py
@@ -382,3 +382,6 @@ class ToolHead:
self.reset_print_time()
except:
logging.exception("Exception in force_shutdown")
+
+def add_printer_objects(printer, config):
+ printer.add_object('toolhead', ToolHead(printer, config))