From 3f0bfa0fc8d8d1ee6e4b0ddde12fb7ed81d3559e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 26 Oct 2016 18:11:00 +0200 Subject: [PATCH] New POSITION_UPDATE event for responses to M114 --- src/octoprint/events.py | 1 + src/octoprint/printer/standard.py | 3 +++ src/octoprint/util/comm.py | 13 +++++++++++++ 3 files changed, 17 insertions(+) diff --git a/src/octoprint/events.py b/src/octoprint/events.py index 1791d5cb..b8f12ad0 100644 --- a/src/octoprint/events.py +++ b/src/octoprint/events.py @@ -78,6 +78,7 @@ class Events(object): CONVEYOR = "Conveyor" EJECT = "Eject" E_STOP = "EStop" + POSITION_UPDATE = "PositionUpdate" REGISTERED_MESSAGE_RECEIVED = "RegisteredMessageReceived" # Timelapse diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 082c4321..5a9719bc 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -956,6 +956,9 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): def on_comm_temperature_update(self, temp, bedTemp): self._addTemperatureData(copy.deepcopy(temp), copy.deepcopy(bedTemp)) + def on_comm_position_update(self, position): + eventManager().fire(Events.POSITION_UPDATE, position) + def on_comm_state_change(self, state): """ Callback method for the comm object, called if the connection state changes. diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 793dd9ae..1648ae85 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -220,6 +220,14 @@ class PositionRecord(object): self.f = other.f self.t = other.t + def as_dict(self): + return dict(x=self.x, + y=self.y, + z=self.z, + e=self.e, + t=self.t, + f=self.f) + class MachineCom(object): STATE_NONE = 0 STATE_OPEN_SERIAL = 1 @@ -1130,6 +1138,8 @@ class MachineCom(object): self._pause_position.copy_from(self._last_position) self._pause_preparation_done() + self._callback.on_comm_position_update(self._last_position.as_dict()) + # temperature processing elif ' T:' in line or line.startswith('T:') or ' T0:' in line or line.startswith('T0:') or ((' B:' in line or line.startswith('B:')) and not 'A:' in line): if not disable_external_heatup_detection and not line.strip().startswith("ok") and not self._heating: @@ -2341,6 +2351,9 @@ class MachineComPrintCallback(object): def on_comm_temperature_update(self, temp, bedTemp): pass + def on_comm_position_update(self, position): + pass + def on_comm_state_change(self, state): pass