add connection cycle option

adds the option to disconnect / reconnect after sending M112.
May help break out of blocking commands by resetting some control boards
This commit is contained in:
ntoff 2018-03-01 12:04:10 +10:00
parent f8688d6415
commit 62a6dac6e9
3 changed files with 46 additions and 11 deletions

View File

@ -9,7 +9,9 @@ class EstopPlugin(octoprint.plugin.StartupPlugin,
octoprint.plugin.SettingsPlugin): octoprint.plugin.SettingsPlugin):
def get_settings_defaults(self): def get_settings_defaults(self):
return dict(estopCommand = "M112") return dict(
estopCommand = "M112",
estopReconnect = False)
def on_after_startup(self): def on_after_startup(self):
self.estopCommand = self._settings.get(["estopCommand"]) self.estopCommand = self._settings.get(["estopCommand"])
@ -26,6 +28,14 @@ class EstopPlugin(octoprint.plugin.StartupPlugin,
dict(type="sidebar", name="Emergency STOP!", icon="close", template="estop_sidebar.jinja2", styles=["display: none"], data_bind="visible: loginState.isUser"), dict(type="sidebar", name="Emergency STOP!", icon="close", template="estop_sidebar.jinja2", styles=["display: none"], data_bind="visible: loginState.isUser"),
dict(type="settings", name="E-Stop Settings", template="estop_settings.jinja2", custom_bindings=False) dict(type="settings", name="E-Stop Settings", template="estop_settings.jinja2", custom_bindings=False)
] ]
def on_settings_save(self, data):
s = self._settings
if "estopCommand" in data.keys():
s.set(["estopCommand"], data["estopCommand"])
if "estopReconnect" in data.keys():
s.setBoolean(["estopReconnect"], data["estopReconnect"])
s.save()
def get_update_information(self): def get_update_information(self):
return dict( return dict(

View File

@ -5,14 +5,15 @@
$(function() { $(function() {
function EstopViewModel(parameters) { function EstopViewModel(parameters) {
var self = this; var self = this;
self.loginState = parameters[0]; self.loginState = parameters[0];
self.printerState = parameters[1]; self.printerState = parameters[1];
self.settings = parameters[2]; self.settings = parameters[2];
self.estopCommand = ko.observable("M112"); self.estopCommand = ko.observable("M112");
self.estopReconnect = ko.observable(false);
self.enableEstop = ko.pureComputed(function() { self.enableEstop = ko.pureComputed(function() {
return self.printerState.isOperational() && self.loginState.isUser(); return self.printerState.isOperational() && self.loginState.isUser();
}); });
@ -34,22 +35,39 @@ $(function() {
}); });
self.onBeforeBinding = function () { self.onBeforeBinding = function () {
//self.estopCommand(self.settings.settings.plugins.estop.estopCommand()); self.updateSettingsValues();
} }
self.sendEstopCommand = function () { self.onSettingsHidden = function () {
if (self.enableEstop()) { self.updateSettingsValues();
}
self.updateSettingsValues = function () { //lazy way of making sure we have the latest version of the settings
self.estopCommand(self.settings.settings.plugins.estop.estopCommand());
self.estopReconnect(self.settings.settings.plugins.estop.estopReconnect());
}
self.sendEstopCommand = function () {
if (self.enableEstop()) {
self.estopCommand(self.settings.settings.plugins.estop.estopCommand()); self.estopCommand(self.settings.settings.plugins.estop.estopCommand());
OctoPrint.control.sendGcode(self.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
OctoPrint.connection.connect(); //reconnect
}
}
};
}; };
} }
OCTOPRINT_VIEWMODELS.push({ OCTOPRINT_VIEWMODELS.push({
construct: EstopViewModel, construct: EstopViewModel,
dependencies: [ dependencies: [
"loginStateViewModel", "loginStateViewModel",
"printerStateViewModel", "printerStateViewModel",
"settingsViewModel"], "settingsViewModel"],
elements: ["#sidebar_plugin_estop_wrapper"] elements: ["#sidebar_plugin_estop_wrapper"]
}); });
}); });

View File

@ -9,5 +9,12 @@
<span class="help-block">Usually this is M112. Only change if you know what you're doing.</span> <span class="help-block">Usually this is M112. Only change if you know what you're doing.</span>
</div> </div>
</div> </div>
<div class="control-group">
<label class="control-label">{{ _('Cycle the connection?') }}</label>
<div class="controls">
<input type="checkbox" class="input-block" data-bind="checked: settings.plugins.estop.estopReconnect">
<span class="help-block">Enabling this will attempt to automatically cycle the connection to the printer. This may cause the printer's control board to be reset (may help break out of blocking commands).</span>
</div>
</div>
</form> </form>
</div> </div>