mirror of https://github.com/Desuuuu/klipper.git
klippy: Introduce load_config_prefix() for modules that take parameters
Use both load_config() and load_config_prefix() functions when dynamically loading a module from the extras directory - if the config section name has parameters in it then use load_config_prefix(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
7e3adde542
commit
f4bfce260a
|
@ -26,5 +26,5 @@ class ad5206:
|
|||
self.mcu.add_config_cmd(
|
||||
"send_spi_message pin=%s msg=%02x%02x" % (self.pin, i, val))
|
||||
|
||||
def load_config(config):
|
||||
def load_config_prefix(config):
|
||||
return ad5206(config)
|
||||
|
|
|
@ -90,6 +90,4 @@ class BedTiltCalibrate:
|
|||
z_warn, new_params['x_adjust'], new_params['y_adjust']))
|
||||
|
||||
def load_config(config):
|
||||
if config.get_name() != 'bed_tilt':
|
||||
raise config.error("Invalid bed_tilt config name")
|
||||
return BedTilt(config)
|
||||
|
|
|
@ -71,6 +71,4 @@ class DeltaCalibrate:
|
|||
new_params['radius']))
|
||||
|
||||
def load_config(config):
|
||||
if config.get_name() != 'delta_calibrate':
|
||||
raise config.error("Invalid delta_calibrate config name")
|
||||
return DeltaCalibrate(config)
|
||||
|
|
|
@ -34,6 +34,4 @@ class PrinterFan:
|
|||
self.last_fan_value = value
|
||||
|
||||
def load_config(config):
|
||||
if config.get_name() != 'fan':
|
||||
raise config.error("Invalid print cooling fan config name")
|
||||
return PrinterFan(config)
|
||||
|
|
|
@ -33,5 +33,5 @@ class PrinterHeaterFan:
|
|||
self.fan.set_speed(print_time, power)
|
||||
return eventtime + 1.
|
||||
|
||||
def load_config(config):
|
||||
def load_config_prefix(config):
|
||||
return PrinterHeaterFan(config)
|
||||
|
|
|
@ -36,6 +36,4 @@ class HomingOverride:
|
|||
self.in_script = False
|
||||
|
||||
def load_config(config):
|
||||
if config.get_name() != 'homing_override':
|
||||
raise config.error("Invalid homing_override config name")
|
||||
return HomingOverride(config)
|
||||
|
|
|
@ -50,5 +50,5 @@ class PrinterMultiPin:
|
|||
for mcu_pin in self.mcu_pins:
|
||||
mcu_pin.set_pwm(print_time, value)
|
||||
|
||||
def load_config(config):
|
||||
def load_config_prefix(config):
|
||||
return PrinterMultiPin(config)
|
||||
|
|
|
@ -172,6 +172,4 @@ def coordinate_descent(adj_params, params, error_func):
|
|||
return params
|
||||
|
||||
def load_config(config):
|
||||
if config.get_name() != 'probe':
|
||||
raise config.error("Invalid probe config name")
|
||||
return PrinterProbe(config)
|
||||
|
|
|
@ -218,6 +218,4 @@ class Replicape:
|
|||
return pclass(self, channel, pin_params)
|
||||
|
||||
def load_config(config):
|
||||
if config.get_name() != 'replicape':
|
||||
raise config.error("Invalid replicape config name")
|
||||
return Replicape(config)
|
||||
|
|
|
@ -55,5 +55,5 @@ class PrinterServo:
|
|||
else:
|
||||
self.set_angle(print_time, self.gcode.get_float('ANGLE', params))
|
||||
|
||||
def load_config(config):
|
||||
def load_config_prefix(config):
|
||||
return PrinterServo(config)
|
||||
|
|
|
@ -185,13 +185,19 @@ class Printer:
|
|||
def _try_load_module(self, config, section):
|
||||
if section in self.objects:
|
||||
return
|
||||
module_name = section.split()[0]
|
||||
module_parts = section.split()
|
||||
module_name = module_parts[0]
|
||||
py_name = os.path.join(os.path.dirname(__file__),
|
||||
'extras', module_name + '.py')
|
||||
if not os.path.exists(py_name):
|
||||
return
|
||||
mod = importlib.import_module('extras.' + module_name)
|
||||
self.objects[section] = mod.load_config(config.getsection(section))
|
||||
init_func = 'load_config'
|
||||
if len(module_parts) > 1:
|
||||
init_func = 'load_config_prefix'
|
||||
init_func = getattr(mod, init_func, None)
|
||||
if init_func is not None:
|
||||
self.objects[section] = init_func(config.getsection(section))
|
||||
def _read_config(self):
|
||||
fileconfig = ConfigParser.RawConfigParser()
|
||||
config_file = self.start_args['config_file']
|
||||
|
|
Loading…
Reference in New Issue