configfile: Support config.getchoice() with integer keys
If the choice mapping uses integer keys then lookup the config option using self.getint(). This simplifies the callers and improves the encoding of the printer.configfile.settings export. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
75183bfb86
commit
84ac5b0146
|
@ -69,6 +69,9 @@ class ConfigWrapper:
|
||||||
return self._get_wrapper(self.fileconfig.getboolean, option, default,
|
return self._get_wrapper(self.fileconfig.getboolean, option, default,
|
||||||
note_valid=note_valid)
|
note_valid=note_valid)
|
||||||
def getchoice(self, option, choices, default=sentinel, note_valid=True):
|
def getchoice(self, option, choices, default=sentinel, note_valid=True):
|
||||||
|
if choices and type(list(choices.keys())[0]) == int:
|
||||||
|
c = self.getint(option, default, note_valid=note_valid)
|
||||||
|
else:
|
||||||
c = self.get(option, default, note_valid=note_valid)
|
c = self.get(option, default, note_valid=note_valid)
|
||||||
if c not in choices:
|
if c not in choices:
|
||||||
raise error("Choice '%s' for option '%s' in section '%s'"
|
raise error("Choice '%s' for option '%s' in section '%s'"
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
BACKGROUND_PRIORITY_CLOCK = 0x7fffffff00000000
|
BACKGROUND_PRIORITY_CLOCK = 0x7fffffff00000000
|
||||||
LINE_LENGTH_DEFAULT="20"
|
LINE_LENGTH_DEFAULT=20
|
||||||
LINE_LENGTH_OPTIONS={"16":16, "20":20}
|
LINE_LENGTH_OPTIONS={16:16, 20:20}
|
||||||
|
|
||||||
TextGlyphs = { 'right_arrow': '\x7e' }
|
TextGlyphs = { 'right_arrow': '\x7e' }
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
import logging
|
import logging
|
||||||
from .. import bus
|
from .. import bus
|
||||||
|
|
||||||
LINE_LENGTH_DEFAULT="20"
|
LINE_LENGTH_DEFAULT=20
|
||||||
LINE_LENGTH_OPTIONS={"16":16, "20":20}
|
LINE_LENGTH_OPTIONS={16:16, 20:20}
|
||||||
|
|
||||||
TextGlyphs = { 'right_arrow': '\x7e' }
|
TextGlyphs = { 'right_arrow': '\x7e' }
|
||||||
|
|
||||||
|
|
|
@ -167,13 +167,13 @@ class MAX31856(SensorBase):
|
||||||
}
|
}
|
||||||
value = config.getchoice('tc_type', types, default="K")
|
value = config.getchoice('tc_type', types, default="K")
|
||||||
averages = {
|
averages = {
|
||||||
"1" : MAX31856_CR1_AVGSEL1,
|
1 : MAX31856_CR1_AVGSEL1,
|
||||||
"2" : MAX31856_CR1_AVGSEL2,
|
2 : MAX31856_CR1_AVGSEL2,
|
||||||
"4" : MAX31856_CR1_AVGSEL4,
|
4 : MAX31856_CR1_AVGSEL4,
|
||||||
"8" : MAX31856_CR1_AVGSEL8,
|
8 : MAX31856_CR1_AVGSEL8,
|
||||||
"16" : MAX31856_CR1_AVGSEL16
|
16 : MAX31856_CR1_AVGSEL16
|
||||||
}
|
}
|
||||||
value |= config.getchoice('tc_averaging_count', averages, "1")
|
value |= config.getchoice('tc_averaging_count', averages, 1)
|
||||||
cmds.append(value)
|
cmds.append(value)
|
||||||
|
|
||||||
value = (MAX31856_MASK_VOLTAGE_UNDER_OVER_FAULT |
|
value = (MAX31856_MASK_VOLTAGE_UNDER_OVER_FAULT |
|
||||||
|
|
|
@ -472,11 +472,8 @@ def TMCMicrostepHelper(config, mcu_tmc):
|
||||||
and config.get('microsteps', None, note_valid=False) is not None):
|
and config.get('microsteps', None, note_valid=False) is not None):
|
||||||
# Older config format with microsteps in tmc config section
|
# Older config format with microsteps in tmc config section
|
||||||
ms_config = config
|
ms_config = config
|
||||||
ms = ms_config.getint('microsteps')
|
steps = {256: 0, 128: 1, 64: 2, 32: 3, 16: 4, 8: 5, 4: 6, 2: 7, 1: 8}
|
||||||
mres = {256: 0, 128: 1, 64: 2, 32: 3, 16: 4, 8: 5, 4: 6, 2: 7, 1: 8}.get(ms)
|
mres = ms_config.getchoice('microsteps', steps)
|
||||||
if mres is None:
|
|
||||||
raise config.error("Invalid '%s' microstep setting (%d)"
|
|
||||||
% (config.get_name(), ms))
|
|
||||||
fields.set_field("mres", mres)
|
fields.set_field("mres", mres)
|
||||||
fields.set_field("intpol", config.getboolean("interpolate", True))
|
fields.set_field("intpol", config.getboolean("interpolate", True))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue