Skip to content

Commit

Permalink
Add ability to download base tunes
Browse files Browse the repository at this point in the history
  • Loading branch information
noisymime committed Jul 17, 2019
1 parent 6a56aac commit 2788065
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 18 deletions.
13 changes: 13 additions & 0 deletions assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -2370,6 +2370,11 @@ input, select, textarea {
display: none;
}

select4 option {
color: #ffffff;
background: #022b3a;
}

input[type="text"],
input[type="password"],
input[type="email"],
Expand Down Expand Up @@ -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;
Expand Down
49 changes: 45 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -39,13 +40,18 @@
<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="btnDetails" value="View Firmware Notes" onclick="refreshDetails();" /></li>
<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' value="Get Base Tune" id="btnBasetune" onclick="window.location.href='#basetunes';" /></li>
</ul>
</p>
<div id="error"></div>
<div id="ports"></div>
Expand All @@ -62,7 +68,7 @@ <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' 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>
Expand Down Expand Up @@ -106,13 +112,48 @@ <h3>Terminal Output:</h3>
</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 -->
Expand Down
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand Down
98 changes: 85 additions & 13 deletions renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const {ipcRenderer} = require("electron")
const {remote} = require('electron')
const { shell } = require('electron')

var basetuneList = [];

function refreshSerialPorts()
{
serialport.list((err, ports) => {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
{
Expand All @@ -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()
{

Expand All @@ -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
Expand All @@ -166,26 +237,26 @@ function downloadIni()

}

//Installing the Windows drivers
function installDrivers()
function downloadBasetune()
{
ipcRenderer.send("installWinDrivers", {
});

}

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";
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()
{
ipcRenderer.send("installWinDrivers", {
});

}

Expand Down Expand Up @@ -330,6 +401,7 @@ window.onload = function () {
document.getElementById('title').innerHTML = "Speeduino Universal Firmware Loader (v" + remote.app.getVersion() + ")"

refreshAvailableFirmwares();
refreshBasetunes();
refreshSerialPorts();
checkForUpdates();

Expand Down

0 comments on commit 2788065

Please sign in to comment.