From ecf53e6194a7ccdc7015faa79ad3f74f6f7a5d1a Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 30 Jun 2018 14:10:59 -0400 Subject: [PATCH] gcode: Add run_script() method that is valid from non-command contexts Add an ability to run a series of g-code commands from a reactor callback that isn't part of the normal g-code command processing. Signed-off-by: Kevin O'Connor --- klippy/gcode.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/klippy/gcode.py b/klippy/gcode.py index 38e1124b..0ea50751 100644 --- a/klippy/gcode.py +++ b/klippy/gcode.py @@ -241,6 +241,17 @@ class GCodeParser: self.process_commands(script.split('\n'), need_ack=False) finally: self.need_ack = prev_need_ack + def run_script(self, script): + curtime = self.reactor.monotonic() + for line in script.split('\n'): + while 1: + try: + res = self.process_batch(line) + except: + break + if res: + break + curtime = self.reactor.pause(curtime + 0.100) # Response handling def ack(self, msg=None): if not self.need_ack or self.is_fileinput: