aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--klippy/configfile.py5
-rw-r--r--klippy/extras/display/hd44780.py12
-rw-r--r--klippy/extras/display/hd44780_spi.py12
-rw-r--r--klippy/extras/spi_temperature.py12
-rw-r--r--klippy/extras/tmc.py7
5 files changed, 24 insertions, 24 deletions
diff --git a/klippy/configfile.py b/klippy/configfile.py
index d6fd8beb..c24cfe16 100644
--- a/klippy/configfile.py
+++ b/klippy/configfile.py
@@ -69,7 +69,10 @@ class ConfigWrapper:
return self._get_wrapper(self.fileconfig.getboolean, option, default,
note_valid=note_valid)
def getchoice(self, option, choices, default=sentinel, note_valid=True):
- c = self.get(option, default, note_valid=note_valid)
+ 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)
if c not in choices:
raise error("Choice '%s' for option '%s' in section '%s'"
" is not a valid choice" % (c, option, self.section))
diff --git a/klippy/extras/display/hd44780.py b/klippy/extras/display/hd44780.py
index 7d7b5c6b..ea161348 100644
--- a/klippy/extras/display/hd44780.py
+++ b/klippy/extras/display/hd44780.py
@@ -7,8 +7,8 @@
import logging
BACKGROUND_PRIORITY_CLOCK = 0x7fffffff00000000
-LINE_LENGTH_DEFAULT="20"
-LINE_LENGTH_OPTIONS={"16":16, "20":20}
+LINE_LENGTH_DEFAULT=20
+LINE_LENGTH_OPTIONS={16:16, 20:20}
TextGlyphs = { 'right_arrow': '\x7e' }
@@ -22,9 +22,9 @@ class HD44780:
pins = [ppins.lookup_pin(config.get(name + '_pin'))
for name in ['rs', 'e', 'd4', 'd5', 'd6', 'd7']]
self.hd44780_protocol_init = config.getboolean('hd44780_protocol_init',
- True)
+ True)
self.line_length = config.getchoice('line_length', LINE_LENGTH_OPTIONS,
- LINE_LENGTH_DEFAULT)
+ LINE_LENGTH_DEFAULT)
mcu = None
for pin_params in pins:
if mcu is not None and pin_params['chip'] != mcu:
@@ -43,9 +43,9 @@ class HD44780:
self.all_framebuffers = [
# Text framebuffers
(self.text_framebuffers[0], bytearray('~'*2*self.line_length),
- 0x80),
+ 0x80),
(self.text_framebuffers[1], bytearray('~'*2*self.line_length),
- 0xc0),
+ 0xc0),
# Glyph framebuffer
(self.glyph_framebuffer, bytearray('~'*64), 0x40) ]
def build_config(self):
diff --git a/klippy/extras/display/hd44780_spi.py b/klippy/extras/display/hd44780_spi.py
index a935a832..97edef31 100644
--- a/klippy/extras/display/hd44780_spi.py
+++ b/klippy/extras/display/hd44780_spi.py
@@ -8,8 +8,8 @@
import logging
from .. import bus
-LINE_LENGTH_DEFAULT="20"
-LINE_LENGTH_OPTIONS={"16":16, "20":20}
+LINE_LENGTH_DEFAULT=20
+LINE_LENGTH_OPTIONS={16:16, 20:20}
TextGlyphs = { 'right_arrow': '\x7e' }
@@ -19,7 +19,7 @@ class hd44780_spi:
def __init__(self, config):
self.printer = config.get_printer()
self.hd44780_protocol_init = config.getboolean('hd44780_protocol_init',
- True)
+ True)
# spi config
self.spi = bus.MCU_SPI_from_config(
config, 0x00, pin_option="latch_pin")
@@ -31,7 +31,7 @@ class hd44780_spi:
self.icons = {}
self.line_length = config.getchoice('line_length', LINE_LENGTH_OPTIONS,
- LINE_LENGTH_DEFAULT)
+ LINE_LENGTH_DEFAULT)
# framebuffers
self.text_framebuffers = [bytearray(' '*2*self.line_length),
@@ -40,9 +40,9 @@ class hd44780_spi:
self.all_framebuffers = [
# Text framebuffers
(self.text_framebuffers[0], bytearray('~'*2*self.line_length),
- 0x80),
+ 0x80),
(self.text_framebuffers[1], bytearray('~'*2*self.line_length),
- 0xc0),
+ 0xc0),
# Glyph framebuffer
(self.glyph_framebuffer, bytearray('~'*64), 0x40) ]
def send_4_bits(self, cmd, is_data, minclock):
diff --git a/klippy/extras/spi_temperature.py b/klippy/extras/spi_temperature.py
index 31efea58..1a45a624 100644
--- a/klippy/extras/spi_temperature.py
+++ b/klippy/extras/spi_temperature.py
@@ -167,13 +167,13 @@ class MAX31856(SensorBase):
}
value = config.getchoice('tc_type', types, default="K")
averages = {
- "1" : MAX31856_CR1_AVGSEL1,
- "2" : MAX31856_CR1_AVGSEL2,
- "4" : MAX31856_CR1_AVGSEL4,
- "8" : MAX31856_CR1_AVGSEL8,
- "16" : MAX31856_CR1_AVGSEL16
+ 1 : MAX31856_CR1_AVGSEL1,
+ 2 : MAX31856_CR1_AVGSEL2,
+ 4 : MAX31856_CR1_AVGSEL4,
+ 8 : MAX31856_CR1_AVGSEL8,
+ 16 : MAX31856_CR1_AVGSEL16
}
- value |= config.getchoice('tc_averaging_count', averages, "1")
+ value |= config.getchoice('tc_averaging_count', averages, 1)
cmds.append(value)
value = (MAX31856_MASK_VOLTAGE_UNDER_OVER_FAULT |
diff --git a/klippy/extras/tmc.py b/klippy/extras/tmc.py
index d849c1bb..0279a040 100644
--- a/klippy/extras/tmc.py
+++ b/klippy/extras/tmc.py
@@ -472,11 +472,8 @@ def TMCMicrostepHelper(config, mcu_tmc):
and config.get('microsteps', None, note_valid=False) is not None):
# Older config format with microsteps in tmc config section
ms_config = config
- ms = ms_config.getint('microsteps')
- mres = {256: 0, 128: 1, 64: 2, 32: 3, 16: 4, 8: 5, 4: 6, 2: 7, 1: 8}.get(ms)
- if mres is None:
- raise config.error("Invalid '%s' microstep setting (%d)"
- % (config.get_name(), ms))
+ steps = {256: 0, 128: 1, 64: 2, 32: 3, 16: 4, 8: 5, 4: 6, 2: 7, 1: 8}
+ mres = ms_config.getchoice('microsteps', steps)
fields.set_field("mres", mres)
fields.set_field("intpol", config.getboolean("interpolate", True))