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
def parse_gear_ratio(config, note_valid):
gear_ratio = config.get('gear_ratio', None, note_valid=note_valid)
if gear_ratio is None:
return 1.
gear_ratio = config.getlists('gear_ratio', (), seps=(':', ','), count=2,
parser=float, note_valid=note_valid)
result = 1.
try:
gears = gear_ratio.split(',')
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,))
for g1, g2 in gear_ratio:
result *= g1 / g2
return result
# Obtain "step distance" information from a config section