different handling of offline event detect

setting to null was giving javascript console errors. Changed it to just not do anything if the emergency button wasn't pressed.
This commit is contained in:
ntoff 2018-03-10 02:25:51 +10:00
parent 15889e0dc7
commit 3666aa5e8d

View File

@ -12,6 +12,7 @@ $(function() {
self.estopCommand = ko.observable("M112");
self.estopReconnect = ko.observable(false);
self.emergencyCalled = ko.observable(false);
self.enableEstop = ko.pureComputed(function() {
return self.printerState.isOperational() && self.loginState.isUser();
@ -21,10 +22,18 @@ $(function() {
return self.loginState.isUser() > 0 ? "estop_sidebar" : "estop_sidebar_disabled";
});
self.reconnect = ko.pureComputed(function() {
return self.estopReconnect() && self.emergencyCalled();
})
self.buttonText = ko.pureComputed(function() {
if (self.enableEstop()) {
return gettext("EMERGENCY STOP");
} else {
} else if (self.reconnect()) {
return gettext("Reconnecting...")
}
else {
return gettext("Offline");
}
});
@ -46,21 +55,27 @@ $(function() {
self.estopReconnect(self.settings.settings.plugins.estop.estopReconnect());
}
self.onEventDisconnected = function () {
if (self.estopReconnect() && self.emergencyCalled()) {
self.timedReconnect = setTimeout(function() { //reconnect 3 seconds after detecting the printer is offline
self.emergencyCalled(false);
OctoPrint.connection.connect();
}, 3*1000); //3 seconds
}
}
self.sendEstopCommand = function () {
if (self.enableEstop()) {
self.emergencyCalled(true);
self.estopCommand(self.settings.settings.plugins.estop.estopCommand());
OctoPrint.control.sendGcode(self.estopCommand());
if (self.estopReconnect()) { //cycle the connection (if enabled) to reset the control board
OctoPrint.connection.disconnect(); //send a disconnect, maybe useful for breaking out of blocking commands.
self.onEventDisconnected = function () { //wait until octoprint has disconnected
self.onEventDisconnected = null; //unregister event handler
OctoPrint.connection.connect(); //reconnect
}
if (self.estopReconnect()) {
OctoPrint.connection.disconnect(); //normally octoprint would probably disconnect anyway, just calling this here in case the printer is in a blocking loop
}
};
};
}
}
}
OCTOPRINT_VIEWMODELS.push({