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>
This commit is contained in:
Kevin O'Connor 2017-04-29 13:57:02 -04:00
parent d0e6a0928b
commit 136dccbcdf
5 changed files with 25 additions and 11 deletions

View File

@ -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')))

View File

@ -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')))

View File

@ -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')))

View File

@ -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():

View File

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