Merge remote-tracking branch 'upstream/devel' into devel

master
Richard Mitchell 2013-02-23 18:40:28 +00:00
commit 0e6fd2bde2
3 changed files with 73 additions and 34 deletions

View File

@ -122,11 +122,14 @@ The following example config should explain the available options:
# Controls consist at least of a name, a type and type-specific further attributes. Currently recognized types are # Controls consist at least of a name, a type and type-specific further attributes. Currently recognized types are
# - section: Creates a visual section in the UI, you can use this to separate functional blocks # - section: Creates a visual section in the UI, you can use this to separate functional blocks
# - command: Creates a button that sends a defined GCODE command to the printer when clicked # - command: Creates a button that sends a defined GCODE command to the printer when clicked
# - commands: Creates a button that sends multiple defined GCODE commands to the printer when clicked
# - parametric_command: Creates a button that sends a parameterized GCODE command to the printer, parameters # - parametric_command: Creates a button that sends a parameterized GCODE command to the printer, parameters
# needed for the command are added to the UI as input fields, are named and can such be referenced from the command # needed for the command are added to the UI as input fields, are named and can such be referenced from the command
# - parametric_commands: Like parametric_command, but supports multiple commands
# #
# The following example defines a control for enabling the cooling fan with a variable speed defined by the user # The following example defines a control for enabling the cooling fan with a variable speed defined by the user
# (default 255) and a control for disabling the fan, all within a section named "Fan". # (default 255) and a control for disabling the fan, all within a section named "Fan", and two example controls with
# multiple commands in a section "Example for multiple commands".
controls: controls:
- name: Fan - name: Fan
type: section type: section
@ -141,7 +144,28 @@ The following example config should explain the available options:
- name: Disable Fan - name: Disable Fan
type: command type: command
command: M107 command: M107
- name: Example for multiple commands
type: section
children:
- name: Move X (static)
type: commands
commands:
- G91
- G1 X10 F3000
- G90
- name: Move X (parametric)
type: parametric_commands
commands:
- G91
- G1 X%(distance)s F%(speed)s
- G90
input:
- default: 10
name: Distance
parameter: distance
- default: 3000
name: Speed
parameter: speed
Setup on a Raspberry Pi running Raspbian Setup on a Raspberry Pi running Raspbian
---------------------------------------- ----------------------------------------

View File

@ -129,21 +129,25 @@ def disconnect():
@app.route(BASEURL + "control/command", methods=["POST"]) @app.route(BASEURL + "control/command", methods=["POST"])
def printerCommand(): def printerCommand():
command = request.form["command"] if "application/json" in request.headers["Content-Type"]:
data = request.json
# if parameters for the command are given, retrieve them from the request and format the command string with them parameters = {}
parameters = {} if "parameters" in data.keys(): parameters = data["parameters"]
for requestParameter in request.values.keys():
if not requestParameter.startswith("parameter_"):
continue
parameterName = requestParameter[len("parameter_"):] commands = []
parameterValue = request.values[requestParameter] if "command" in data.keys(): commands = [data["command"]]
parameters[parameterName] = parameterValue elif "commands" in data.keys(): commands = data["commands"]
if len(parameters) > 0:
command = command % parameters commandsToSend = []
for command in commands:
commandToSend = command
if len(parameters) > 0:
commandToSend = command % parameters
commandsToSend.append(commandToSend)
printer.commands(commandsToSend)
printer.command(command)
return jsonify(SUCCESS) return jsonify(SUCCESS)
@app.route(BASEURL + "control/print", methods=["POST"]) @app.route(BASEURL + "control/print", methods=["POST"])

View File

@ -421,7 +421,7 @@ function ControlsViewModel() {
} }
self._enhanceControl = function(control) { self._enhanceControl = function(control) {
if (control.type == "parametric_command") { if (control.type == "parametric_command" || control.type == "parametric_commands") {
for (var i = 0; i < control.input.length; i++) { for (var i = 0; i < control.input.length; i++) {
control.input[i].value = control.input[i].default; control.input[i].value = control.input[i].default;
} }
@ -475,25 +475,33 @@ function ControlsViewModel() {
if (!command) if (!command)
return; return;
if (command.type == "command") { var data = undefined;
$.ajax({ if (command.type == "command" || command.type == "parametric_command") {
url: AJAX_BASEURL + "control/command", // single command
type: "POST", data = {"command" : command.command};
dataType: "json", } else if (command.type == "commands" || command.type == "parametric_commands") {
data: "command=" + command.command // multi command
}) data = {"commands": command.commands};
} else if (command.type="parametric_command") {
var data = {"command": command.command};
for (var i = 0; i < command.input.length; i++) {
data["parameter_" + command.input[i].parameter] = command.input[i].value;
}
$.ajax({
url: AJAX_BASEURL + "control/command",
type: "POST",
dataType: "json",
data: data
})
} }
if (command.type == "parametric_command" || command.type == "parametric_commands") {
// parametric command(s)
data["parameters"] = {};
for (var i = 0; i < command.input.length; i++) {
data["parameters"][command.input[i].parameter] = command.input[i].value;
}
}
if (!data)
return;
$.ajax({
url: AJAX_BASEURL + "control/command",
type: "POST",
dataType: "json",
contentType: "application/json; charset=UTF-8",
data: JSON.stringify(data)
})
} }
self.displayMode = function(customControl) { self.displayMode = function(customControl) {
@ -501,8 +509,10 @@ function ControlsViewModel() {
case "section": case "section":
return "customControls_sectionTemplate"; return "customControls_sectionTemplate";
case "command": case "command":
case "commands":
return "customControls_commandTemplate"; return "customControls_commandTemplate";
case "parametric_command": case "parametric_command":
case "parametric_commands":
return "customControls_parametricCommandTemplate"; return "customControls_parametricCommandTemplate";
default: default:
return "customControls_emptyTemplate"; return "customControls_emptyTemplate";
@ -1299,7 +1309,8 @@ $(function() {
url: AJAX_BASEURL + "control/command", url: AJAX_BASEURL + "control/command",
type: "POST", type: "POST",
dataType: "json", dataType: "json",
data: "command=" + command contentType: "application/json; charset=UTF-8",
data: JSON.stringify({"command": command})
}) })
} }
}) })