Skip to content

Commit 2788065

Browse files
committed
Add ability to download base tunes
1 parent 6a56aac commit 2788065

File tree

4 files changed

+144
-18
lines changed

4 files changed

+144
-18
lines changed

assets/css/main.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,6 +2370,11 @@ input, select, textarea {
23702370
display: none;
23712371
}
23722372

2373+
select4 option {
2374+
color: #ffffff;
2375+
background: #022b3a;
2376+
}
2377+
23732378
input[type="text"],
23742379
input[type="password"],
23752380
input[type="email"],
@@ -3252,6 +3257,14 @@ input, select, textarea {
32523257
background-color: #953d75;
32533258
}
32543259

3260+
.wrapper.style4 {
3261+
background-color: #022b3a;
3262+
}
3263+
3264+
.wrapper.style4-alt {
3265+
background-color: #022b3a;
3266+
}
3267+
32553268
.wrapper.fullscreen {
32563269
display: -moz-flex;
32573270
display: -webkit-flex;

index.html

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<li><a href="#details">Firmware Details</a></li>
2727
<li><a href="#port">Choose Port</a></li>
2828
<li><a href="#progress">Progress</a></li>
29+
<li><a href="#basetunes">Base Tunes</a></li>
2930
</ul>
3031
</nav>
3132
</div>
@@ -39,13 +40,18 @@
3940
<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>
4041
<div class="inner">
4142
<center><img src="assets/speeduino logo_white.png" width="235"/></center>
43+
4244
<!--<h1>Firmware Loader</h1>-->
4345
<p>Available Firmwares:
44-
<select name="firmwares" class="select" id="versionsSelect" size="10" width="20" ></select>
46+
<select name="firmwares" class="select" id="versionsSelect" size="10" width="20" onClick="refreshBasetunes();"></select>
4547
<ul class="actions">
46-
<li><input type='button' id="btnDetails" value="View Firmware Notes" onclick="refreshDetails();" /></li>
4748
<li><input type='button' id="btnChoosePort" value="Choose Port" onclick="window.location.href='#port';" /></li>
4849
</ul>
50+
<p>Other actions:</p>
51+
<ul class="actions">
52+
<li><input type='button' id="btnDetails" value="View Firmware Notes" onclick="refreshDetails();" /></li>
53+
<li><input type='button' value="Get Base Tune" id="btnBasetune" onclick="window.location.href='#basetunes';" /></li>
54+
</ul>
4955
</p>
5056
<div id="error"></div>
5157
<div id="ports"></div>
@@ -62,7 +68,7 @@ <h2><div id="detailsHeading" style="padding-left: 0.55em;" ></div></h2>
6268
<div id="detailsText" style="padding-left: 0.9em; padding-right: 0.9em; overflow-y: auto; height: 50vh;"></div>
6369
</div>
6470
<ul class="actions">
65-
<li><input type='button' value="Download Base Tune" id="btnBasetune" onclick="downloadTune();" /></li>
71+
<li><input type='button' value="Get Base Tune" id="btnBasetune" onclick="window.location.href='#basetunes';" /></li>
6672
<li><input type='button' id="btnDetails" value="Change Version" onclick="window.location.href='#loader';" /></li>
6773
<li><input type='button' id="btnChoosePort" value="Install" onclick="window.location.href='#port';" /></li>
6874
</ul>
@@ -106,13 +112,48 @@ <h3>Terminal Output:</h3>
106112
</section>
107113
</div>
108114
<ul class="actions">
115+
<li><input type='button' id="btnChoosePort" value="Choose Port" onclick="window.location.href='#port';" /></li>
109116
<li><input type='button' value="Burn again" id="btnReinstall" onclick="uploadFW();" /></li>
110-
<li><input type='button' value="Download Base Tune" id="btnBasetune" onclick="downloadTune();" /></li>
117+
<li><input type='button' value="Get Base Tune" id="btnBasetune" onclick="window.location.href='#basetunes';" /></li>
118+
</ul>
119+
<ul class="actions">
111120
<li><input type='button' value="Exit" id="btnExit" onclick="quit();" /></li>
112121
</ul>
113122
</div>
114123
</section>
115124

125+
<!-- Firmware details -->
126+
<section id="details" class="wrapper style1-alt spotlights" style="display: none; height: 100vh;">
127+
<div class="inner">
128+
<h1>Firmware Notes</h1>
129+
130+
<div class="features major" >
131+
<h2><div id="detailsHeading" style="padding-left: 0.55em;" ></div></h2>
132+
<div id="detailsText" style="padding-left: 0.9em; padding-right: 0.9em; overflow-y: auto; height: 50vh;"></div>
133+
</div>
134+
<ul class="actions">
135+
<li><input type='button' id="btnDetails" value="Change Version" onclick="window.location.href='#loader';" /></li>
136+
<li><input type='button' id="btnChoosePort" value="Install" onclick="window.location.href='#port';" /></li>
137+
</ul>
138+
</div>
139+
</section>
140+
141+
<!-- Base Tune download -->
142+
<section id="basetunes" class="wrapper style4 fullscreen fade-up" style="height: 100vh;">
143+
<div class="inner">
144+
<h1>Base Tunes</h1>
145+
<p>
146+
Selected firmware: <span id="basetunesSelectedFW"></span><br />
147+
Available Base Tunes:
148+
<select name="basetunes" class="select4" id="basetunesSelect" size="10" width="20" ></select>
149+
<ul class="actions">
150+
<li><input type='button' value="Change firmware version" onclick="window.location.href='#loader';" /></li>
151+
<li><input type='button' id="btnDownloadBasetune" value="Download tune" onclick="downloadBasetune();" /></li>
152+
</ul>
153+
</p>
154+
</div>
155+
</section>
156+
116157
</div>
117158

118159
<!-- Footer -->

main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ ipcMain.on('download', (e, args) => {
7171

7272
//console.log("Filename: " + fullFile );
7373
options = {};
74-
if(filename == "Speeduino%20base%20tune.msq")
74+
if(filename.split('.').pop() == "msq")
7575
{
7676
options = { saveAs: true };
7777
}

renderer.js

Lines changed: 85 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const {ipcRenderer} = require("electron")
33
const {remote} = require('electron')
44
const { shell } = require('electron')
55

6+
var basetuneList = [];
7+
68
function refreshSerialPorts()
79
{
810
serialport.list((err, ports) => {
@@ -87,8 +89,10 @@ function refreshAvailableFirmwares()
8789
//Disable the buttons. These are only re-enabled if the retrieve is successful
8890
var DetailsButton = document.getElementById("btnDetails");
8991
var ChoosePortButton = document.getElementById("btnChoosePort");
92+
var basetuneButton = document.getElementById("btnBasetune");
9093
DetailsButton.disabled = true;
9194
ChoosePortButton.disabled = true;
95+
basetuneButton.disabled = true;
9296

9397
var request = require('request');
9498
request.get('http://speeduino.com/fw/versions', {timeout: 10000}, function (error, response, body)
@@ -107,10 +111,12 @@ function refreshAvailableFirmwares()
107111
select.appendChild(newOption);
108112
}
109113
select.selectedIndex = 0;
114+
refreshBasetunes();
110115

111116
//Re-enable the buttons
112117
DetailsButton.disabled = false;
113118
ChoosePortButton.disabled = false;
119+
basetuneButton.disabled = false;
114120
}
115121
else if(error)
116122
{
@@ -136,6 +142,71 @@ function refreshAvailableFirmwares()
136142
);
137143
}
138144

145+
function refreshBasetunes()
146+
{
147+
//Check whether the base tunes list has been populated yet
148+
if(basetuneList === undefined || basetuneList.length == 0)
149+
{
150+
console.log("No tunes loaded. Retrieving from server");
151+
//Load the json
152+
var url = "https://speeduino.com/fw/basetunes.json";
153+
154+
var request = require('request');
155+
const options = {
156+
url: url,
157+
headers: {
158+
'User-Agent': 'request'
159+
}
160+
};
161+
162+
request.get(options, function (error, response, body) {
163+
if (!error )
164+
{
165+
basetuneList = JSON.parse(body);
166+
refreshBasetunes();
167+
}
168+
});
169+
}
170+
else
171+
{
172+
//JSON list of base tunes has been downloaded
173+
174+
//Get the display list object
175+
var select = document.getElementById('basetunesSelect');
176+
177+
//Get the currently selected version
178+
selectElement = document.getElementById('versionsSelect');
179+
if(selectElement.selectedIndex == -1) { return; } //Check for no value being selected
180+
var selectedFW = selectElement.options[selectElement.selectedIndex].value;
181+
182+
//Clear the current options from the list
183+
while(select.options.length)
184+
{
185+
select.remove(0);
186+
}
187+
188+
for (var tune in basetuneList)
189+
{
190+
//Check whether the current tune was available for the selected firmware
191+
if(parseInt(basetuneList[tune].introduced) <= parseInt(selectedFW))
192+
{
193+
var url = basetuneList[tune].baseURL.replace("$VERSION", selectedFW) + basetuneList[tune].filename;
194+
//console.log("Tune url: " + url);
195+
//console.log("Found a valid tune: " + basetuneList[tune].displayName);
196+
var newOption = document.createElement('option');
197+
newOption.style.background = "#022b3a";
198+
newOption.value = url;
199+
newOption.innerHTML = basetuneList[tune].displayName;
200+
select.appendChild(newOption);
201+
}
202+
203+
}
204+
205+
//Finally update the selected firmware label on the basetunes page
206+
document.getElementById('basetunesSelectedFW').innerHTML = selectedFW;
207+
}
208+
}
209+
139210
function downloadHex()
140211
{
141212

@@ -155,7 +226,7 @@ function downloadIni()
155226
{
156227

157228
var e = document.getElementById('versionsSelect');
158-
var DLurl = "http://speeduino.com/fw/" + e.options[e.selectedIndex].value + ".ini";
229+
var DLurl = "https://speeduino.com/fw/" + e.options[e.selectedIndex].value + ".ini";
159230
console.log("Downloading: " + DLurl);
160231

161232
//Download the ini file
@@ -166,26 +237,26 @@ function downloadIni()
166237

167238
}
168239

169-
//Installing the Windows drivers
170-
function installDrivers()
240+
function downloadBasetune()
171241
{
172-
ipcRenderer.send("installWinDrivers", {
173-
});
174-
175-
}
176-
177-
function downloadTune()
178-
{
179-
180-
var e = document.getElementById('versionsSelect');
181-
var DLurl = "https://raw.githubusercontent.com/noisymime/speeduino/" + e.options[e.selectedIndex].value + "/reference/Base%20Tunes/Speeduino%20base%20tune.msq";
242+
var basetuneSelect = document.getElementById('basetunesSelect');
243+
var version = document.getElementById('versionsSelect');
244+
//var DLurl = "https://github.com/noisymime/speeduino/raw/" + version + "/reference/Base%20Tunes/" + e.options[e.selectedIndex].value;
245+
var DLurl = basetuneSelect.options[basetuneSelect.selectedIndex].value;
182246
console.log("Downloading: " + DLurl);
183247

184248
//Download the ini file
185249
ipcRenderer.send("download", {
186250
url: DLurl,
187251
properties: {directory: "downloads"}
188252
});
253+
}
254+
255+
//Installing the Windows drivers
256+
function installDrivers()
257+
{
258+
ipcRenderer.send("installWinDrivers", {
259+
});
189260

190261
}
191262

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

332403
refreshAvailableFirmwares();
404+
refreshBasetunes();
333405
refreshSerialPorts();
334406
checkForUpdates();
335407

0 commit comments

Comments
 (0)