Add ability to download base tunes

This commit is contained in:
Josh Stewart 2019-07-17 16:51:27 +10:00
parent 6a56aacca2
commit 27880653a9
4 changed files with 147 additions and 21 deletions

View File

@ -2370,6 +2370,11 @@ input, select, textarea {
display: none;
}
select4 option {
color: #ffffff;
background: #022b3a;
}
input[type="text"],
input[type="password"],
input[type="email"],
@ -3252,6 +3257,14 @@ input, select, textarea {
background-color: #953d75;
}
.wrapper.style4 {
background-color: #022b3a;
}
.wrapper.style4-alt {
background-color: #022b3a;
}
.wrapper.fullscreen {
display: -moz-flex;
display: -webkit-flex;

View File

@ -26,6 +26,7 @@
<li><a href="#details">Firmware Details</a></li>
<li><a href="#port">Choose Port</a></li>
<li><a href="#progress">Progress</a></li>
<li><a href="#basetunes">Base Tunes</a></li>
</ul>
</nav>
</div>
@ -39,12 +40,17 @@
<div style="display: none; text-align: center;" id="update_text"><a href="" id="update_url" target="_blank">A new version is available. Click here to download</a></div>
<div class="inner">
<center><img src="assets/speeduino logo_white.png" width="235"/></center>
<!--<h1>Firmware Loader</h1>-->
<p>Available Firmwares:
<select name="firmwares" class="select" id="versionsSelect" size="10" width="20" ></select>
<select name="firmwares" class="select" id="versionsSelect" size="10" width="20" onClick="refreshBasetunes();"></select>
<ul class="actions">
<li><input type='button' id="btnChoosePort" value="Choose Port" onclick="window.location.href='#port';" /></li>
</ul>
<p>Other actions:</p>
<ul class="actions">
<li><input type='button' id="btnDetails" value="View Firmware Notes" onclick="refreshDetails();" /></li>
<li><input type='button' id="btnChoosePort" value="Choose Port" onclick="window.location.href='#port';" /></li>
<li><input type='button' value="Get Base Tune" id="btnBasetune" onclick="window.location.href='#basetunes';" /></li>
</ul>
</p>
<div id="error"></div>
@ -62,7 +68,7 @@
<div id="detailsText" style="padding-left: 0.9em; padding-right: 0.9em; overflow-y: auto; height: 50vh;"></div>
</div>
<ul class="actions">
<li><input type='button' value="Download Base Tune" id="btnBasetune" onclick="downloadTune();" /></li>
<li><input type='button' value="Get Base Tune" id="btnBasetune" onclick="window.location.href='#basetunes';" /></li>
<li><input type='button' id="btnDetails" value="Change Version" onclick="window.location.href='#loader';" /></li>
<li><input type='button' id="btnChoosePort" value="Install" onclick="window.location.href='#port';" /></li>
</ul>
@ -106,13 +112,48 @@
</section>
</div>
<ul class="actions">
<li><input type='button' id="btnChoosePort" value="Choose Port" onclick="window.location.href='#port';" /></li>
<li><input type='button' value="Burn again" id="btnReinstall" onclick="uploadFW();" /></li>
<li><input type='button' value="Download Base Tune" id="btnBasetune" onclick="downloadTune();" /></li>
<li><input type='button' value="Get Base Tune" id="btnBasetune" onclick="window.location.href='#basetunes';" /></li>
</ul>
<ul class="actions">
<li><input type='button' value="Exit" id="btnExit" onclick="quit();" /></li>
</ul>
</div>
</section>
<!-- Firmware details -->
<section id="details" class="wrapper style1-alt spotlights" style="display: none; height: 100vh;">
<div class="inner">
<h1>Firmware Notes</h1>
<div class="features major" >
<h2><div id="detailsHeading" style="padding-left: 0.55em;" ></div></h2>
<div id="detailsText" style="padding-left: 0.9em; padding-right: 0.9em; overflow-y: auto; height: 50vh;"></div>
</div>
<ul class="actions">
<li><input type='button' id="btnDetails" value="Change Version" onclick="window.location.href='#loader';" /></li>
<li><input type='button' id="btnChoosePort" value="Install" onclick="window.location.href='#port';" /></li>
</ul>
</div>
</section>
<!-- Base Tune download -->
<section id="basetunes" class="wrapper style4 fullscreen fade-up" style="height: 100vh;">
<div class="inner">
<h1>Base Tunes</h1>
<p>
Selected firmware: <span id="basetunesSelectedFW"></span><br />
Available Base Tunes:
<select name="basetunes" class="select4" id="basetunesSelect" size="10" width="20" ></select>
<ul class="actions">
<li><input type='button' value="Change firmware version" onclick="window.location.href='#loader';" /></li>
<li><input type='button' id="btnDownloadBasetune" value="Download tune" onclick="downloadBasetune();" /></li>
</ul>
</p>
</div>
</section>
</div>
<!-- Footer -->

View File

@ -71,7 +71,7 @@ ipcMain.on('download', (e, args) => {
//console.log("Filename: " + fullFile );
options = {};
if(filename == "Speeduino%20base%20tune.msq")
if(filename.split('.').pop() == "msq")
{
options = { saveAs: true };
}

View File

@ -3,6 +3,8 @@ const {ipcRenderer} = require("electron")
const {remote} = require('electron')
const { shell } = require('electron')
var basetuneList = [];
function refreshSerialPorts()
{
serialport.list((err, ports) => {
@ -87,8 +89,10 @@ function refreshAvailableFirmwares()
//Disable the buttons. These are only re-enabled if the retrieve is successful
var DetailsButton = document.getElementById("btnDetails");
var ChoosePortButton = document.getElementById("btnChoosePort");
var basetuneButton = document.getElementById("btnBasetune");
DetailsButton.disabled = true;
ChoosePortButton.disabled = true;
basetuneButton.disabled = true;
var request = require('request');
request.get('http://speeduino.com/fw/versions', {timeout: 10000}, function (error, response, body)
@ -107,10 +111,12 @@ function refreshAvailableFirmwares()
select.appendChild(newOption);
}
select.selectedIndex = 0;
refreshBasetunes();
//Re-enable the buttons
DetailsButton.disabled = false;
ChoosePortButton.disabled = false;
basetuneButton.disabled = false;
}
else if(error)
{
@ -136,6 +142,71 @@ function refreshAvailableFirmwares()
);
}
function refreshBasetunes()
{
//Check whether the base tunes list has been populated yet
if(basetuneList === undefined || basetuneList.length == 0)
{
console.log("No tunes loaded. Retrieving from server");
//Load the json
var url = "https://speeduino.com/fw/basetunes.json";
var request = require('request');
const options = {
url: url,
headers: {
'User-Agent': 'request'
}
};
request.get(options, function (error, response, body) {
if (!error )
{
basetuneList = JSON.parse(body);
refreshBasetunes();
}
});
}
else
{
//JSON list of base tunes has been downloaded
//Get the display list object
var select = document.getElementById('basetunesSelect');
//Get the currently selected version
selectElement = document.getElementById('versionsSelect');
if(selectElement.selectedIndex == -1) { return; } //Check for no value being selected
var selectedFW = selectElement.options[selectElement.selectedIndex].value;
//Clear the current options from the list
while(select.options.length)
{
select.remove(0);
}
for (var tune in basetuneList)
{
//Check whether the current tune was available for the selected firmware
if(parseInt(basetuneList[tune].introduced) <= parseInt(selectedFW))
{
var url = basetuneList[tune].baseURL.replace("$VERSION", selectedFW) + basetuneList[tune].filename;
//console.log("Tune url: " + url);
//console.log("Found a valid tune: " + basetuneList[tune].displayName);
var newOption = document.createElement('option');
newOption.style.background = "#022b3a";
newOption.value = url;
newOption.innerHTML = basetuneList[tune].displayName;
select.appendChild(newOption);
}
}
//Finally update the selected firmware label on the basetunes page
document.getElementById('basetunesSelectedFW').innerHTML = selectedFW;
}
}
function downloadHex()
{
@ -155,7 +226,7 @@ function downloadIni()
{
var e = document.getElementById('versionsSelect');
var DLurl = "http://speeduino.com/fw/" + e.options[e.selectedIndex].value + ".ini";
var DLurl = "https://speeduino.com/fw/" + e.options[e.selectedIndex].value + ".ini";
console.log("Downloading: " + DLurl);
//Download the ini file
@ -166,6 +237,21 @@ function downloadIni()
}
function downloadBasetune()
{
var basetuneSelect = document.getElementById('basetunesSelect');
var version = document.getElementById('versionsSelect');
//var DLurl = "https://github.com/noisymime/speeduino/raw/" + version + "/reference/Base%20Tunes/" + e.options[e.selectedIndex].value;
var DLurl = basetuneSelect.options[basetuneSelect.selectedIndex].value;
console.log("Downloading: " + DLurl);
//Download the ini file
ipcRenderer.send("download", {
url: DLurl,
properties: {directory: "downloads"}
});
}
//Installing the Windows drivers
function installDrivers()
{
@ -174,21 +260,6 @@ function installDrivers()
}
function downloadTune()
{
var e = document.getElementById('versionsSelect');
var DLurl = "https://raw.githubusercontent.com/noisymime/speeduino/" + e.options[e.selectedIndex].value + "/reference/Base%20Tunes/Speeduino%20base%20tune.msq";
console.log("Downloading: " + DLurl);
//Download the ini file
ipcRenderer.send("download", {
url: DLurl,
properties: {directory: "downloads"}
});
}
function uploadFW()
{
//Jump to the progress section
@ -330,6 +401,7 @@ window.onload = function () {
document.getElementById('title').innerHTML = "Speeduino Universal Firmware Loader (v" + remote.app.getVersion() + ")"
refreshAvailableFirmwares();
refreshBasetunes();
refreshSerialPorts();
checkForUpdates();