';
$("#table_gcodes").append(item);
e.preventDefault();
});
$("#btn_add_head_temp").click(function(e) {
var temperature = checkBoundaries($("#input_add_head_temp").val(), 0, -273.15, 300);
var type = $('input[name="temp_selection"]:checked').val();
var item = '
' + temperature + ' °C';
item += '
';
$("#ul_" + type + "_temps").append(item);
e.preventDefault();
});
$("#btn_add_bed_temp").click(function(e) {
var temperature = checkBoundaries($("#input_add_bed_temp").val(), 0, -273.15, 180);
var item = '
' + temperature + ' °C';
item += '
';
$("#ul_bed_temps").append(item);
e.preventDefault();
});
$("#btn_add_tool").click(function(e) {
var gcode = "M563 P" + $("#input_tool_number").val();
var drives = $("input[name='tool_drives']:checked");
if (drives != undefined) {
var driveList = [];
drives.each(function() { driveList.push($(this).val()); });
gcode += " D" + driveList.reduce(function(a, b) { return a + ":" + b; });
}
var heaters = $("input[name='tool_heaters']:checked");
if (heaters != undefined) {
var heaterList = [];
heaters.each(function() { heaterList.push($(this).val()); });
gcode += " H" + heaterList.reduce(function(a, b) { return a + ":" + b; });
}
sendGCode(gcode);
extendedStatusCounter = settings.extendedStatusInterval;
e.preventDefault();
});
$("#btn_cancel").click(function() {
sendGCode("M0 H1"); // Stop / Cancel Print, but leave all the heaters on
$(this).addClass("disabled");
});
$("#btn_cancel_upload").click(function() {
cancelUpload();
});
$(".btn-connect").click(function() {
if (!isConnected) {
// Attempt to connect with the last-known password first
connect(sessionPassword, true);
} else {
disconnect();
}
});
$(".btn-emergency-stop").click(function() {
if (settings.confirmStop) {
showConfirmationDialog(T("Emergency STOP"), T("This will turn off everything and perform a software reset.
Are you REALLY sure you want to do this?"), function() {
sendGCode("M112\nM999");
});
} else {
sendGCode("M112\nM999");
}
});
$("#btn_fw_diagnostics").click(function() {
if (isConnected) {
sendGCode("M122");
showPage("console");
}
});
$("#btn_clear_log").click(function(e) {
$("#console_log").html("");
log("info", "" + T("Message Log cleared!") + "");
e.preventDefault();
});
// TODO: deal with mixing drives
$("#btn_extrude").click(function(e) {
var feedrate = $("#panel_extrude input[name=feedrate]:checked").val() * 60;
var amount = $("#panel_extrude input[name=feed]:checked").val();
sendGCode("M120\nM83\nG1 E" + amount + " F" + feedrate + "\nM121");
});
$("#btn_retract").click(function(e) {
var feedrate = $("#panel_extrude input[name=feedrate]:checked").val() * 60;
var amount = $("#panel_extrude input[name=feed]:checked").val();
sendGCode("M120\nM83\nG1 E-" + amount + " F" + feedrate + "\nM121");
});
$(".btn-hide-info").click(function() {
if ($(this).hasClass("active")) {
$("#row_info").addClass("hidden-xs hidden-sm");
$("#main_content").addClass("content-collapsed-padding");
setTimeout(function() {
$(".btn-hide-info").removeClass("active");
}, 100);
} else {
$("#row_info").removeClass("hidden-xs hidden-sm");
$("#main_content").removeClass("content-collapsed-padding");
setTimeout(function() {
$(".btn-hide-info").addClass("active");
}, 100);
}
$(this).blur();
});
$(".btn-home-x").resize(function() {
if (geometry != "delta") {
var width = $(this).parent().width();
if (width > 0) {
$("#btn_homeall").css("min-width", width);
}
}
}).resize();
$("#mobile_home_buttons button, #btn_homeall, #table_move_head a").click(function(e) {
$this = $(this);
if ($this.data("home") != undefined) {
if ($this.data("home") == "all") {
sendGCode("G28");
} else {
sendGCode("G28 " + $this.data("home"));
}
} else {
var moveString = "M120\nG91\nG1";
if ($this.data("x") != undefined) {
moveString += " X" + $this.data("x");
}
if ($this.data("y") != undefined) {
moveString += " Y" + $this.data("y");
}
if ($this.data("z") != undefined) {
moveString += " Z" + $this.data("z");
}
moveString += " F" + settings.moveFeedrate + "\nM121";
sendGCode(moveString);
}
e.preventDefault();
});
$("#btn_new_gcode_directory").click(function() {
showTextInput(T("New directory"), T("Please enter a name:"), function(value) {
$.ajax("rr_mkdir?dir=" + currentGCodeDirectory + "/" + value, {
dataType: "json",
success: function(response) {
if (response.err == 0) {
gcodeUpdateIndex = -1;
updateGCodeFiles();
} else {
showMessage("warning", T("Error"), T("Could not create this directory!"));
}
}
});
});
});
$("#btn_new_macro_directory").click(function() {
showTextInput(T("New directory"), T("Please enter a name:"), function(value) {
$.ajax("rr_mkdir?dir=" + currentMacroDirectory + "/" + value, {
dataType: "json",
success: function(response) {
if (response.err == 0) {
macroUpdateIndex = -1;
updateMacroFiles();
} else {
showMessage("warning", T("Error"), T("Could not create this directory!"));
}
}
});
});
});
$("#btn_pause").click(function() {
if (isPaused) {
sendGCode("M24"); // Resume
} else if (isPrinting) {
sendGCode("M25"); // Pause
}
$(this).addClass("disabled");
});
$(".btn-upload").click(function(e) {
if (!$(this).is(".disabled")) {
$("#input_file_upload").data("type", $(this).data("type")).click();
}
e.preventDefault();
});
$("#btn_reset_settings").click(function(e) {
showConfirmationDialog(T("Reset Settings"), T("Are you sure you want to revert to Factory Settings?"), function() {
if (defaultSettings.language != settings.language) {
showMessage("info", T("Language has changed"), T("You have changed the current language. Please reload the web interface to apply this change."), 0);
}
settings = jQuery.extend(true, {}, defaultSettings);
$("#btn_language").data("language", "en").children("span:first-child").text("English");
saveSettings();
applySettings();
});
e.preventDefault();
});
["print", "gcode", "macro", "generic"].forEach(function(type) {
var child = $(".btn-upload[data-type='" + type + "']");
// Drag Enter
child.on("dragover", function(e) {
$(this).removeClass($(this).data("style")).addClass("btn-success");
e.preventDefault();
e.stopPropagation();
});
// Drag Leave
child.on("dragleave", function(e) {
$(this).removeClass("btn-success").addClass($(this).data("style"));
e.preventDefault();
e.stopPropagation();
});
// Drop
child.on("drop", function(e) {
$(this).removeClass("btn-success").addClass($(this).data("style"));
e.preventDefault();
e.stopPropagation();
var files = e.originalEvent.dataTransfer.files;
if (!$(this).is(".disabled") && files != null && files.length > 0) {
// Start new file upload
startUpload($(this).data("type"), files, false);
}
});
});
$(".gcode-input").submit(function(e) {
if (isConnected) {
var gcode = $(this).find("input").val();
if (settings.uppercaseGCode) {
gcode = gcode.toUpperCase();
}
sendGCode(gcode, true);
$(this).find("input").select();
}
e.preventDefault();
});
// Make the auto-complete dropdown items look proper.
// This should be replaced by proper CSS someday, but
// for now we only check which elements may float around.
$(".div-gcodes").bind("shown.bs.dropdown", function() {
var maxWidth = 0;
$(this).find("ul > li > a").each(function() {
var rowWidth = 0;
$(this).find("span").each(function() {
rowWidth += $(this).width();
});
if (rowWidth > maxWidth) {
maxWidth = rowWidth;
}
});
if (maxWidth > 0) {
$(this).find("ul > li > a").each(function() {
var rowWidth = 0;
$(this).find("span").each(function() {
rowWidth += $(this).width();
});
if (rowWidth < maxWidth) {
$(this).addClass("gcode-float");
}
});
}
});
$("#frm_settings").submit(function(e) {
saveSettings();
applySettings();
e.preventDefault();
});
$("#frm_settings > ul > li a").on("shown.bs.tab", function(e) {
$("#frm_settings > ul li").removeClass("active");
var links = $('#frm_settings > ul > li a[href="' + $(this).attr("href") + '"]');
$.each(links, function() {
$(this).parent().addClass("active");
});
});
$("input[type='number']").focus(function() {
var input = $(this);
setTimeout(function() {
input.select();
}, 10);
});
$("input[name='temp_selection']:radio").change(function() {
if ($(this).val() == "active") {
$("#ul_active_temps").removeClass("hidden");
$("#ul_standby_temps").addClass("hidden");
} else {
$("#ul_standby_temps").removeClass("hidden");
$("#ul_active_temps").addClass("hidden");
}
});
$("#input_file_upload").change(function(e) {
if (this.files.length > 0) {
// For POST uploads, we need file blobs
startUpload($(this).data("type"), this.files, false);
}
});
$("#input_temp_bed").keydown(function(e) {
var enterKeyPressed = (e.which == 13);
enterKeyPressed |= (e.which == 9 && window.matchMedia('(max-width: 991px)').matches); // need this for Android
if (isConnected && enterKeyPressed) {
sendGCode("M140 S" + $(this).val());
$(this).select();
e.preventDefault();
}
});
$("#input_temp_chamber").keydown(function(e) {
var enterKeyPressed = (e.which == 13);
enterKeyPressed |= (e.which == 9 && window.matchMedia('(max-width: 991px)').matches); // need this for Android
if (isConnected && enterKeyPressed) {
sendGCode("M141 S" + $(this).val());
$(this).select();
e.preventDefault();
}
});
$("input[id^='input_temp_h']").keydown(function(e) {
var enterKeyPressed = (e.which == 13);
enterKeyPressed |= (e.which == 9 && window.matchMedia('(max-width: 991px)').matches); // need this for Android
if (isConnected && enterKeyPressed) {
var activeOrStandby = ($(this).prop("id").match("active$")) ? "S" : "R";
var heater = $(this).prop("id").match("_h(.)_")[1];
var temperature = $(this).val();
var gcode = "";
getToolsByHeater(heater).forEach(function(toolNumber) {
gcode += "G10 P" + toolNumber + " " + activeOrStandby + temperature + "\n";
});
sendGCode(gcode);
$(this).select();
e.preventDefault();
}
});
$("#input_temp_all_active, #input_temp_all_standby").keydown(function(e) {
if (isConnected && e.which == 13) {
if (toolMapping != undefined) {
var activeOrStandby = ($(this).prop("id").match("active$")) ? "S" : "R";
var temperature = $(this).val();
var gcode = "";
for(var i=0; i abbr").click(function(e) {
showMessage("warning", T("Warning"), T("Some axes are not homed"));
e.preventDefault();
});
$(".navlink").click(function(e) {
$(this).blur();
showPage($(this).data("target"));
e.preventDefault();
});
$("#page_listitems input").on("input", function() {
// Validate form controls
$("#btn_add_gcode").toggleClass("disabled", $("#input_gcode").val().trim() == "" || $("#input_gcode_description").val().trim() == "");
$("#btn_add_head_temp").toggleClass("disabled", isNaN(parseFloat($("#input_add_head_temp").val())));
$("#btn_add_bed_temp").toggleClass("disabled", isNaN(parseFloat($("#input_add_bed_temp").val())));
});
$("#page_listitems input").keydown(function(e) {
if (e.which == 13) {
var button = $(this).parents("div:not(.input-group):eq(0)").find("button");
if (!button.hasClass("disabled")) {
button.click();
}
e.preventDefault();
}
});
$("#panel_control_misc label.btn").click(function() {
if ($(this).find("input").val() == 1) { // ATX on
sendGCode("M80");
} else { // ATX off
showConfirmationDialog(T("ATX Power"), T("Do you really want to turn off ATX power?
This will turn off all drives, heaters and fans."), function() {
sendGCode("M81");
});
}
});
$("#panel_extrude label.btn").click(function() {
$(this).parent().find("label.btn").removeClass("btn-primary").addClass("btn-default");
$(this).removeClass("btn-default").addClass("btn-primary");
});
$(".span-refresh-files").click(function() {
gcodeUpdateIndex = -1;
updateGCodeFiles();
$(".span-refresh-files").addClass("hidden");
});
$(".span-refresh-macros").click(function() {
macroUpdateIndex = -1;
updateMacroFiles();
$(".span-refresh-macros").addClass("hidden");
});
$(document).delegate('#text_config', 'keydown', function(e) {
var keyCode = e.keyCode || e.which;
if (keyCode == 9) {
e.preventDefault();
var start = $(this).get(0).selectionStart;
var end = $(this).get(0).selectionEnd;
// set textarea value to: text before caret + tab + text after caret
$(this).val($(this).val().substring(0, start)
+ "\t"
+ $(this).val().substring(end));
// put caret at right position again
$(this).get(0).selectionStart = $(this).get(0).selectionEnd = start + 1;
}
});
$(".panel-chart").resize(function() {
resizeCharts();
});
$('a[href="#page_general"], a[href="#page_listitems"]').on('shown.bs.tab', function () {
$("#row_save_settings, #btn_reset_settings").removeClass("hidden");
});
$('a[href="#page_config"]').on('shown.bs.tab', function() {
$("#row_save_settings, #btn_reset_settings").addClass("hidden");
$("#text_config").trigger("input");
getConfigFile();
});
$('a[href="#page_machine"], a[href="#page_tools"]').on('shown.bs.tab', function () {
$("#row_save_settings").addClass("hidden");
});
$("#table_heaters a").click(function(e) {
if (isConnected && lastStatusResponse != undefined) {
if ($(this).parents("#tr_bed").length > 0) {
var bedState = lastStatusResponse.temps.bed.state;
if (bedState == 3) {
showMessage("danger", T("Heater Fault"), T("Error: A heater fault has occured on this particular heater.
Please turn off your machine and check your wiring for loose connections."));
} else if (bedState == 2) {
// Put bed into standby mode
sendGCode("M144");
} else {
// Bed is either off or in standby mode, send M140 to turn it back on
sendGCode("M140 S" + $("#input_temp_bed").val());
}
} else {
var heater = $(this).parents("tr").index();
var heaterState = lastStatusResponse.temps.heads.state[heater - 1];
if (heaterState == 3) {
showMessage("danger", T("Heater Fault"), T("Error: A heater fault has occured on this particular heater.
Please turn off your machine and check your wiring for loose connections."));
} else {
var tools = getToolsByHeater(heater), hasToolSelected = false;
tools.forEach(function(tool) {
if (tool == lastStatusResponse.currentTool) {
hasToolSelected = true;
}
});
if (hasToolSelected) {
changeTool(-1);
$(this).blur();
} else if (tools.length == 1) {
changeTool(tools[0]);
$(this).blur();
} else if (tools.length > 0) {
var popover = $(this).parent().children("div.popover");
if (popover.length) {
$(this).popover("hide");
$(this).blur();
} else {
var content = '
';
$(this).popover({
content: content,
html: true,
title: T("Select Tool"),
trigger: "manual",
placement: "bottom",
}).popover("show");
}
}
}
}
}
e.preventDefault();
});
$("#table_define_tool input[type='checkbox']").change(function() {
var isChecked = $(this).is(":checked");
$(this).parents("label").toggleClass("btn-primary", isChecked).toggleClass("btn-default", !isChecked);
validateAddTool();
});
$("#table_define_tool input[type='number']").on("input", function() {
validateAddTool();
});
function validateAddTool() {
var toolNumber = parseInt($("#input_tool_number").val());
var disableButton = (!isConnected) ||
(isNaN(toolNumber) || toolNumber < 0 || toolNumber > 255) ||
(toolMapping != undefined && getTool(toolNumber) != undefined) ||
($("input[name='tool_heaters']:checked").length + $("input[name='tool_drives']:checked").length == 0);
$("#btn_add_tool").toggleClass("disabled", disableButton);
}
$("#table_define_tool input[type='number']").keydown(function(e) {
if (e.which == 13) {
if (!$("#btn_add_tool").hasClass("disabled")) {
$("#btn_add_tool").click();
}
e.preventDefault();
}
});
$("#table_heaters tr > th:first-child > a").blur(function() {
$(this).popover("hide");
});
$("#ul_control_dropdown").click(function(e) {
$(this).find(".dropdown").removeClass("open");
if ($(e.target).is("a")) {
$(this).parents(".dropdown").removeClass("open");
} else {
e.stopPropagation();
}
});
$("#ul_control_dropdown .btn-active-temp, #ul_control_dropdown .btn-standby-temp").click(function(e) {
$(this).parent().toggleClass("open");
e.stopPropagation();
});
/* Temperature charts */
function addLayerData(lastLayerTime, updateGui) {
layerData.push([layerData.length + 1, lastLayerTime]);
if (lastLayerTime > maxLayerTime) {
maxLayerTime = lastLayerTime;
}
if (updateGui) {
$("#td_last_layertime").html(convertSeconds(lastLayerTime)).addClass("layer-done-animation");
setTimeout(function() {
$("#td_last_layertime").removeClass("layer-done-animation");
}, 2000);
drawPrintChart();
}
}
function drawTemperatureChart()
{
// Only draw the chart if it's possible
if ($("#chart_temp").width() === 0) {
refreshTempChart = true;
return;
}
// Prepare the data
var preparedBedTemps = [];
for(var i=0; i 2) {
for(var i=(layerData.length > 26) ? layerData.length - 25 : 1; i < layerData.length; i++) {
if (maxY < layerData[i][1] * 1.1) {
maxY = layerData[i][1] * 1.1;
}
}
} else if (layerData.length > 0) {
maxY = layerData[0][1] * 1.1;
}
printChartOptions.yaxis.max = maxY;
printChartOptions.yaxis.panRange = [0, (maxLayerTime < maxY) ? maxY : maxLayerTime];
printChartOptions.yaxis.zoomRange = [30, (maxLayerTime < maxY) ? maxY : maxLayerTime];
// Update chart and pan to the right
printChart = $.plot("#chart_print", [layerData], printChartOptions);
printChart.pan({ left: 99999 });
refreshPrintChart = false;
// Add hover events to chart
$("#chart_print").unbind("plothover").bind("plothover", function (event, pos, item) {
if (item) {
var layer = item.datapoint[0];
if (layer == 0) {
layer = 1;
}
$("#layer_tooltip").html(T("Layer {0}: {1}", layer, convertSeconds(item.datapoint[1])))
.css({top: item.pageY + 5, left: item.pageX + 5})
.fadeIn(200);
} else {
$("#layer_tooltip").hide();
}
});
}
function resizeCharts() {
var headsHeight = $("#table_heaters").height();
var statusHeight = 0;
$("#div_status table").each(function() {
statusHeight += $(this).outerHeight();
});
var max = (headsHeight > statusHeight) ? headsHeight : statusHeight;
max -= tempChartPadding;
if (max > 0) {
$("#chart_temp").css("height", max);
}
if (refreshTempChart) {
drawTemperatureChart();
}
if (refreshPrintChart) {
drawPrintChart();
}
}
/* Sliders */
$('#slider_fan_control').slider({
enabled: false,
id: "fan_control",
min: 0,
max: 100,
step: 1,
value: 35,
tooltip: "always",
formatter: function(value) {
return value + " %";
}
}).on("slideStart", function() {
fanSliderActive = true;
}).on("slideStop", function(slideEvt) {
if (isConnected && !isNaN(slideEvt.value)) {
sendGCode("M106 S" + (slideEvt.value / 100.0));
$("#slider_fan_print").slider("setValue", slideEvt.value);
}
fanSliderActive = false;
});
$('#slider_fan_print').slider({
enabled: false,
id: "fan_print",
min: 0,
max: 100,
step: 1,
value: 35,
tooltip: "always",
formatter: function(value) {
return value + " %";
}
}).on("slideStart", function() {
fanSliderActive = true;
}).on("slideStop", function(slideEvt) {
if (isConnected && !isNaN(slideEvt.value)) {
sendGCode("M106 S" + (slideEvt.value / 100.0));
$("#slider_fan_control").slider("setValue", slideEvt.value);
}
fanSliderActive = false;
});
for(var extr=1; extr<=6; extr++) {
$('#slider_extr_' + extr).slider({
enabled: false,
id: "extr-" + extr,
min: 50,
max: 150,
step: 1,
value: 100,
tooltip: "always",
formatter: function(value) {
return value + " %";
}
}).on("slideStart", function() {
extrSliderActive = true;
}).on("slideStop", function(slideEvt) {
if (isConnected && !isNaN(slideEvt.value)) {
sendGCode("M221 D" + $(this).data("drive") + " S" + slideEvt.value);
}
extrSliderActive = false;
});
}
$('#slider_speed').slider({
enabled: false,
id: "speed",
min: 20,
max: 200,
step: 1,
value: 100,
tooltip: "always",
formatter: function(value) {
return value + " %";
}
}).on("slideStart", function() {
speedSliderActive = true;
}).on("slideStop", function(slideEvt) {
if (isConnected && !isNaN(slideEvt.value)) {
sendGCode("M220 S" + slideEvt.value);
}
speedSliderActive = false;
});
/* Modals */
function showConfirmationDialog(title, message, action) {
$("#modal_confirmation h4").html(' ' + title);
$("#modal_confirmation p").html(message);
$("#modal_confirmation button:first-child").off().one("click", action);
$("#modal_confirmation").modal("show");
$("#modal_confirmation .btn-success").focus();
}
function showTextInput(title, message, action) {
$("#modal_textinput h4").html(title);
$("#modal_textinput p").html(message);
$("#modal_textinput input").val("");
$("#modal_textinput form").off().submit(function(e) {
$("#modal_textinput").modal("hide");
var value = $("#modal_textinput input").val();
if (value.trim() != "") {
action(value);
}
e.preventDefault();
});
$("#modal_textinput").modal("show");
}
function showMessage(type, title, message, timeout, allowDismiss) {
// Find a suitable icon
var icon = "glyphicon glyphicon-info-sign";
if (type == "warning") {
icon = "glyphicon glyphicon-warning-sign";
} else if (type == "danger") {
icon = "glyphicon glyphicon-exclamation-sign";
}
// Check if the title can be displayed as bold text
if (title != "")
{
if (title.indexOf("") == -1)
{
title = "" + title + "";
}
title += "
";
}
// Show the notification
var notifySettings = { icon: "glyphicon glyphicon-" + icon,
title: title,
message: message};
var options = { type: type,
allow_dismiss: (allowDismiss == undefined) ? true : allowDismiss,
delay: (timeout == undefined) ? settings.notificationTimeout : timeout };
return $.notify(notifySettings, options);
}
function showPasswordPrompt() {
$('#input_password').val("");
$("#modal_pass_input").modal("show");
$("#modal_pass_input").one("hide.bs.modal", function() {
// The network request will take a few ms anyway, so no matter if the user has
// cancelled the password input, we can reset the Connect button here...
$(".btn-connect").removeClass("btn-warning disabled").addClass("btn-info").find("span:not(.glyphicon)").text(T("Connect"));
});
}
function showUpdateMessage() {
var notifySettings = { icon: "glyphicon glyphicon-time",
title: "" + T("Updating Firmware...") + "
",
message: T("Please wait while the firmware is being updated..."),
progress: settings.updateReconnectDelay / 100,
};
var options = { type: "success",
allow_dismiss: false,
delay: settings.updateReconnectDelay,
timeout: 1000,
showProgressbar: true
};
return $.notify(notifySettings, options);
}
$("#modal_pass_input, #modal_textinput").on('shown.bs.modal', function() {
$(this).find("input").focus()
});
$(".modal").on("hidden.bs.modal", function() {
// Bootstrap bug: Padding is added to the right, but never cleaned
$("body").css("padding-right", "");
});
$("#form_password").submit(function(e) {
$("#modal_pass_input").off("hide.bs.modal").modal("hide");
connect($("#input_password").val(), false);
e.preventDefault();
});
/* GUI Helpers */
function addBedTemperature(temperature) {
// Drop-Down item
$(".ul-bed-temp").append('
';
$("#table_gcodes").append(item);
}
function addGCodeFile(filename) {
$("#page_files h1").addClass("hidden");
var row = '
';
row += '
' + filename + '
';
row += '
' + T("loading") + '
';
row += '
loading
';
row += '
loading
';
row += '
loading
';
row += '
' + T("loading") + '
';
$("#table_gcode_files").removeClass("hidden");
return $(row).appendTo("#table_gcode_files");
}
function addMacroFile(filename) {
// Control Page
if (currentMacroDirectory == "/macros") {
var label = stripMacroFilename(filename);
var macroButton = '
');
$(".btn-" + type + "-temp").removeClass("disabled");
// Entry on Settings page
var item = '
' + temperature + ' °C';
item += '
';
$("#ul_" + type + "_temps").append(item);
}
function changeTool(tool)
{
if (tool >= 0) {
if (getTool(tool).heaters.length > 0) {
// Tool macros are likely to block the HTTP G-Code processor, so we first turn off
// the appropriate heater, change the tool and then turn it back on.
var firstToolHeater = getTool(tool).heaters;
var gcode = "G10 P" + tool + " S-273\n" +
"T" + tool + "\n" +
"G10 P" + tool + " S" + $("#input_temp_h" + firstToolHeater + "_active").val();
sendGCode(gcode);
} else {
sendGCode("T" + tool);
}
} else {
sendGCode("T-1");
}
}
function clearBedTemperatures() {
$(".ul-bed-temp, #ul_bed_temps").html("");
$(".btn-bed-temp").addClass("disabled");
}
function clearGCodeDirectory() {
$("#ol_gcode_directory").children(":not(:last-child)").remove();
$("#ol_gcode_directory").prepend('
' + T("G-Codes Directory") + '
');
}
function clearGCodeFiles() {
$("#table_gcode_files > tbody").remove();
$("#table_gcode_files").addClass("hidden");
$("#page_files h1").removeClass("hidden");
if (isConnected) {
$("#page_files h1").text(T("No Files or Directories found"));
} else {
$("#page_files h1").text(T("Connect to your Duet to display G-Code files"));
}
}
function clearDefaultGCodes() {
$(".ul-gcodes").html("");
$("#table_gcodes > tbody").remove();
$(".btn-gcodes").addClass("disabled");
}
function clearHeadTemperatures() {
$(".ul-active-temp, .ul-standby-temp, #ul_active_temps, #ul_standby_temps").html("");
$(".btn-active-temp, .btn-standby-temp").addClass("disabled");
}
function clearMacroDirectory() {
$("#ol_macro_directory").children(":not(:last-child)").remove();
$("#ol_macro_directory").prepend('
' + T("Macros Directory") + '
');
}
function clearMacroFiles() {
// Control Page
if (currentMacroDirectory == "/macros") {
$("#panel_macro_buttons .btn-group-vertical").html("");
$("#panel_macro_buttons h4").removeClass("hidden");
}
// Macros Page
$("#table_macro_files > tbody").remove();
$("#table_macro_files").addClass("hidden");
$("#page_macros h1").removeClass("hidden");
if (isConnected) {
$("#page_macros h1").text(T("No Macro Files found"));
} else {
$("#page_macros h1").text(T("Connect to your Duet to display Macro files"));
}
}
function convertSeconds(value) {
value = Math.round(value);
if (value < 0) {
value = 0;
}
var timeLeft = [], temp;
if (value >= 3600) {
temp = Math.floor(value / 3600);
if (temp > 0) {
timeLeft.push(temp + "h");
value = value % 3600;
}
}
if (value >= 60) {
temp = Math.floor(value / 60);
if (temp > 0) {
timeLeft.push((temp > 9 ? temp : "0" + temp) + "m");
value = value % 60;
}
}
value = value.toFixed(0);
timeLeft.push((value > 9 ? value : "0" + value) + "s");
return timeLeft.reduce(function(a, b) { return a + " " + b; });
}
function formatSize(bytes) {
if (settings.useKiB) {
if (bytes > 1073741824) { // GiB
return (bytes / 1073741824).toFixed(1) + " GiB";
}
if (bytes > 1048576) { // MiB
return (bytes / 1048576).toFixed(1) + " MiB";
}
if (bytes > 1024) { // KiB
return (bytes / 1024).toFixed(1) + " KiB";
}
} else {
if (bytes > 1000000000) { // GB
return (bytes / 1000000000).toFixed(1) + " GB";
}
if (bytes > 1000000) { // MB
return (bytes / 1000000).toFixed(1) + " MB";
}
if (bytes > 1000) { // KB
return (bytes / 1000).toFixed(1) + " KB";
}
}
return bytes + " B";
}
function loadMacroDropdown(directory, dropdown) {
$.ajax("rr_files?dir=" + encodeURIComponent(directory), {
dataType: "json",
directory: directory,
dropdown: dropdown,
success: function(response) {
if (response.files.length == 0) {
dropdown.html('