Merge remote-tracking branch 'upstream/devel' into devel
commit
0e6fd2bde2
28
README.md
28
README.md
|
@ -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
|
||||
# - 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
|
||||
# - 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
|
||||
# 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
|
||||
# (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:
|
||||
- name: Fan
|
||||
type: section
|
||||
|
@ -141,7 +144,28 @@ The following example config should explain the available options:
|
|||
- name: Disable Fan
|
||||
type: command
|
||||
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
|
||||
----------------------------------------
|
||||
|
|
|
@ -129,21 +129,25 @@ def disconnect():
|
|||
|
||||
@app.route(BASEURL + "control/command", methods=["POST"])
|
||||
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 = {}
|
||||
for requestParameter in request.values.keys():
|
||||
if not requestParameter.startswith("parameter_"):
|
||||
continue
|
||||
if "parameters" in data.keys(): parameters = data["parameters"]
|
||||
|
||||
parameterName = requestParameter[len("parameter_"):]
|
||||
parameterValue = request.values[requestParameter]
|
||||
parameters[parameterName] = parameterValue
|
||||
commands = []
|
||||
if "command" in data.keys(): commands = [data["command"]]
|
||||
elif "commands" in data.keys(): commands = data["commands"]
|
||||
|
||||
commandsToSend = []
|
||||
for command in commands:
|
||||
commandToSend = command
|
||||
if len(parameters) > 0:
|
||||
command = command % parameters
|
||||
commandToSend = command % parameters
|
||||
commandsToSend.append(commandToSend)
|
||||
|
||||
printer.commands(commandsToSend)
|
||||
|
||||
printer.command(command)
|
||||
return jsonify(SUCCESS)
|
||||
|
||||
@app.route(BASEURL + "control/print", methods=["POST"])
|
||||
|
|
|
@ -421,7 +421,7 @@ function ControlsViewModel() {
|
|||
}
|
||||
|
||||
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++) {
|
||||
control.input[i].value = control.input[i].default;
|
||||
}
|
||||
|
@ -475,34 +475,44 @@ function ControlsViewModel() {
|
|||
if (!command)
|
||||
return;
|
||||
|
||||
if (command.type == "command") {
|
||||
$.ajax({
|
||||
url: AJAX_BASEURL + "control/command",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: "command=" + command.command
|
||||
})
|
||||
} else if (command.type="parametric_command") {
|
||||
var data = {"command": command.command};
|
||||
var data = undefined;
|
||||
if (command.type == "command" || command.type == "parametric_command") {
|
||||
// single command
|
||||
data = {"command" : command.command};
|
||||
} else if (command.type == "commands" || command.type == "parametric_commands") {
|
||||
// multi command
|
||||
data = {"commands": command.commands};
|
||||
}
|
||||
|
||||
if (command.type == "parametric_command" || command.type == "parametric_commands") {
|
||||
// parametric command(s)
|
||||
data["parameters"] = {};
|
||||
for (var i = 0; i < command.input.length; i++) {
|
||||
data["parameter_" + command.input[i].parameter] = command.input[i].value;
|
||||
data["parameters"][command.input[i].parameter] = command.input[i].value;
|
||||
}
|
||||
}
|
||||
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
$.ajax({
|
||||
url: AJAX_BASEURL + "control/command",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: data
|
||||
contentType: "application/json; charset=UTF-8",
|
||||
data: JSON.stringify(data)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
self.displayMode = function(customControl) {
|
||||
switch (customControl.type) {
|
||||
case "section":
|
||||
return "customControls_sectionTemplate";
|
||||
case "command":
|
||||
case "commands":
|
||||
return "customControls_commandTemplate";
|
||||
case "parametric_command":
|
||||
case "parametric_commands":
|
||||
return "customControls_parametricCommandTemplate";
|
||||
default:
|
||||
return "customControls_emptyTemplate";
|
||||
|
@ -1299,7 +1309,8 @@ $(function() {
|
|||
url: AJAX_BASEURL + "control/command",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: "command=" + command
|
||||
contentType: "application/json; charset=UTF-8",
|
||||
data: JSON.stringify({"command": command})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue