From cc5f119f1b7db764a85912bf6f05d60c2f79356d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 15 Nov 2016 11:56:30 +0100 Subject: [PATCH] Include position in PrintPaused and PrintCancelled events If available. Updated docs accordingly. --- docs/events/index.rst | 22 ++++++++++++++++++++++ src/octoprint/printer/standard.py | 23 ++++++++++++++--------- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/docs/events/index.rst b/docs/events/index.rst index 0b0139c9..506aaddd 100644 --- a/docs/events/index.rst +++ b/docs/events/index.rst @@ -308,6 +308,17 @@ PrintCancelled * ``name``: the file's name * ``path``: the file's path within its storage location * ``origin``: the origin storage location of the file, either ``local`` or ``sdcard`` + * ``position``: the print head position at the time of cancelling, if available + * ``position.x``: x coordinate, as reported back from the firmware through `M114` + * ``position.y``: y coordinate, as reported back from the firmware through `M114` + * ``position.z``: z coordinate, as reported back from the firmware through `M114` + * ``position.e``: e coordinate (of currently selected extruder), as reported back from the firmware through `M114` + * ``position.t``: last tool selected *through OctoPrint* (note that if you did change the printer's selected + tool outside of OctoPrint, e.g. through the printer controller, or if you are printing from SD, this will NOT + be accurate) + * ``position.f``: last feedrate for move commands **sent through OctoPrint** (note that if you modified the + feedrate outside of OctoPrint, e.g. through the printer controller, or if you are printing from SD, this will + NOT be accurate) .. deprecated:: 1.3.0 @@ -324,6 +335,17 @@ PrintPaused * ``name``: the file's name * ``path``: the file's path within its storage location * ``origin``: the origin storage location of the file, either ``local`` or ``sdcard`` + * ``position``: the print head position at the time of pausing, if available + * ``position.x``: x coordinate, as reported back from the firmware through `M114` + * ``position.y``: y coordinate, as reported back from the firmware through `M114` + * ``position.z``: z coordinate, as reported back from the firmware through `M114` + * ``position.e``: e coordinate (of currently selected extruder), as reported back from the firmware through `M114` + * ``position.t``: last tool selected *through OctoPrint* (note that if you did change the printer's selected + tool outside of OctoPrint, e.g. through the printer controller, or if you are printing from SD, this will NOT + be accurate) + * ``position.f``: last feedrate for move commands **sent through OctoPrint** (note that if you modified the + feedrate outside of OctoPrint, e.g. through the printer controller, or if you are printing from SD, this will + NOT be accurate) .. deprecated:: 1.3.0 diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 76eba336..fe7ed97a 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -1077,7 +1077,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): eventManager().fire(Events.PRINT_FAILED, payload) def on_comm_print_job_cancelled(self): - payload = self._payload_for_print_job_event() + payload = self._payload_for_print_job_event(position=self._comm.cancel_position.as_dict() if self._comm and self._comm.cancel_position else None) if payload: eventManager().fire(Events.PRINT_CANCELLED, payload) self.script("afterPrintCancelled", @@ -1085,7 +1085,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): must_be_set=False) def on_comm_print_job_paused(self): - payload = self._payload_for_print_job_event() + payload = self._payload_for_print_job_event(position=self._comm.pause_position.as_dict() if self._comm and self._comm.pause_position else None) if payload: eventManager().fire(Events.PRINT_PAUSED, payload) self.script("afterPrintPaused", @@ -1131,7 +1131,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): except: self._logger.exception("Error while trying to persist print recovery data") - def _payload_for_print_job_event(self, location=None, print_job_file=None): + def _payload_for_print_job_event(self, location=None, print_job_file=None, position=None): if print_job_file is None: selected_file = self._selectedFile if not selected_file: @@ -1156,13 +1156,18 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): _, name = self._fileManager.split_path(FileDestinations.LOCAL, path) origin = FileDestinations.LOCAL - return dict(name=name, - path=path, - origin=origin, + result= dict(name=name, + path=path, + origin=origin, - # TODO deprecated, remove in 1.4.0 - file=full_path, - filename=name) + # TODO deprecated, remove in 1.4.0 + file=full_path, + filename=name) + + if position is not None: + result["position"] = position + + return result class StateMonitor(object):