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):
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"])
@ -27,6 +29,14 @@ class EstopPlugin(octoprint.plugin.StartupPlugin,
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(
estop=dict(

View File

@ -11,8 +11,9 @@ $(function() {
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"]
});
});

View File

@ -9,5 +9,12 @@
<span class="help-block">Usually this is M112. Only change if you know what you're doing.</span>
</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>
</div>