pause_resume: use new save/restore gcodes to handle state

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2019-05-31 12:13:28 -04:00 committed by KevinOConnor
parent 89650a1e60
commit ca8233e6d5
1 changed files with 15 additions and 30 deletions

View File

@ -9,25 +9,23 @@ class PauseResume:
self.printer = config.get_printer() self.printer = config.get_printer()
self.gcode = self.printer.lookup_object('gcode') self.gcode = self.printer.lookup_object('gcode')
self.recover_velocity = config.getfloat('recover_velocity', 50.) self.recover_velocity = config.getfloat('recover_velocity', 50.)
self.captured_position = None self.v_sd = None
self.captured_speed = 0. self.is_paused = False
self.captured_epos = None
self.toolhead = self.v_sd = None
self.pause_command_sent = False
self.sd_paused = False self.sd_paused = False
self.pause_command_sent = False
self.printer.register_event_handler("klippy:ready", self.handle_ready) self.printer.register_event_handler("klippy:ready", self.handle_ready)
self.gcode.register_command("PAUSE", self.cmd_PAUSE) self.gcode.register_command("PAUSE", self.cmd_PAUSE)
self.gcode.register_command("RESUME", self.cmd_RESUME) self.gcode.register_command("RESUME", self.cmd_RESUME)
def handle_ready(self): def handle_ready(self):
self.toolhead = self.printer.lookup_object('toolhead')
self.v_sd = self.printer.lookup_object('virtual_sdcard', None) self.v_sd = self.printer.lookup_object('virtual_sdcard', None)
def get_status(self, eventtime): def get_status(self, eventtime):
paused = self.captured_position is not None
return { return {
'is_paused': paused 'is_paused': self.is_paused
} }
def send_pause_command(self): def send_pause_command(self):
# This sends the appropriate pause command from an event. # This sends the appropriate pause command from an event. Note
# the difference between pause_command_sent and is_paused, the
# module isn't officially paused until the PAUSE gcode executes.
if not self.pause_command_sent: if not self.pause_command_sent:
if self.v_sd is not None and self.v_sd.is_active(): if self.v_sd is not None and self.v_sd.is_active():
# Printing from virtual sd, run pause command # Printing from virtual sd, run pause command
@ -38,36 +36,23 @@ class PauseResume:
self.gcode.respond_info("action:pause") self.gcode.respond_info("action:pause")
self.pause_command_sent = True self.pause_command_sent = True
def cmd_PAUSE(self, params): def cmd_PAUSE(self, params):
if self.captured_position is not None: if self.is_paused:
self.gcode.respond_info("Print already paused") self.gcode.respond_info("Print already paused")
return return
self.send_pause_command() self.send_pause_command()
self.toolhead.wait_moves() self.gcode.run_script_from_command(
self.captured_position = self.toolhead.get_position() "SAVE_GCODE_STATE STATE=PAUSE_STATE")
reactor = self.printer.get_reactor() self.is_paused = True
gcs = self.gcode.get_status(reactor.monotonic())
self.captured_speed = gcs['speed']
if gcs['abs_extrude']:
self.captured_epos = gcs['last_epos'] - gcs['base_epos']
def cmd_RESUME(self, params): def cmd_RESUME(self, params):
if self.captured_position is None: if not self.is_paused:
self.gcode.respond_info("Print is not paused, resume aborted") self.gcode.respond_info("Print is not paused, resume aborted")
return return
velocity = self.gcode.get_float( velocity = self.gcode.get_float(
'VELOCITY', params, self.recover_velocity) 'VELOCITY', params, self.recover_velocity)
cur_pos = self.toolhead.get_position()
self.captured_position[3] = cur_pos[3]
self.toolhead.move(self.captured_position, velocity)
self.toolhead.get_last_move_time()
self.gcode.reset_last_position()
# restore previous speed
self.gcode.run_script_from_command( self.gcode.run_script_from_command(
"G1 F%.6f" % (self.captured_speed)) "RESTORE_GCODE_STATE STATE=PAUSE_STATE MOVE=1 MOVE_SPEED=%.4f"
if self.captured_epos is not None: % (velocity))
self.gcode.run_script_from_command( self.is_paused = False
"G92 E%.6f" % (self.captured_epos))
self.captured_position = self.captured_epos = None
self.pause_command_sent = False self.pause_command_sent = False
if self.sd_paused: if self.sd_paused:
# Printing from virtual sd, run pause command # Printing from virtual sd, run pause command