From 4d27de032d4f749a6c942bfd6d8fca0207df8827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 28 Jul 2017 13:35:00 +0200 Subject: [PATCH] Improved handling of external reset while operational * Display message to user * Stop print/transfer (lost state) --- src/octoprint/events.py | 1 + src/octoprint/static/js/app/dataupdater.js | 8 +++++++- src/octoprint/util/comm.py | 21 ++++++++++++++++----- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/octoprint/events.py b/src/octoprint/events.py index 03a7daf2..f8c35558 100644 --- a/src/octoprint/events.py +++ b/src/octoprint/events.py @@ -40,6 +40,7 @@ class Events(object): # State changes PRINTER_STATE_CHANGED = "PrinterStateChanged" + PRINTER_RESET = "PrinterReset" # connect/disconnect by client CLIENT_OPENED = "ClientOpened" diff --git a/src/octoprint/static/js/app/dataupdater.js b/src/octoprint/static/js/app/dataupdater.js index 10831303..06a15c12 100644 --- a/src/octoprint/static/js/app/dataupdater.js +++ b/src/octoprint/static/js/app/dataupdater.js @@ -238,11 +238,17 @@ function DataUpdater(allViewModels, connectCallback, disconnectCallback) { if (payload.error && payload.error.indexOf("autodetect") == -1) { // ignore "failed to autodetect" new PNotify({ title: gettext("Unhandled communication error"), - text: _.sprintf(gettext("The was an unhandled error while talking to the printer. Due to that OctoPrint disconnected. Error: %(error)s"), payload), + text: _.sprintf(gettext("There was an unhandled error while talking to the printer. Due to that OctoPrint disconnected. Error: %(error)s"), payload), type: "error", hide: false }); } + } else if (type == "PrinterReset") { + new PNotify({ + title: gettext("Printer reset detected"), + text: gettext("It looks like the printer was reset while a connection was active. If this was intentional you may safely ignore this message. Otherwise you should investigate why your printer reset itself, since this will interrupt prints and also file transfers to your printer's SD."), + hide: false + }); } var legacyEventHandlers = { diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 1cadcd34..cdad5130 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -1562,11 +1562,22 @@ class MachineCom(object): self.STATE_PAUSED, self.STATE_TRANSFERING_FILE): if line == "start": # exact match, to be on the safe side - message = "Printer sent 'start' while already operational. External reset? " \ - "Resetting line numbers to be on the safe side" - self._log(message) - self._logger.warn(message) - self.resetLineNumbers() + if self._state in (self.STATE_OPERATIONAL,): + message = "Printer sent 'start' while already operational. External reset? " \ + "Resetting line numbers to be on the safe side" + self._log(message) + self._logger.warn(message) + self.resetLineNumbers() + + else: + verb = "streaming to SD" if self.isStreaming() else "printing" + message = "Printer sent 'start' while {}. External reset? " \ + "Aborting job since printer lost state.".format(verb) + self._log(message) + self._logger.warn(message) + self.cancelPrint() + + eventManager().fire(Events.PRINTER_RESET) except: self._logger.exception("Something crashed inside the serial connection loop, please report this in OctoPrint's bug tracker:")