Improved handling of external reset while operational

* Display message to user
  * Stop print/transfer (lost state)
This commit is contained in:
Gina Häußge 2017-07-28 13:35:00 +02:00
parent 7073c12444
commit 4d27de032d
3 changed files with 24 additions and 6 deletions

View file

@ -40,6 +40,7 @@ class Events(object):
# State changes
PRINTER_STATE_CHANGED = "PrinterStateChanged"
PRINTER_RESET = "PrinterReset"
# connect/disconnect by client
CLIENT_OPENED = "ClientOpened"

View file

@ -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 = {

View file

@ -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:")