gcode: Improve end-of-file handling when input is a debug file

Wait for any pending moves to be fully handled before exiting.  Make
sure the wait is done inside the "self.is_processing_data" check to
avoid infinite recursion.  Don't keep reading from the file while
waiting to exit.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-07-21 21:13:59 -04:00
parent 19090bdd5b
commit 7faa5fe233
1 changed files with 10 additions and 7 deletions

View File

@ -126,9 +126,10 @@ class GCodeParser:
lines[0] = self.partial_input + lines[0] lines[0] = self.partial_input + lines[0]
self.partial_input = lines.pop() self.partial_input = lines.pop()
if self.is_processing_data: if self.is_processing_data:
if not self.is_fileinput:
if not lines: if not lines:
return return
if not self.is_fileinput and lines[0].strip().upper() == 'M112': if lines[0].strip().upper() == 'M112':
self.cmd_M112({}) self.cmd_M112({})
self.reactor.unregister_fd(self.fd_handle) self.reactor.unregister_fd(self.fd_handle)
self.fd_handle = None self.fd_handle = None
@ -136,12 +137,14 @@ class GCodeParser:
eventtime = self.reactor.pause(eventtime + 0.100) eventtime = self.reactor.pause(eventtime + 0.100)
self.is_processing_data = True self.is_processing_data = True
self.process_commands(lines) self.process_commands(lines)
if not data and self.is_fileinput:
self.motor_heater_off()
if self.toolhead is not None:
self.toolhead.wait_moves()
self.printer.request_exit('exit_eof')
self.is_processing_data = False self.is_processing_data = False
if self.fd_handle is None: if self.fd_handle is None:
self.fd_handle = self.reactor.register_fd(self.fd, self.process_data) self.fd_handle = self.reactor.register_fd(self.fd, self.process_data)
if not data and self.is_fileinput:
self.motor_heater_off()
self.printer.request_exit('exit_eof')
# Response handling # Response handling
def ack(self, msg=None): def ack(self, msg=None):
if not self.need_ack or self.is_fileinput: if not self.need_ack or self.is_fileinput: