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:
Kevin O'Connor 2016-11-30 15:39:36 -05:00
parent 3806ed882a
commit 57244de37d
3 changed files with 33 additions and 24 deletions

View File

@ -35,25 +35,32 @@ Printer is shutdown
class ConfigWrapper:
error = ConfigParser.Error
class sentinel:
pass
def __init__(self, printer, section):
self.printer = printer
self.section = section
def get(self, option, default=None):
if not self.printer.fileconfig.has_option(self.section, option):
def get_wrapper(self, parser, option, default):
if (default is not self.sentinel
and not self.printer.fileconfig.has_option(self.section, option)):
return default
return self.printer.fileconfig.get(self.section, option)
def getint(self, option, default=None):
if not self.printer.fileconfig.has_option(self.section, option):
return default
return self.printer.fileconfig.getint(self.section, option)
def getfloat(self, option, default=None):
if not self.printer.fileconfig.has_option(self.section, option):
return default
return self.printer.fileconfig.getfloat(self.section, option)
def getboolean(self, option, default=None):
if not self.printer.fileconfig.has_option(self.section, option):
return default
return self.printer.fileconfig.getboolean(self.section, option)
try:
return parser(self.section, option)
except self.error, e:
raise
except:
raise self.error("Unable to parse option '%s' in section '%s'" % (
option, self.section))
def get(self, option, default=sentinel):
return self.get_wrapper(self.printer.fileconfig.get, option, default)
def getint(self, option, default=sentinel):
return self.get_wrapper(self.printer.fileconfig.getint, option, default)
def getfloat(self, option, default=sentinel):
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):
return ConfigWrapper(self.printer, section)

View File

@ -394,7 +394,7 @@ class MCU:
# Resolve pin names
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:
pnames = pins.mcu_to_pins(mcu)
else:

View File

@ -23,9 +23,9 @@ class PrinterStepper:
self.homing_positive_dir = config.getboolean(
'homing_positive_dir', False)
self.homing_retract_dist = config.getfloat('homing_retract_dist', 5.)
self.homing_stepper_phases = config.getint('homing_stepper_phases')
self.homing_endstop_phase = config.getint('homing_endstop_phase')
endstop_accuracy = config.getfloat('homing_endstop_accuracy')
self.homing_stepper_phases = config.getint('homing_stepper_phases', None)
self.homing_endstop_phase = config.getint('homing_endstop_phase', None)
endstop_accuracy = config.getfloat('homing_endstop_accuracy', None)
self.homing_endstop_accuracy = None
if self.homing_stepper_phases:
if endstop_accuracy is None:
@ -40,9 +40,11 @@ class PrinterStepper:
logging.info("Endstop for %s is not accurate enough for stepper"
" phase adjustment" % (self.config.section,))
self.homing_stepper_phases = None
self.position_min = self.position_endstop = self.position_max = None
if config.get('endstop_pin', None) is not None:
self.position_min = config.getfloat('position_min', 0.)
self.position_endstop = config.getfloat('position_endstop')
self.position_max = config.getfloat('position_max')
self.position_max = config.getfloat('position_max', 0.)
self.need_motor_enable = True
def set_max_jerk(self, max_jerk):
@ -59,10 +61,10 @@ class PrinterStepper:
mcu = self.printer.mcu
self.mcu_stepper = mcu.create_stepper(
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:
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:
self.mcu_endstop = mcu.create_endstop(endstop_pin, self.mcu_stepper)
def motor_enable(self, move_time, enable=0):