From 62a6dac6e963d39f89fd98f5e3008dcd88f0f5be Mon Sep 17 00:00:00 2001 From: ntoff Date: Thu, 1 Mar 2018 12:04:10 +1000 Subject: [PATCH] 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 --- octoprint_estop/__init__.py | 12 +++++- octoprint_estop/static/js/estop.js | 38 ++++++++++++++----- .../templates/estop_settings.jinja2 | 7 ++++ 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/octoprint_estop/__init__.py b/octoprint_estop/__init__.py index b2c0664..14e4f94 100644 --- a/octoprint_estop/__init__.py +++ b/octoprint_estop/__init__.py @@ -9,7 +9,9 @@ class EstopPlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.SettingsPlugin): def get_settings_defaults(self): - return dict(estopCommand = "M112") + return dict( + estopCommand = "M112", + estopReconnect = False) def on_after_startup(self): 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="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): return dict( diff --git a/octoprint_estop/static/js/estop.js b/octoprint_estop/static/js/estop.js index 6020dd4..356b7b7 100644 --- a/octoprint_estop/static/js/estop.js +++ b/octoprint_estop/static/js/estop.js @@ -5,14 +5,15 @@ $(function() { function EstopViewModel(parameters) { var self = this; - + self.loginState = parameters[0]; self.printerState = parameters[1]; self.settings = parameters[2]; 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(); }); @@ -34,22 +35,39 @@ $(function() { }); self.onBeforeBinding = function () { - //self.estopCommand(self.settings.settings.plugins.estop.estopCommand()); + self.updateSettingsValues(); } - self.sendEstopCommand = function () { - if (self.enableEstop()) { + self.onSettingsHidden = function () { + 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()); 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, dependencies: [ - "loginStateViewModel", - "printerStateViewModel", - "settingsViewModel"], + "loginStateViewModel", + "printerStateViewModel", + "settingsViewModel"], elements: ["#sidebar_plugin_estop_wrapper"] }); }); diff --git a/octoprint_estop/templates/estop_settings.jinja2 b/octoprint_estop/templates/estop_settings.jinja2 index 03937d2..8c4f171 100644 --- a/octoprint_estop/templates/estop_settings.jinja2 +++ b/octoprint_estop/templates/estop_settings.jinja2 @@ -9,5 +9,12 @@ Usually this is M112. Only change if you know what you're doing. +
+ +
+ + 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). +
+