added hability to send shell scripts

This commit is contained in:
Vitor de Miranda Henrique
2018-06-15 14:16:54 -05:00
parent 112762622e
commit e1a9c9c217
4 changed files with 47 additions and 9 deletions

View File

@@ -122,10 +122,20 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
self.print_complete = False
def get_settings_version(self):
return 5
return 6
def on_settings_migrate(self, target, current):
def on_settings_migrate(self, target, current=None):
self._logger.warn("######### current settings version %s target settings version %s #########", current, target)
if current >= 4 and target == 6:
self._logger.warn(
"######### migrating settings to v6 #########")
old_outputs = self._settings.get(["rpi_outputs"])
for rpi_output in old_outputs:
if 'shutdown_on_failed' not in rpi_output:
rpi_output['shutdown_on_failed'] = False
if 'shell_script' not in rpi_output:
rpi_output['shell_script'] = ""
if current == 4 and target == 5:
self._logger.warn("######### migrating settings from v4 to v5 #########")
old_outputs = self._settings.get(["rpi_outputs"])
@@ -170,7 +180,6 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
val = GPIO.input(pin) if not rpi_output['active_low'] else (
not GPIO.input(pin))
index = self.to_int(rpi_output['index_id'])
# result.append(dict(index_id=rpi_output['index_id'], value=val))
gpio_status.append(dict(index_id=index, status=val))
return flask.Response(json.dumps(gpio_status), mimetype='application/json')
@@ -187,13 +196,9 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
@octoprint.plugin.BlueprintPlugin.route("/sendShellCommand", methods=["GET"])
def send_shell_command(self):
output_index = self.to_int(flask.request.values["index_id"])
rpi_output = [r_out for r_out in self.rpi_outputs if self.to_int(
r_out['index_id']) == output_index].pop()
if rpi_output:
command = rpi_output['shell_script']
self.shell_command(command)
self.send_gcode_command(rpi_output['shell_script'])
return flask.jsonify(success=True)

View File

@@ -511,6 +511,19 @@ $(function () {
});
};
self.handleShellOutput = function (item, form) {
var request = {
"index_id": item.index_id()
};
$.ajax({
type: "GET",
dataType: "json",
data: request,
url: self.buildPluginUrl("/sendShellCommand")
});
};
self.switchAutoStartUp = function (item) {
var request = {

View File

@@ -5,6 +5,7 @@
</a>
<ul class="dropdown-menu" data-bind="foreach: $root.rpi_outputs()">
<!-- ko if: ($data.show_on_navbar()) -->
<!-- ko if: ($data.output_type() == "regular") -->
<li>
<a href="javascript:void(0)" data-bind="click: $root.handleIO">
@@ -38,6 +39,15 @@
<!-- /ko -->
<!-- /ko -->
<!-- ko if: ($data.output_type() == "shell_output") -->
<li>
<a href="javascript:void(0)" data-bind="click: $root.handleShellOutput">
<span data-bind="html: label"> </span>
<span class="badge badge-info">shell</span>
</a>
</li>
<!-- /ko -->
<!-- /ko -->
</ul>

View File

@@ -170,6 +170,16 @@
</div>
<!-- /ko -->
<!-- ko if: ($data.output_type() == "shell_output") -->
<h4>
<span data-bind="html: label"> </span>
<span class="badge">Shell Script</span>
</h4>
<div>
<button data-bind="enable: $root.isUser(), click: $root.handleShellOutput" class="btn">Execute Script</button>
</div>
<!-- /ko -->
<!-- ko if: ($data.output_type() == "pwm") -->
<h4>
<span data-bind="html: label"> </span>
@@ -292,4 +302,4 @@
<!-- /ko -->
</h4>
<!-- /ko -->
<!-- /ko -->
<!-- /ko -->