diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2017-03-12 19:55:56 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2017-03-13 00:38:17 -0400 |
commit | 1d796a4e24311dded166f74396662251672869fd (patch) | |
tree | 0d69fe742fc14bc8be9fc24769dd4f87ca37d961 /klippy/pins.py | |
parent | 8e6d5efdac4e8ced2d9c91fc1d8816a3c7df8286 (diff) | |
download | kutter-1d796a4e24311dded166f74396662251672869fd.tar.gz kutter-1d796a4e24311dded166f74396662251672869fd.tar.xz kutter-1d796a4e24311dded166f74396662251672869fd.zip |
mcu: Support config mechanism for translating seconds to clock ticks
Introduce a TICKS() macro during config parsing that will translate
time in seconds to time in clock ticks.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/pins.py')
-rw-r--r-- | klippy/pins.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/klippy/pins.py b/klippy/pins.py index 597e59b3..a4262a4e 100644 --- a/klippy/pins.py +++ b/klippy/pins.py @@ -100,9 +100,12 @@ def get_pin_map(mcu, mapping_name=None): pins['analog%d' % (i,)] = pins[apins[i]] return pins -# Translate pin names in a firmware command +# Translate pin names and tick times in a firmware command re_pin = re.compile(r'(?P<prefix>[ _]pin=)(?P<name>[^ ]*)') -def update_command(cmd, pmap): - def fixup(m): +re_ticks = re.compile(r'TICKS\((?P<ticks>[^)]*)\)') +def update_command(cmd, mcu_freq, pmap): + def pin_fixup(m): return m.group('prefix') + str(pmap[m.group('name')]) - return re_pin.sub(fixup, cmd) + def ticks_fixup(m): + return str(int(mcu_freq * float(m.group('ticks')))) + return re_ticks.sub(ticks_fixup, re_pin.sub(pin_fixup, cmd)) |