var selectedControllerType = 'blackbox4x'
function flashToolBoard(device) {
selectedControllerType = device
if (device == "blackbox4x") {
$("#grblAxesCount").data("select").val("3axes-grbl")
$("#flash-tool-grbl-row").show();
$("#flash-tool-grblhal-row").hide();
$("#flash-tool-erase-row").hide();
$("#flash-tool-interface-fw-row").hide();
$("#flash-tool-custom-row").hide();
$("#customFirmwareSet").html("Please select the Grbl Firmware hex file you want to flash");
} else if (device == "blackboxx32") {
$("#grblHalAxesCount").data("select").val("3axes-grblhal")
$("#flash-tool-grbl-row").hide();
$("#flash-tool-grblhal-row").show();
$("#flash-tool-erase-row").show();
$("#flash-tool-interface-fw-row").hide();
$("#flash-tool-custom-row").hide();
$("#customFirmwareSet").html("Please select the GrblHAL Firmware binary file you want to flash");
} else if (device == "interfacev1") {
$("#interfaceFirmwareVer").data("select").val("online")
$("#flash-tool-grbl-row").hide();
$("#flash-tool-grblhal-row").hide();
$("#flash-tool-erase-row").hide();
$("#flash-tool-interface-fw-row").show();
$("#customFirmwareSet").html("Please select the Interface Firmware binary file you want to flash");
}
}
function openFlashingTool() {
var template = `
You can use this wizard to flash Firmware onto compatible controllers. Only use with care, or when instructed by Support
`
Metro.dialog.create({
title: " Firmware Flashing Tool",
content: template,
toTop: true,
width: '75%',
clsDialog: 'dark',
actions: [{
caption: "FLASH",
cls: "js-dialog-close success",
onclick: function() {
flashFirmwarefromWizard();
}
}, {
caption: "Cancel",
cls: "js-dialog-close",
onclick: function() {
//
}
}]
});
$("#grblAxesCount").on("change", function() {
if (this.value == "custom") {
$("#flash-tool-door-row").hide();
$("#flash-tool-custom-row").show();
} else {
$("#flash-tool-door-row").show();
$("#flash-tool-custom-row").hide();
}
});
$("#grblHalAxesCount").on("change", function() {
if (this.value == "custom") {
$("#flash-tool-door-row").hide();
$("#flash-tool-custom-row").show();
} else {
$("#flash-tool-door-row").show();
$("#flash-tool-custom-row").hide();
}
});
$("#interfaceFirmwareVer").on("change", function() {
if (this.value == "custom") {
$("#flash-tool-custom-row").show();
} else {
$("#flash-tool-custom-row").hide();
}
});
setTimeout(function() {
var opts = ``;
if (parseFloat(laststatus.interface.firmware.availVersion) > 0) {
opts += ``;
}
var fwselect = $("#interfaceFirmwareVer").data("select");
fwselect.data(opts);
populatePortsMenu();
}, 200);
}
function readEspFirmwareFile() {
console.log("Sending")
var form = document.getElementById('customFirmwareForm');
var formData = new FormData(form);
var xhr = new XMLHttpRequest();
xhr.onload = function() {
if (xhr.status == 200) {
$("#customFirmwareSet").html(xhr.response)
}
};
// Add any event handlers here...
xhr.open('POST', '/uploadCustomFirmware', true);
xhr.send(formData);
}
function flashFirmwarefromWizard() {
if (selectedControllerType == "blackbox4x") {
if ($("#grblAxesCount").val() == "3axes-grbl") {
var filename = "grbl-3axes-nodoor.hex";
} else if ($("#grblAxesCount").val() == "2axes-grbl") {
var filename = "grbl-2axes-nodoor.hex";
} else if ($("#grblAxesCount").val() == "servo-grbl") {
var filename = "grbl-servo-nodoor.hex";
}
var data = {
port: $("#portUSB2").val(),
file: filename,
board: $("#flashController").val(),
customImg: false
}
if ($("#grblAxesCount").val() == "custom") {
// Custom Firmware
if ($("#firmwareBin").val().length > 0) {
var form = document.getElementById('customFirmwareForm');
var formData = new FormData(form);
var xhr = new XMLHttpRequest();
xhr.onload = function() {
if (xhr.status == 200) {
console.log(xhr.response);
$("#customFirmwareSet").html(xhr.response);
data.customImg = true;
data.file = xhr.response;
console.log(data);
socket.emit('flashGrbl', data);
}
};
// Add any event handlers here...
xhr.open('POST', '/uploadCustomFirmware', true);
xhr.send(formData);
} else {
$('#controlTab').click();
$('#consoletab').click();
printLog("[ Firmware Upgrade ] You selected the option to use a custom firmware file, but failed to select a file to use for the operation. Please try again")
}
} else {
// Precompiled Firmwares
socket.emit('flashGrbl', data)
}
} else if (selectedControllerType == "blackboxx32") {
if ($("#grblHalAxesCount").val() == "3axes-grblhal") {
var filename = "grblhal-grbl3axis.bin";
} else if ($("#grblHalAxesCount").val() == "2axes-grblhal") {
var filename = "";
} else if ($("#grblHalAxesCount").val() == "4axes-grblhal") {
var filename = "grblhal-grbl4axis.bin";
}
var data = {
port: $("#portUSB2").val(),
file: filename,
erase: false,
customImg: false
}
if ($("#flashErase").val() == "flasherase") {
data.erase = true;
}
if ($("#grblHalAxesCount").val() == "custom") {
// Custom Firmware
if ($("#firmwareBin").val().length > 0) {
var form = document.getElementById('customFirmwareForm');
var formData = new FormData(form);
var xhr = new XMLHttpRequest();
xhr.onload = function() {
if (xhr.status == 200) {
$("#customFirmwareSet").html(xhr.response);
data.customImg = true;
data.file = $("#firmwareBin").val();
socket.emit('flashGrblHal', data);
}
};
// Add any event handlers here...
xhr.open('POST', '/uploadCustomFirmware', true);
xhr.send(formData);
} else {
$('#controlTab').click();
$('#consoletab').click();
printLog("[ Firmware Upgrade ] You selected the option to use a custom firmware file, but failed to select a file to use for the operation. Please try again")
}
} else {
// Precompiled Firmwares
socket.emit('flashGrblHal', data)
}
} else if (selectedControllerType == "interfacev1") {
var data = {
port: $("#portUSB2").val(),
file: "firmware.bin", // version that ships with Interface
board: $("#flashController").val()
}
if ($("#interfaceFirmwareVer").val() == "custom") {
// custom image
if ($("#firmwareBin").val().length > 0) {
var form = document.getElementById('customFirmwareForm');
var formData = new FormData(form);
var xhr = new XMLHttpRequest();
xhr.onload = function() {
if (xhr.status == 200) {
$("#customFirmwareSet").html(xhr.response);
data.file = $("#firmwareBin").val();
socket.emit('flashInterface', data);
}
};
// Add any event handlers here...
xhr.open('POST', '/uploadCustomFirmware', true);
xhr.send(formData);
} else {
$('#controlTab').click();
$('#consoletab').click();
printLog("[ Firmware Upgrade ] You selected the option to use a custom firmware file, but failed to select a file to use for the operation. Please try again")
}
} else {
// latest included firmware
socket.emit('flashInterface', data)
}
} else {
console.log("no controller selected")
}
}