klippy: Add ConfigWrapper.getchoice method
Add helper function that ensures a config option is one of several choices. This helps ensure that a proper error is raised if an invalid choice is made. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
57244de37d
commit
2f97b2d7c2
|
@ -26,7 +26,7 @@ class PrinterHeater:
|
||||||
self.printer = printer
|
self.printer = printer
|
||||||
self.config = config
|
self.config = config
|
||||||
self.mcu_pwm = self.mcu_adc = None
|
self.mcu_pwm = self.mcu_adc = None
|
||||||
self.thermistor_c = Thermistors.get(config.get('thermistor_type'))
|
self.thermistor_c = config.getchoice('thermistor_type', Thermistors)
|
||||||
self.pullup_r = config.getfloat('pullup_resistor', 4700.)
|
self.pullup_r = config.getfloat('pullup_resistor', 4700.)
|
||||||
self.min_extrude_temp = config.getfloat('min_extrude_temp', 170.)
|
self.min_extrude_temp = config.getfloat('min_extrude_temp', 170.)
|
||||||
self.can_extrude = (self.min_extrude_temp <= 0.)
|
self.can_extrude = (self.min_extrude_temp <= 0.)
|
||||||
|
@ -48,9 +48,8 @@ class PrinterHeater:
|
||||||
self.mcu_adc.set_minmax(
|
self.mcu_adc.set_minmax(
|
||||||
SAMPLE_TIME, SAMPLE_COUNT, minval=min_adc, maxval=max_adc)
|
SAMPLE_TIME, SAMPLE_COUNT, minval=min_adc, maxval=max_adc)
|
||||||
self.mcu_adc.set_adc_callback(REPORT_TIME, self.adc_callback)
|
self.mcu_adc.set_adc_callback(REPORT_TIME, self.adc_callback)
|
||||||
control_algo = self.config.get('control', 'watermark')
|
|
||||||
algos = {'watermark': ControlBangBang, 'pid': ControlPID}
|
algos = {'watermark': ControlBangBang, 'pid': ControlPID}
|
||||||
self.control = algos[control_algo](self, self.config)
|
self.control = self.config.getchoice('control', algos)(self, self.config)
|
||||||
if self.printer.mcu.is_fileoutput():
|
if self.printer.mcu.is_fileoutput():
|
||||||
self.can_extrude = True
|
self.can_extrude = True
|
||||||
def set_pwm(self, read_time, value):
|
def set_pwm(self, read_time, value):
|
||||||
|
|
|
@ -61,6 +61,13 @@ class ConfigWrapper:
|
||||||
def getboolean(self, option, default=sentinel):
|
def getboolean(self, option, default=sentinel):
|
||||||
return self.get_wrapper(
|
return self.get_wrapper(
|
||||||
self.printer.fileconfig.getboolean, option, default)
|
self.printer.fileconfig.getboolean, option, default)
|
||||||
|
def getchoice(self, option, choices, default=sentinel):
|
||||||
|
c = self.get(option, default)
|
||||||
|
if c not in choices:
|
||||||
|
raise self.error(
|
||||||
|
"Option '%s' in section '%s' is not a valid choice" % (
|
||||||
|
option, self.section))
|
||||||
|
return choices[c]
|
||||||
def getsection(self, section):
|
def getsection(self, section):
|
||||||
return ConfigWrapper(self.printer, section)
|
return ConfigWrapper(self.printer, section)
|
||||||
|
|
||||||
|
|
|
@ -161,8 +161,7 @@ class ToolHead:
|
||||||
self.extruder = printer.objects.get('extruder')
|
self.extruder = printer.objects.get('extruder')
|
||||||
kintypes = {'cartesian': cartesian.CartKinematics,
|
kintypes = {'cartesian': cartesian.CartKinematics,
|
||||||
'delta': delta.DeltaKinematics}
|
'delta': delta.DeltaKinematics}
|
||||||
kin = config.get('kinematics', 'cartesian')
|
self.kin = config.getchoice('kinematics', kintypes)(printer, config)
|
||||||
self.kin = kintypes[kin](printer, config)
|
|
||||||
self.max_speed, self.max_accel = self.kin.get_max_speed()
|
self.max_speed, self.max_accel = self.kin.get_max_speed()
|
||||||
self.junction_deviation = config.getfloat('junction_deviation', 0.02)
|
self.junction_deviation = config.getfloat('junction_deviation', 0.02)
|
||||||
self.move_queue = MoveQueue()
|
self.move_queue = MoveQueue()
|
||||||
|
|
Loading…
Reference in New Issue