@@ -3,6 +3,8 @@ const {ipcRenderer} = require("electron")
3
3
const { remote} = require ( 'electron' )
4
4
const { shell } = require ( 'electron' )
5
5
6
+ var basetuneList = [ ] ;
7
+
6
8
function refreshSerialPorts ( )
7
9
{
8
10
serialport . list ( ( err , ports ) => {
@@ -87,8 +89,10 @@ function refreshAvailableFirmwares()
87
89
//Disable the buttons. These are only re-enabled if the retrieve is successful
88
90
var DetailsButton = document . getElementById ( "btnDetails" ) ;
89
91
var ChoosePortButton = document . getElementById ( "btnChoosePort" ) ;
92
+ var basetuneButton = document . getElementById ( "btnBasetune" ) ;
90
93
DetailsButton . disabled = true ;
91
94
ChoosePortButton . disabled = true ;
95
+ basetuneButton . disabled = true ;
92
96
93
97
var request = require ( 'request' ) ;
94
98
request . get ( 'http://speeduino.com/fw/versions' , { timeout : 10000 } , function ( error , response , body )
@@ -107,10 +111,12 @@ function refreshAvailableFirmwares()
107
111
select . appendChild ( newOption ) ;
108
112
}
109
113
select . selectedIndex = 0 ;
114
+ refreshBasetunes ( ) ;
110
115
111
116
//Re-enable the buttons
112
117
DetailsButton . disabled = false ;
113
118
ChoosePortButton . disabled = false ;
119
+ basetuneButton . disabled = false ;
114
120
}
115
121
else if ( error )
116
122
{
@@ -136,6 +142,71 @@ function refreshAvailableFirmwares()
136
142
) ;
137
143
}
138
144
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
+
139
210
function downloadHex ( )
140
211
{
141
212
@@ -155,7 +226,7 @@ function downloadIni()
155
226
{
156
227
157
228
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" ;
159
230
console . log ( "Downloading: " + DLurl ) ;
160
231
161
232
//Download the ini file
@@ -166,26 +237,26 @@ function downloadIni()
166
237
167
238
}
168
239
169
- //Installing the Windows drivers
170
- function installDrivers ( )
240
+ function downloadBasetune ( )
171
241
{
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 ;
182
246
console . log ( "Downloading: " + DLurl ) ;
183
247
184
248
//Download the ini file
185
249
ipcRenderer . send ( "download" , {
186
250
url : DLurl ,
187
251
properties : { directory : "downloads" }
188
252
} ) ;
253
+ }
254
+
255
+ //Installing the Windows drivers
256
+ function installDrivers ( )
257
+ {
258
+ ipcRenderer . send ( "installWinDrivers" , {
259
+ } ) ;
189
260
190
261
}
191
262
@@ -330,6 +401,7 @@ window.onload = function () {
330
401
document . getElementById ( 'title' ) . innerHTML = "Speeduino Universal Firmware Loader (v" + remote . app . getVersion ( ) + ")"
331
402
332
403
refreshAvailableFirmwares ( ) ;
404
+ refreshBasetunes ( ) ;
333
405
refreshSerialPorts ( ) ;
334
406
checkForUpdates ( ) ;
335
407
0 commit comments