pause_resume: fixes

- When using absolute extrusion the gcode position e-axis position is now captured on PAUSE and restored in RESUME with a call to the G92 handler.
- Add a get_status() function that returns a dictionary with an 'is_paused' key.
- Do not allow consective calls to PAUSE or RESUME to exectue.  Also do not allow a RESUME to executed without a previous PAUSE.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2019-01-31 19:14:12 -05:00 committed by KevinOConnor
parent ca4e10dbd6
commit 9766d62ad3
1 changed files with 28 additions and 12 deletions

View File

@ -11,6 +11,7 @@ class PauseResume:
self.recover_velocity = config.getfloat('recover_velocity', 50.)
self.captured_position = None
self.captured_speed = 0.
self.captured_epos = None
self.toolhead = self.v_sd = None
self.sd_paused = False
self.printer.register_event_handler("klippy:ready", self.handle_ready)
@ -19,7 +20,15 @@ class PauseResume:
def handle_ready(self):
self.toolhead = self.printer.lookup_object('toolhead')
self.v_sd = self.printer.lookup_object('virtual_sdcard', None)
def get_status(self, eventtime):
paused = self.captured_position is not None
return {
'is_paused': paused
}
def cmd_PAUSE(self, params):
if self.captured_position is not None:
self.gcode.respond_info("Print already paused")
return
if self.v_sd is not None and self.v_sd.is_active():
# Printing from virtual sd, run pause command
self.sd_paused = True
@ -30,13 +39,17 @@ class PauseResume:
self.toolhead.wait_moves()
self.captured_position = self.toolhead.get_position()
reactor = self.printer.get_reactor()
gc_status = self.gcode.get_status(reactor.monotonic())
self.captured_speed = gc_status['speed']
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):
if self.captured_position is None:
self.gcode.respond_info("Print is not paused, resume aborted")
return
velocity = self.gcode.get_float(
'VELOCITY', params, self.recover_velocity)
if self.captured_position is not None:
# restore previous xyz position
cur_pos = self.toolhead.get_position()
self.captured_position[3] = cur_pos[3]
self.toolhead.move(self.captured_position, velocity)
@ -45,7 +58,10 @@ class PauseResume:
# restore previous speed
self.gcode.run_script_from_command(
"G1 F%.6f" % (self.captured_speed))
self.captured_position = None
if self.captured_epos is not None:
self.gcode.run_script_from_command(
"G92 E%.6f" % (self.captured_epos))
self.captured_position = self.captured_epos = None
if self.sd_paused:
# Printing from virtual sd, run pause command
self.v_sd.cmd_M24({})