From fecc162b5d671934e612745e3282202acf96f11c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 16 May 2019 11:31:00 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20"starting"=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/octoprint/comm/protocol/__init__.py | 13 +++++++++---- src/octoprint/comm/protocol/reprap/__init__.py | 15 +++++++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/octoprint/comm/protocol/__init__.py b/src/octoprint/comm/protocol/__init__.py index 7430750d6..0214aaa68 100644 --- a/src/octoprint/comm/protocol/__init__.py +++ b/src/octoprint/comm/protocol/__init__.py @@ -213,26 +213,30 @@ class Protocol(ListenerAware, TransportListener): def process(self, job, position=0, user=None, tags=None, **kwargs): if not job.can_process(self): raise ValueError("Job {} cannot be processed with protocol {}".format(job, self)) + self._job = job self._job.register_listener(self) + + self.state = ProtocolState.STARTING + self.notify_listeners("on_protocol_job_starting", self, self._job, user=user, tags=tags, **kwargs) self._job.process(self, position=position, user=user, tags=tags, **kwargs) def pause_processing(self, user=None, tags=None, **kwargs): - if self._job is None or self.state != ProtocolState.PROCESSING: + if self._job is None or self.state not in ProtocolState.PROCESSING_STATES: return self.state = ProtocolState.PAUSING self.notify_listeners("on_protocol_job_pausing", self, self._job, user=user, tags=tags, **kwargs) self._job.pause(user=user, tags=tags) def resume_processing(self, user=None, tags=None, **kwargs): - if self._job is None or self.state != ProtocolState.PAUSED: + if self._job is None or self.state not in (ProtocolState.PAUSING, ProtocolState.PAUSED): return self.state = ProtocolState.RESUMING self.notify_listeners("on_protocol_job_resuming", self, self._job, user=user, tags=tags, **kwargs) self._job.resume(user=user, tags=tags, **kwargs) def cancel_processing(self, error=False, user=None, tags=None, **kwargs): - if self._job is not None and self.state in (ProtocolState.PROCESSING, ProtocolState.PAUSED): + if self._job is not None and self.state in ProtocolState.PROCESSING_STATES + (ProtocolState.PAUSED,): self.state = ProtocolState.CANCELLING self.notify_listeners("on_protocol_job_cancelling", self, self._job, user=user, tags=tags, **kwargs) self._job.cancel(error=error, user=user, tags=tags, **kwargs) @@ -317,6 +321,7 @@ class ProtocolState(object): CONNECTED = "connected" DISCONNECTING = "disconnecting" DISCONNECTED = "disconnected" + STARTING = "starting" PROCESSING = "processing" FINISHING = "finishing" CANCELLING = "cancelling" @@ -327,7 +332,7 @@ class ProtocolState(object): DISCONNECTING_WITH_ERROR = "disconnecting_with_error" DISCONNECTED_WITH_ERROR = "disconnected_with_error" - PROCESSING_STATES = (PROCESSING, CANCELLING, PAUSING, RESUMING, FINISHING) + PROCESSING_STATES = (STARTING, PROCESSING, CANCELLING, PAUSING, RESUMING, FINISHING) OPERATIONAL_STATES = (CONNECTED, PAUSED) + PROCESSING_STATES class ProtocolSettings(SubSettings): diff --git a/src/octoprint/comm/protocol/reprap/__init__.py b/src/octoprint/comm/protocol/reprap/__init__.py index 76a90e503..b93ca6b1a 100644 --- a/src/octoprint/comm/protocol/reprap/__init__.py +++ b/src/octoprint/comm/protocol/reprap/__init__.py @@ -392,7 +392,7 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt self._continue_sending() def cancel_processing(self, error=False, user=None, tags=None, log_position=True): - if self.state not in (ProtocolState.PROCESSING, ProtocolState.PAUSED, ProtocolState.PAUSING): + if self.state not in ProtocolState.PROCESSING_STATES + (ProtocolState.PAUSED,): return if self._job is None: @@ -806,6 +806,17 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt ##~~ Job handling + def on_job_started(self, job, *args, **kwargs): + if job != self._job: + return + + self.notify_listeners("on_protocol_job_started", self, job, *args, **kwargs) + + def finalize(): + self.state = ProtocolState.PROCESSING + self.send_commands(SendQueueMarker(finalize)) + self._continue_sending() + def on_job_cancelled(self, job, *args, **kwargs): if job != self._job: return @@ -1288,7 +1299,7 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt actual, target = temperatures[tool] self._internal_flags["temperatures"].set_tool(x, actual=actual, target=target) - if "B" in temperatures: + if "B" in temperatures and self._printer_profile["heatedBed"]: actual, target = temperatures["B"] self._internal_flags["temperatures"].set_bed(actual=actual, target=target)