stepper: Use config.getlists() for gear_ratio config option

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-08-19 13:03:59 -04:00
parent f9ca5b9098
commit 67d99fe8a8
1 changed files with 4 additions and 10 deletions

View File

@ -215,17 +215,11 @@ def PrinterStepper(config, units_in_radians=False):
# Parse stepper gear_ratio config parameter # Parse stepper gear_ratio config parameter
def parse_gear_ratio(config, note_valid): def parse_gear_ratio(config, note_valid):
gear_ratio = config.get('gear_ratio', None, note_valid=note_valid) gear_ratio = config.getlists('gear_ratio', (), seps=(':', ','), count=2,
if gear_ratio is None: parser=float, note_valid=note_valid)
return 1.
result = 1. result = 1.
try: for g1, g2 in gear_ratio:
gears = gear_ratio.split(',') result *= g1 / g2
for gear in gears:
g1, g2 = [float(v.strip()) for v in gear.split(':')]
result *= g1 / g2
except:
raise config.error("Unable to parse gear_ratio: %s" % (gear_ratio,))
return result return result
# Obtain "step distance" information from a config section # Obtain "step distance" information from a config section