Added abort, start & pause

USL-541
This commit is contained in:
Jaime van Kessel 2017-12-15 15:00:10 +01:00
parent 6bdce54e1d
commit 0ac48817b2
2 changed files with 39 additions and 0 deletions

View file

@ -31,6 +31,17 @@ class USBPrinterOuptutController(PrinterOutputController):
def homeBed(self, printer): def homeBed(self, printer):
self._output_device.sendCommand("G28 Z") self._output_device.sendCommand("G28 Z")
def setJobState(self, job: "PrintJobOutputModel", state: str):
if state == "pause":
self._output_device.pausePrint()
job.updateState("paused")
elif state == "print":
self._output_device.resumePrint()
job.updateState("printing")
elif state == "abort":
self._output_device.cancelPrint()
pass
def preheatBed(self, printer: "PrinterOutputModel", temperature, duration): def preheatBed(self, printer: "PrinterOutputModel", temperature, duration):
try: try:
temperature = round(temperature) # The API doesn't allow floating point. temperature = round(temperature) # The API doesn't allow floating point.

View file

@ -60,6 +60,8 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
self._accepts_commands = True self._accepts_commands = True
self._paused = False
# Queue for commands that need to be send. Used when command is sent when a print is active. # Queue for commands that need to be send. Used when command is sent when a print is active.
self._command_queue = Queue() self._command_queue = Queue()
@ -83,6 +85,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
# \param gcode_list List with gcode (strings). # \param gcode_list List with gcode (strings).
def _printGCode(self, gcode_list): def _printGCode(self, gcode_list):
self._gcode.clear() self._gcode.clear()
self._paused = False
for layer in gcode_list: for layer in gcode_list:
self._gcode.extend(layer.split("\n")) self._gcode.extend(layer.split("\n"))
@ -179,6 +182,8 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
if b"ok" in line: if b"ok" in line:
if not self._command_queue.empty(): if not self._command_queue.empty():
self._sendCommand(self._command_queue.get()) self._sendCommand(self._command_queue.get())
elif self._paused:
pass # Nothing to do!
else: else:
self._sendNextGcodeLine() self._sendNextGcodeLine()
elif b"resend" in line.lower() or b"rs" in line: elif b"resend" in line.lower() or b"rs" in line:
@ -190,6 +195,29 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
# In some cases of the RS command it needs to be handled differently. # In some cases of the RS command it needs to be handled differently.
self._gcode_position = int(line.split()[1]) self._gcode_position = int(line.split()[1])
def pausePrint(self):
self._paused = True
def resumePrint(self):
self._paused = False
def cancelPrint(self):
self._gcode_position = 0
self._gcode.clear()
self._printers[0].updateActivePrintJob(None)
self._is_printing = False
self._is_paused = False
# Turn off temperatures, fan and steppers
self._sendCommand("M140 S0")
self._sendCommand("M104 S0")
self._sendCommand("M107")
# Home XY to prevent nozzle resting on aborted print
# Don't home bed because it may crash the printhead into the print on printers that home on the bottom
self.printers[0].homeHead()
self._sendCommand("M84")
def _sendNextGcodeLine(self): def _sendNextGcodeLine(self):
if self._gcode_position >= len(self._gcode): if self._gcode_position >= len(self._gcode):
self._printers[0].updateActivePrintJob(None) self._printers[0].updateActivePrintJob(None)