diff --git a/src/octoprint/comm/protocol/__init__.py b/src/octoprint/comm/protocol/__init__.py index 926aeb80a..6a574b248 100644 --- a/src/octoprint/comm/protocol/__init__.py +++ b/src/octoprint/comm/protocol/__init__.py @@ -118,6 +118,12 @@ class Protocol(MessageReceiver, StateReceiver, LogReceiver): "origin": self._current_file.getFileLocation() }) self._changeState(State.OPERATIONAL) + self._print_cancelled() + if self._protocol_listener is not None: + self._protocol_listener.onPrintjobCancelled(self) + + def _print_cancelled(self): + pass def init_sd(self): pass @@ -472,9 +478,15 @@ class ProtocolListener(object): def onFileSelected(self, source, filename, filesize, origin): pass + def onPrintjobStarted(self, source): + pass + def onPrintjobDone(self, source): pass + def onPrintjobCancelled(self, source): + pass + def onFileTransferStarted(self, source, filename, filesize): pass diff --git a/src/octoprint/comm/protocol/reprap/__init__.py b/src/octoprint/comm/protocol/reprap/__init__.py index aac2d148e..85925590b 100644 --- a/src/octoprint/comm/protocol/reprap/__init__.py +++ b/src/octoprint/comm/protocol/reprap/__init__.py @@ -146,7 +146,7 @@ class RepRapProtocol(Protocol): self._sdstatus_interval = 5.0 self._sent_lines = deque([]) - self._sent_lock = threading.RLock() + self._send_lock = threading.RLock() self._previous_resend = False self._last_comm_error = None @@ -199,7 +199,7 @@ class RepRapProtocol(Protocol): self._preprocessors[postfix][code] = getattr(self, attr) def _reset(self, from_start=False): - with self._sent_lock: + with self._send_lock: self._lastTemperatureUpdate = time.time() self._lastSdProgressUpdate = time.time() @@ -280,9 +280,10 @@ class RepRapProtocol(Protocol): Protocol.cancel_print(self) + def _print_cancelled(self): with self._fill_queue_mutex: cleared = self._send_queue.clear(matcher=lambda entry: entry is not None and entry.command is not None and hasattr(entry.command, "progress") and entry.command.progress is not None and (not hasattr(entry, "prepared") or entry.prepared is None)) - self._logger.debug("Cleared %d entries from the send queue: %r" % (len(cleared), cleared)) + self._logger.debug("Cleared %d job entries from the send queue: %r" % (len(cleared), cleared)) def init_sd(self): Protocol.init_sd(self) @@ -537,7 +538,7 @@ class RepRapProtocol(Protocol): ##~~ private def _process_acknowledgement(self): - with self._sent_lock: + with self._send_lock: if len(self._sent_lines) > 0: entry = self._sent_lines.popleft() @@ -736,7 +737,7 @@ class RepRapProtocol(Protocol): self._last_comm_error = None if line_to_resend is not None: - with self._sent_lock: + with self._send_lock: if len(self._sent_lines) > 0: nack_entry = self._sent_lines[0] @@ -823,7 +824,7 @@ class RepRapProtocol(Protocol): continue try: - with self._sent_lock: + with self._send_lock: sent = self._send_from_queue() except SendTimeout: # we just got a send timeout, so we'll just try again on the next loop iteration diff --git a/src/octoprint/printer.py b/src/octoprint/printer.py index bfbae49e4..ba6824613 100644 --- a/src/octoprint/printer.py +++ b/src/octoprint/printer.py @@ -205,12 +205,9 @@ class Printer(): # forward relevant state changes to gcode manager if oldState == ProtocolState.PRINTING: - if self._selectedFile is not None: - if newState == ProtocolState.OPERATIONAL: - self._fileManager.log_print(FileDestinations.SDCARD if self._selectedFile["sd"] else FileDestinations.LOCAL, self._selectedFile["filename"], time.time(), self._protocol.get_print_time(), True) - elif newState == ProtocolState.OFFLINE or newState == ProtocolState.ERROR: - self._fileManager.log_print(FileDestinations.SDCARD if self._selectedFile["sd"] else FileDestinations.LOCAL, self._selectedFile["filename"], time.time(), self._protocol.get_print_time(), False) self._analysisQueue.resume() # printing done, put those cpu cycles to good use + if self._selectedFile is not None and newState == ProtocolState.OFFLINE or newState == ProtocolState.ERROR: + self._fileManager.log_print(FileDestinations.SDCARD if self._selectedFile["sd"] else FileDestinations.LOCAL, self._selectedFile["filename"], time.time(), self._protocol.get_print_time(), False) elif newState == ProtocolState.PRINTING: self._analysisQueue.pause() # do not analyse files while printing @@ -257,6 +254,16 @@ class Printer(): self._setProgressData(100.0, self._selectedFile["filesize"], self._protocol.get_print_time(), 0) self._stateMonitor.setState({"text": self.getStateString(), "flags": self._getStateFlags()}) + if self._selectedFile is not None: + self._fileManager.log_print(FileDestinations.SDCARD if self._selectedFile["sd"] else FileDestinations.LOCAL, self._selectedFile["filename"], time.time(), self._protocol.get_print_time(), True) + + def onPrintjobCancelled(self, source): + if not source == self._protocol: + return + + if self._selectedFile is not None: + self._fileManager.log_print(FileDestinations.SDCARD if self._selectedFile["sd"] else FileDestinations.LOCAL, self._selectedFile["filename"], time.time(), self._protocol.get_print_time(), False) + def onFileTransferStarted(self, source, filename, filesize): if not source == self._protocol: return