Skip to content

Commit

Permalink
configfile: Allow getchoice() to take a list
Browse files Browse the repository at this point in the history
If a list is passed to getchoice(), seamlessly convert it to a dict.

Signed-off-by: Kevin O'Connor <[email protected]>
  • Loading branch information
KevinOConnor committed Jun 17, 2024
1 parent 863a463 commit 11f04ba
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 11 deletions.
2 changes: 2 additions & 0 deletions klippy/configfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def getboolean(self, option, default=sentinel, note_valid=True):
return self._get_wrapper(self.fileconfig.getboolean, option, default,
note_valid=note_valid)
def getchoice(self, option, choices, default=sentinel, note_valid=True):
if type(choices) == type([]):
choices = {i: i for i in choices}
if choices and type(list(choices.keys())[0]) == int:
c = self.getint(option, default, note_valid=note_valid)
else:
Expand Down
2 changes: 1 addition & 1 deletion klippy/extras/bltouch.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, config):
# Create an "endstop" object to handle the sensor pin
self.mcu_endstop = ppins.setup_pin('endstop', config.get('sensor_pin'))
# output mode
omodes = {'5V': '5V', 'OD': 'OD', None: None}
omodes = ['5V', 'OD', None]
self.output_mode = config.getchoice('set_output_mode', omodes, None)
# Setup for sensor test
self.next_test_time = 0.
Expand Down
2 changes: 1 addition & 1 deletion klippy/extras/display/hd44780.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

BACKGROUND_PRIORITY_CLOCK = 0x7fffffff00000000
LINE_LENGTH_DEFAULT=20
LINE_LENGTH_OPTIONS={16:16, 20:20}
LINE_LENGTH_OPTIONS=[16, 20]

TextGlyphs = { 'right_arrow': b'\x7e' }

Expand Down
2 changes: 1 addition & 1 deletion klippy/extras/display/hd44780_spi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .. import bus

LINE_LENGTH_DEFAULT=20
LINE_LENGTH_OPTIONS={16:16, 20:20}
LINE_LENGTH_OPTIONS=[16, 20]

TextGlyphs = { 'right_arrow': b'\x7e' }

Expand Down
2 changes: 1 addition & 1 deletion klippy/extras/display/menu_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, config, callback):
# Register rotary encoder
encoder_pins = config.get('encoder_pins', None)
encoder_steps_per_detent = config.getchoice('encoder_steps_per_detent',
{2: 2, 4: 4}, 4)
[2, 4], 4)
if encoder_pins is not None:
try:
pin1, pin2 = encoder_pins.split(',')
Expand Down
2 changes: 1 addition & 1 deletion klippy/extras/probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def __init__(self, config, mcu_probe):
self.sample_count = config.getint('samples', 1, minval=1)
self.sample_retract_dist = config.getfloat('sample_retract_dist', 2.,
above=0.)
atypes = {'median': 'median', 'average': 'average'}
atypes = ['median', 'average']
self.samples_result = config.getchoice('samples_result', atypes,
'average')
self.samples_tolerance = config.getfloat('samples_tolerance', 0.100,
Expand Down
2 changes: 1 addition & 1 deletion klippy/extras/replicape.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def __init__(self, config):
printer = config.get_printer()
ppins = printer.lookup_object('pins')
ppins.register_chip('replicape', self)
revisions = {'B3': 'B3'}
revisions = ['B3']
config.getchoice('revision', revisions)
self.host_mcu = mcu.get_printer_mcu(printer, config.get('host_mcu'))
# Setup enable pin
Expand Down
2 changes: 1 addition & 1 deletion klippy/kinematics/cartesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, toolhead, config):
self.dc_module = None
if config.has_section('dual_carriage'):
dc_config = config.getsection('dual_carriage')
dc_axis = dc_config.getchoice('axis', {'x': 'x', 'y': 'y'})
dc_axis = dc_config.getchoice('axis', ['x', 'y'])
self.dual_carriage_axis = {'x': 0, 'y': 1}[dc_axis]
# setup second dual carriage rail
self.rails.append(stepper.LookupMultiRail(dc_config))
Expand Down
2 changes: 1 addition & 1 deletion klippy/kinematics/hybrid_corexy.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, toolhead, config):
if config.has_section('dual_carriage'):
dc_config = config.getsection('dual_carriage')
# dummy for cartesian config users
dc_config.getchoice('axis', {'x': 'x'}, default='x')
dc_config.getchoice('axis', ['x'], default='x')
# setup second dual carriage rail
self.rails.append(stepper.PrinterRail(dc_config))
self.rails[1].get_endstops()[0][0].add_stepper(
Expand Down
2 changes: 1 addition & 1 deletion klippy/kinematics/hybrid_corexz.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, toolhead, config):
if config.has_section('dual_carriage'):
dc_config = config.getsection('dual_carriage')
# dummy for cartesian config users
dc_config.getchoice('axis', {'x': 'x'}, default='x')
dc_config.getchoice('axis', ['x'], default='x')
# setup second dual carriage rail
self.rails.append(stepper.PrinterRail(dc_config))
self.rails[2].get_endstops()[0][0].add_stepper(
Expand Down
3 changes: 1 addition & 2 deletions klippy/mcu.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,8 @@ def __init__(self, config, clocksync):
restart_methods = [None, 'arduino', 'cheetah', 'command', 'rpi_usb']
self._restart_method = 'command'
if self._baud:
rmethods = {m: m for m in restart_methods}
self._restart_method = config.getchoice('restart_method',
rmethods, None)
restart_methods, None)
self._reset_cmd = self._config_reset_cmd = None
self._is_mcu_bridge = False
self._emergency_stop_cmd = None
Expand Down

0 comments on commit 11f04ba

Please sign in to comment.