2018-12-31 05:59:18 -08:00
|
|
|
const serialport = require('serialport')
|
2019-01-01 15:47:54 -08:00
|
|
|
const {ipcRenderer} = require("electron")
|
2019-01-14 14:34:00 -08:00
|
|
|
const {remote} = require('electron')
|
2019-01-26 17:34:31 -08:00
|
|
|
const { shell } = require('electron')
|
2018-12-31 05:59:18 -08:00
|
|
|
|
|
|
|
function refreshSerialPorts()
|
|
|
|
{
|
|
|
|
serialport.list((err, ports) => {
|
2019-01-02 19:17:33 -08:00
|
|
|
console.log('Serial ports found: ', ports);
|
2018-12-31 05:59:18 -08:00
|
|
|
if (err) {
|
|
|
|
document.getElementById('serialDetectError').textContent = err.message
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
document.getElementById('serialDetectError').textContent = ''
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ports.length === 0) {
|
|
|
|
document.getElementById('serialDetectError').textContent = 'No ports discovered'
|
|
|
|
}
|
|
|
|
|
|
|
|
select = document.getElementById('portsSelect');
|
|
|
|
|
|
|
|
//Clear the current options
|
2019-01-02 19:17:33 -08:00
|
|
|
for (i = 0; i <= select.options.length; i++)
|
2018-12-31 05:59:18 -08:00
|
|
|
{
|
2019-01-02 19:17:33 -08:00
|
|
|
select.remove(0); //Always 0 index (As each time an item is removed, everything shuffles up 1 place)
|
2018-12-31 05:59:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
//Load the current serial values
|
2019-01-01 15:47:54 -08:00
|
|
|
for(var i = 0; i < ports.length; i++)
|
2018-12-31 05:59:18 -08:00
|
|
|
{
|
|
|
|
var newOption = document.createElement('option');
|
|
|
|
newOption.value = ports[i].comName;
|
|
|
|
newOption.innerHTML = ports[i].comName;
|
2019-01-02 19:17:33 -08:00
|
|
|
select.add(newOption);
|
2018-12-31 05:59:18 -08:00
|
|
|
}
|
2019-01-02 18:44:21 -08:00
|
|
|
var button = document.getElementById("btnInstall")
|
|
|
|
if(ports.length > 0)
|
|
|
|
{
|
|
|
|
select.selectedIndex = 0;
|
|
|
|
button.disabled = false;
|
|
|
|
}
|
|
|
|
else { button.disabled = true; }
|
2018-12-31 05:59:18 -08:00
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-01-01 19:47:18 -08:00
|
|
|
function refreshDetails()
|
2019-01-01 15:47:54 -08:00
|
|
|
{
|
|
|
|
var selectElement = document.getElementById('versionsSelect');
|
2019-01-01 21:18:31 -08:00
|
|
|
var version = selectElement.options[selectElement.selectedIndex].value;
|
|
|
|
var url = "https://api.github.com/repos/noisymime/speeduino/releases/tags/" + version;
|
|
|
|
|
|
|
|
document.getElementById('detailsHeading').innerHTML = version;
|
2019-01-01 15:47:54 -08:00
|
|
|
|
2019-01-01 19:47:18 -08:00
|
|
|
var request = require('request');
|
|
|
|
const options = {
|
|
|
|
url: url,
|
|
|
|
headers: {
|
|
|
|
'User-Agent': 'request'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
request.get(options, function (error, response, body) {
|
|
|
|
if (!error ) {
|
|
|
|
|
|
|
|
console.log(body);
|
|
|
|
var result = JSON.parse(body);
|
|
|
|
|
|
|
|
// Continue with your processing here.
|
|
|
|
textField = document.getElementById('detailsText');
|
|
|
|
|
|
|
|
//Need to convert the Markdown that comes from Github to HTML
|
|
|
|
var myMarked = require('marked');
|
|
|
|
textField.innerHTML = myMarked(result.body);
|
|
|
|
}
|
|
|
|
});
|
2019-01-01 21:18:31 -08:00
|
|
|
|
|
|
|
//Finally, make the details section visible
|
|
|
|
document.getElementById('details').style.display = "inline";
|
|
|
|
//And jump to it
|
|
|
|
window.location.href = "#details";
|
2019-01-01 15:47:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function refreshAvailableFirmwares()
|
|
|
|
{
|
2019-01-04 02:47:00 -08:00
|
|
|
//Disable the buttons. These are only re-enabled if the retrieve is successful
|
|
|
|
var DetailsButton = document.getElementById("btnDetails");
|
|
|
|
var ChoosePortButton = document.getElementById("btnChoosePort");
|
|
|
|
DetailsButton.disabled = true;
|
|
|
|
ChoosePortButton.disabled = true;
|
|
|
|
|
2019-01-01 15:47:54 -08:00
|
|
|
var request = require('request');
|
2019-01-04 02:47:00 -08:00
|
|
|
request.get('http://speeduino.com/fw/versions', {timeout: 10000}, function (error, response, body)
|
|
|
|
{
|
|
|
|
select = document.getElementById('versionsSelect');
|
2019-01-01 15:47:54 -08:00
|
|
|
if (!error && response.statusCode == 200) {
|
|
|
|
|
|
|
|
var lines = body.split('\n');
|
|
|
|
// Continue with your processing here.
|
2019-01-04 02:47:00 -08:00
|
|
|
|
2019-01-01 15:47:54 -08:00
|
|
|
for(var i = 0;i < lines.length;i++)
|
|
|
|
{
|
|
|
|
var newOption = document.createElement('option');
|
|
|
|
newOption.value = lines[i];
|
|
|
|
newOption.innerHTML = lines[i];
|
|
|
|
select.appendChild(newOption);
|
|
|
|
}
|
|
|
|
select.selectedIndex = 0;
|
2019-01-04 02:47:00 -08:00
|
|
|
|
|
|
|
//Re-enable the buttons
|
|
|
|
DetailsButton.disabled = false;
|
|
|
|
ChoosePortButton.disabled = false;
|
2019-01-01 15:47:54 -08:00
|
|
|
}
|
2019-01-04 02:47:00 -08:00
|
|
|
else if(error)
|
|
|
|
{
|
|
|
|
console.log("Error retrieving available firmwares");
|
|
|
|
var newOption = document.createElement('option');
|
|
|
|
if(error.code === 'ETIMEDOUT')
|
|
|
|
{
|
|
|
|
newOption.value = "Connection timed out";
|
|
|
|
newOption.innerHTML = "Connection timed out";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newOption.value = "Cannot retrieve firmware list";
|
|
|
|
newOption.innerHTML = "Cannot retrieve firmware list. Check internet connection and restart";
|
|
|
|
}
|
|
|
|
select.appendChild(newOption);
|
|
|
|
}
|
|
|
|
else if(response.statusCode == 404)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2019-01-01 15:47:54 -08:00
|
|
|
}
|
|
|
|
|
2019-01-01 21:18:31 -08:00
|
|
|
function downloadHex()
|
2018-12-31 05:59:18 -08:00
|
|
|
{
|
2019-01-01 21:18:31 -08:00
|
|
|
|
2018-12-31 05:59:18 -08:00
|
|
|
var e = document.getElementById('versionsSelect');
|
|
|
|
var DLurl = "http://speeduino.com/fw/bin/" + e.options[e.selectedIndex].value + ".hex";
|
2019-01-01 21:18:31 -08:00
|
|
|
console.log("Downloading: " + DLurl);
|
2018-12-31 05:59:18 -08:00
|
|
|
|
|
|
|
//Download the Hex file
|
|
|
|
ipcRenderer.send("download", {
|
|
|
|
url: DLurl,
|
|
|
|
properties: {directory: "downloads"}
|
|
|
|
});
|
|
|
|
|
2019-01-01 21:18:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function downloadIni()
|
|
|
|
{
|
|
|
|
|
|
|
|
var e = document.getElementById('versionsSelect');
|
2018-12-31 05:59:18 -08:00
|
|
|
var DLurl = "http://speeduino.com/fw/" + e.options[e.selectedIndex].value + ".ini";
|
2019-01-01 21:18:31 -08:00
|
|
|
console.log("Downloading: " + DLurl);
|
|
|
|
|
|
|
|
//Download the ini file
|
2018-12-31 05:59:18 -08:00
|
|
|
ipcRenderer.send("download", {
|
|
|
|
url: DLurl,
|
|
|
|
properties: {directory: "downloads"}
|
|
|
|
});
|
2019-01-01 21:18:31 -08:00
|
|
|
|
2018-12-31 05:59:18 -08:00
|
|
|
}
|
|
|
|
|
2019-01-01 15:47:54 -08:00
|
|
|
function uploadFW()
|
2018-12-31 05:59:18 -08:00
|
|
|
{
|
2019-01-01 21:18:31 -08:00
|
|
|
//Jump to the progress section
|
|
|
|
window.location.href = "#progress";
|
|
|
|
|
2019-01-03 23:54:39 -08:00
|
|
|
//Start the spinner
|
|
|
|
var spinner = document.getElementById('progressSpinner');
|
2019-01-15 04:25:15 -08:00
|
|
|
//Disable the Re-burn/re-install button
|
|
|
|
var reinstallButton = document.getElementById("btnReinstall")
|
|
|
|
reinstallButton.disabled = true;
|
2019-01-03 23:54:39 -08:00
|
|
|
//Remove any old icons
|
|
|
|
spinner.classList.remove('fa-pause');
|
|
|
|
spinner.classList.remove('fa-check');
|
|
|
|
spinner.classList.remove('fa-times');
|
|
|
|
spinner.classList.add('fa-spinner');
|
|
|
|
|
2019-01-14 14:21:56 -08:00
|
|
|
//Hide the terminal section incase it was there from a previous burn attempt
|
|
|
|
document.getElementById('terminalSection').style.display = "none";
|
2019-01-26 17:34:31 -08:00
|
|
|
//Same for the ini location link
|
|
|
|
document.getElementById('iniFileText').style.display = "none";
|
2019-01-14 14:21:56 -08:00
|
|
|
|
2019-01-01 19:47:18 -08:00
|
|
|
var statusText = document.getElementById('statusText');
|
2019-01-04 04:10:03 -08:00
|
|
|
var burnPercentText = document.getElementById('burnPercent');
|
2019-01-01 21:18:31 -08:00
|
|
|
statusText.innerHTML = "Downloading INI file"
|
|
|
|
downloadIni();
|
2019-01-01 19:47:18 -08:00
|
|
|
|
2019-01-01 21:18:31 -08:00
|
|
|
|
2019-01-04 04:10:03 -08:00
|
|
|
ipcRenderer.on("download complete", (event, file, state) => {
|
2019-01-01 21:18:31 -08:00
|
|
|
console.log("Saved file: " + file); // Full file path
|
|
|
|
|
|
|
|
var extension = file.substr(file.length - 3);
|
|
|
|
if(extension == "ini")
|
|
|
|
{
|
|
|
|
statusText.innerHTML = "Downloading firmware"
|
2019-01-26 17:34:31 -08:00
|
|
|
document.getElementById('iniFileText').style.display = "block"
|
|
|
|
document.getElementById('iniFileLocation').innerHTML = file
|
2019-01-01 21:18:31 -08:00
|
|
|
downloadHex();
|
|
|
|
}
|
|
|
|
else if(extension == "hex")
|
|
|
|
{
|
2019-01-14 14:21:56 -08:00
|
|
|
statusText.innerHTML = "Beginning upload..."
|
2019-01-01 21:18:31 -08:00
|
|
|
|
|
|
|
//Retrieve the select serial port
|
|
|
|
var e = document.getElementById('portsSelect');
|
|
|
|
uploadPort = e.options[e.selectedIndex].value;
|
|
|
|
console.log("Using port: " + uploadPort);
|
|
|
|
|
|
|
|
//Begin the upload
|
|
|
|
ipcRenderer.send("uploadFW", {
|
|
|
|
port: uploadPort,
|
|
|
|
firmwareFile: file
|
|
|
|
});
|
|
|
|
}
|
|
|
|
console.log();
|
|
|
|
});
|
|
|
|
|
|
|
|
ipcRenderer.on("upload completed", (event, code) => {
|
2019-01-02 06:05:30 -08:00
|
|
|
statusText.innerHTML = "Upload to arduino completed successfully!";
|
2019-01-04 04:10:03 -08:00
|
|
|
burnPercentText.innerHTML = "";
|
2019-01-15 04:25:15 -08:00
|
|
|
|
|
|
|
//Turn the spinner off
|
2019-01-03 23:54:39 -08:00
|
|
|
spinner.classList.remove('fa-spinner');
|
|
|
|
spinner.classList.add('fa-check');
|
2019-01-15 04:25:15 -08:00
|
|
|
|
|
|
|
//Re-enable the re-burn button
|
|
|
|
reinstallButton.disabled = true;
|
2019-01-01 15:47:54 -08:00
|
|
|
});
|
2019-01-01 21:18:31 -08:00
|
|
|
|
2019-01-04 04:10:03 -08:00
|
|
|
ipcRenderer.on("upload percent", (event, percent) => {
|
2019-01-14 14:21:56 -08:00
|
|
|
statusText.innerHTML = "Uploading firmware to board"
|
2019-01-04 04:10:03 -08:00
|
|
|
burnPercentText.innerHTML = " (" + percent + "%)";
|
|
|
|
});
|
|
|
|
|
2019-01-01 21:18:31 -08:00
|
|
|
ipcRenderer.on("upload error", (event, code) => {
|
2019-01-14 14:21:56 -08:00
|
|
|
statusText.innerHTML = "Upload to Speeduino failed";
|
2019-01-02 18:44:21 -08:00
|
|
|
//Mke the terminal/error section visible
|
2019-01-03 23:54:39 -08:00
|
|
|
document.getElementById('terminalSection').style.display = "block";
|
2019-01-02 18:44:21 -08:00
|
|
|
document.getElementById('terminalText').innerHTML = code;
|
2019-01-03 23:54:39 -08:00
|
|
|
spinner.classList.remove('fa-spinner');
|
|
|
|
spinner.classList.add('fa-times');
|
2019-01-15 04:25:15 -08:00
|
|
|
|
|
|
|
reinstallButton.disabled = true;
|
2019-01-01 21:18:31 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-12-31 05:59:18 -08:00
|
|
|
}
|
|
|
|
|
2019-01-26 17:34:31 -08:00
|
|
|
//Opens a native file manager window at the location of the downloaded ini file
|
|
|
|
function openFileMgr()
|
|
|
|
{
|
|
|
|
var location = document.getElementById('iniFileLocation').innerHTML
|
|
|
|
if (location != "")
|
|
|
|
{
|
|
|
|
shell.showItemInFolder(location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-14 14:34:00 -08:00
|
|
|
function quit()
|
|
|
|
{
|
|
|
|
let w = remote.getCurrentWindow();
|
|
|
|
w.close();
|
|
|
|
}
|
|
|
|
|
2019-01-04 02:47:00 -08:00
|
|
|
window.onload = function () {
|
|
|
|
refreshSerialPorts();
|
|
|
|
refreshAvailableFirmwares();
|
|
|
|
};
|
|
|
|
|