aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/klippy.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-04-29 13:57:02 -0400
committerKevin O'Connor <kevin@koconnor.net>2017-06-09 18:54:34 -0400
commit136dccbcdfc6a20c8b6755afdfb65891cee3d1a7 (patch)
treefb195571d64d97f79c6197c9c46d02319d347356 /klippy/klippy.py
parentd0e6a0928b483f29a3bcfd86d16192bef5652042 (diff)
downloadkutter-136dccbcdfc6a20c8b6755afdfb65891cee3d1a7.tar.gz
kutter-136dccbcdfc6a20c8b6755afdfb65891cee3d1a7.tar.xz
kutter-136dccbcdfc6a20c8b6755afdfb65891cee3d1a7.zip
klippy: Allow each module to define their config sections
Create add_printer_objects() functions in the fan, heater, extruder, and toolhead modules. Create the necessary printer component objects from this call instead of placing the code directly in klippy.py. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/klippy.py')
-rw-r--r--klippy/klippy.py19
1 files changed, 8 insertions, 11 deletions
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():