gcode: process_batch() should execute commands atomically

Update the process_batch() method so that it will not interleave
commands read from the input fd with the batched commands.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-10-18 11:51:35 -04:00
parent 37b9a2442f
commit a5e55c2acc
3 changed files with 26 additions and 23 deletions

View file

@ -15,7 +15,7 @@ class IdleTimeout:
self.toolhead = None
self.last_timeout = 0.
self.idle_timeout = config.getfloat('timeout', 600., above=0.)
self.idle_script = config.get('gcode', DEFAULT_IDLE_GCODE)
self.idle_gcode = config.get('gcode', DEFAULT_IDLE_GCODE).split('\n')
def printer_state(self, state):
if state == 'ready':
self.toolhead = self.printer.lookup_object('toolhead')
@ -23,14 +23,14 @@ class IdleTimeout:
reactor.register_timer(self.timeout_handler, reactor.NOW)
def run_idle_script(self):
gcode = self.printer.lookup_object('gcode')
for line in self.idle_script.split('\n'):
try:
res = gcode.process_batch(line)
except:
break
if not res:
# Raced with incoming g-code commands
return
try:
res = gcode.process_batch(self.idle_gcode)
except:
logging.exception("idle timeout gcode execution")
return
if not res:
# Raced with incoming g-code commands
return
self.last_timeout = self.toolhead.get_last_move_time()
def timeout_handler(self, eventtime):
info = self.toolhead.get_status(eventtime)