klippy: Throw an exception if any required config parameter is missing
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
3806ed882a
commit
57244de37d
|
@ -35,25 +35,32 @@ Printer is shutdown
|
||||||
|
|
||||||
class ConfigWrapper:
|
class ConfigWrapper:
|
||||||
error = ConfigParser.Error
|
error = ConfigParser.Error
|
||||||
|
class sentinel:
|
||||||
|
pass
|
||||||
def __init__(self, printer, section):
|
def __init__(self, printer, section):
|
||||||
self.printer = printer
|
self.printer = printer
|
||||||
self.section = section
|
self.section = section
|
||||||
def get(self, option, default=None):
|
def get_wrapper(self, parser, option, default):
|
||||||
if not self.printer.fileconfig.has_option(self.section, option):
|
if (default is not self.sentinel
|
||||||
|
and not self.printer.fileconfig.has_option(self.section, option)):
|
||||||
return default
|
return default
|
||||||
return self.printer.fileconfig.get(self.section, option)
|
try:
|
||||||
def getint(self, option, default=None):
|
return parser(self.section, option)
|
||||||
if not self.printer.fileconfig.has_option(self.section, option):
|
except self.error, e:
|
||||||
return default
|
raise
|
||||||
return self.printer.fileconfig.getint(self.section, option)
|
except:
|
||||||
def getfloat(self, option, default=None):
|
raise self.error("Unable to parse option '%s' in section '%s'" % (
|
||||||
if not self.printer.fileconfig.has_option(self.section, option):
|
option, self.section))
|
||||||
return default
|
def get(self, option, default=sentinel):
|
||||||
return self.printer.fileconfig.getfloat(self.section, option)
|
return self.get_wrapper(self.printer.fileconfig.get, option, default)
|
||||||
def getboolean(self, option, default=None):
|
def getint(self, option, default=sentinel):
|
||||||
if not self.printer.fileconfig.has_option(self.section, option):
|
return self.get_wrapper(self.printer.fileconfig.getint, option, default)
|
||||||
return default
|
def getfloat(self, option, default=sentinel):
|
||||||
return self.printer.fileconfig.getboolean(self.section, option)
|
return self.get_wrapper(
|
||||||
|
self.printer.fileconfig.getfloat, option, default)
|
||||||
|
def getboolean(self, option, default=sentinel):
|
||||||
|
return self.get_wrapper(
|
||||||
|
self.printer.fileconfig.getboolean, option, default)
|
||||||
def getsection(self, section):
|
def getsection(self, section):
|
||||||
return ConfigWrapper(self.printer, section)
|
return ConfigWrapper(self.printer, section)
|
||||||
|
|
||||||
|
|
|
@ -394,7 +394,7 @@ class MCU:
|
||||||
|
|
||||||
# Resolve pin names
|
# Resolve pin names
|
||||||
mcu = self.serial.msgparser.config['MCU']
|
mcu = self.serial.msgparser.config['MCU']
|
||||||
pin_map = self._config.get('pin_map')
|
pin_map = self._config.get('pin_map', None)
|
||||||
if pin_map is None:
|
if pin_map is None:
|
||||||
pnames = pins.mcu_to_pins(mcu)
|
pnames = pins.mcu_to_pins(mcu)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -23,9 +23,9 @@ class PrinterStepper:
|
||||||
self.homing_positive_dir = config.getboolean(
|
self.homing_positive_dir = config.getboolean(
|
||||||
'homing_positive_dir', False)
|
'homing_positive_dir', False)
|
||||||
self.homing_retract_dist = config.getfloat('homing_retract_dist', 5.)
|
self.homing_retract_dist = config.getfloat('homing_retract_dist', 5.)
|
||||||
self.homing_stepper_phases = config.getint('homing_stepper_phases')
|
self.homing_stepper_phases = config.getint('homing_stepper_phases', None)
|
||||||
self.homing_endstop_phase = config.getint('homing_endstop_phase')
|
self.homing_endstop_phase = config.getint('homing_endstop_phase', None)
|
||||||
endstop_accuracy = config.getfloat('homing_endstop_accuracy')
|
endstop_accuracy = config.getfloat('homing_endstop_accuracy', None)
|
||||||
self.homing_endstop_accuracy = None
|
self.homing_endstop_accuracy = None
|
||||||
if self.homing_stepper_phases:
|
if self.homing_stepper_phases:
|
||||||
if endstop_accuracy is None:
|
if endstop_accuracy is None:
|
||||||
|
@ -40,9 +40,11 @@ class PrinterStepper:
|
||||||
logging.info("Endstop for %s is not accurate enough for stepper"
|
logging.info("Endstop for %s is not accurate enough for stepper"
|
||||||
" phase adjustment" % (self.config.section,))
|
" phase adjustment" % (self.config.section,))
|
||||||
self.homing_stepper_phases = None
|
self.homing_stepper_phases = None
|
||||||
self.position_min = config.getfloat('position_min', 0.)
|
self.position_min = self.position_endstop = self.position_max = None
|
||||||
self.position_endstop = config.getfloat('position_endstop')
|
if config.get('endstop_pin', None) is not None:
|
||||||
self.position_max = config.getfloat('position_max')
|
self.position_min = config.getfloat('position_min', 0.)
|
||||||
|
self.position_endstop = config.getfloat('position_endstop')
|
||||||
|
self.position_max = config.getfloat('position_max', 0.)
|
||||||
|
|
||||||
self.need_motor_enable = True
|
self.need_motor_enable = True
|
||||||
def set_max_jerk(self, max_jerk):
|
def set_max_jerk(self, max_jerk):
|
||||||
|
@ -59,10 +61,10 @@ class PrinterStepper:
|
||||||
mcu = self.printer.mcu
|
mcu = self.printer.mcu
|
||||||
self.mcu_stepper = mcu.create_stepper(
|
self.mcu_stepper = mcu.create_stepper(
|
||||||
step_pin, dir_pin, min_stop_interval, max_error)
|
step_pin, dir_pin, min_stop_interval, max_error)
|
||||||
enable_pin = self.config.get('enable_pin')
|
enable_pin = self.config.get('enable_pin', None)
|
||||||
if enable_pin is not None:
|
if enable_pin is not None:
|
||||||
self.mcu_enable = mcu.create_digital_out(enable_pin, 0)
|
self.mcu_enable = mcu.create_digital_out(enable_pin, 0)
|
||||||
endstop_pin = self.config.get('endstop_pin')
|
endstop_pin = self.config.get('endstop_pin', None)
|
||||||
if endstop_pin is not None:
|
if endstop_pin is not None:
|
||||||
self.mcu_endstop = mcu.create_endstop(endstop_pin, self.mcu_stepper)
|
self.mcu_endstop = mcu.create_endstop(endstop_pin, self.mcu_stepper)
|
||||||
def motor_enable(self, move_time, enable=0):
|
def motor_enable(self, move_time, enable=0):
|
||||||
|
|
Loading…
Reference in New Issue