@@ -60,6 +60,7 @@ $(document).ready(function () {
6060 if ( deviceRestoreInfo . versionsZipByPlatform [ tempPlatformObj . name ] ) {
6161 result = Object . assign ( { } , tempPlatformObj ) ;
6262 result . versionArray = deviceRestoreInfo . versionsZipByPlatform [ tempPlatformObj . name ] ;
63+ result . isTracker = ( result . id == 26 ) ;
6364 break ;
6465 }
6566 }
@@ -78,6 +79,8 @@ $(document).ready(function () {
7879 const restoreElem = $ ( thisPartial ) . find ( '.apiHelperUsbRestoreDeviceRestore' ) ;
7980 const progressElem = $ ( thisPartial ) . find ( '.apiHelperUsbRestoreDeviceProgressTr' ) ;
8081 const modeSelectElem = $ ( thisPartial ) . find ( '.apiHelperUsbRestoreDeviceModeSelect' ) ;
82+ const tinkerOptionElem = $ ( modeSelectElem ) . find ( 'option[value="tinker"]' ) ;
83+
8184
8285 // Tabs
8386 const versionTrElem = $ ( thisPartial ) . find ( '.apiHelperUsbRestoreDeviceVersionTr' ) ;
@@ -88,6 +91,10 @@ $(document).ready(function () {
8891 const setupBitTrElem = $ ( thisPartial ) . find ( '.apiHelperUsbRestoreSetupBitTr' ) ;
8992 const setupBitSelectElem = $ ( thisPartial ) . find ( '.apiHelperUsbRestoreDeviceSetupBit' ) ;
9093
94+ // Update NCP
95+ const updateNcpTrElem = $ ( thisPartial ) . find ( '.apiHelperUsbRestoreUpdateNcpTr' ) ;
96+ const updateNcpCheckboxElem = $ ( thisPartial ) . find ( '.updateNcpCheckbox' ) ;
97+
9198 const setStatus = function ( str ) {
9299 $ ( thisPartial ) . find ( '.apiHelperUsbRestoreDeviceStatus' ) . html ( str ) ;
93100 }
@@ -111,6 +118,8 @@ $(document).ready(function () {
111118 $ ( versionElem ) . prop ( 'disabled' , true ) ;
112119 $ ( restoreElem ) . prop ( 'disabled' , true ) ;
113120 $ ( setupBitTrElem ) . hide ( ) ;
121+ $ ( updateNcpTrElem ) . hide ( ) ;
122+ $ ( tinkerOptionElem ) . text ( 'Tinker (Factory Default)' ) ;
114123 } ;
115124
116125 const checkRestoreButtonEnable = function ( ) {
@@ -262,7 +271,15 @@ $(document).ready(function () {
262271 if ( platformVersionInfo . gen == 3 ) {
263272 $ ( setupBitTrElem ) . show ( ) ;
264273 }
265-
274+ if ( platformVersionInfo . isTracker ) {
275+ $ ( updateNcpTrElem ) . show ( ) ;
276+
277+ $ ( tinkerOptionElem ) . text ( 'Tracker Edge (Factory Default)' ) ;
278+ }
279+ else {
280+ $ ( tinkerOptionElem ) . text ( 'Tinker (Factory Default)' ) ;
281+ }
282+
266283 $ ( versionElem ) . prop ( 'disabled' , false ) ;
267284 checkRestoreButtonEnable ( ) ;
268285 }
@@ -274,12 +291,11 @@ $(document).ready(function () {
274291 } ) ) ;
275292
276293 if ( $ ( restoreElem ) . on ( 'click' , async function ( ) {
277- let options = {
294+ let baseOptions = {
278295 eventCategory,
279296 platformVersionInfo,
280297 setStatus,
281298 version : $ ( versionElem ) . val ( ) ,
282- setupBit : $ ( setupBitSelectElem ) . val ( ) ,
283299 progressUpdate : function ( msg , pct ) {
284300 $ ( progressElem ) . find ( 'td > span' ) . text ( msg ) ;
285301 $ ( progressElem ) . find ( 'td > progress' ) . val ( pct ) ;
@@ -293,6 +309,10 @@ $(document).ready(function () {
293309 }
294310 }
295311 } ;
312+ let options = Object . assign ( { } , baseOptions ) ;
313+
314+ options . setupBit = $ ( setupBitSelectElem ) . val ( ) ;
315+
296316 if ( userFirmwareBinary ) {
297317 options . userFirmwareBinary = userFirmwareBinary ;
298318 }
@@ -319,10 +339,61 @@ $(document).ready(function () {
319339 $ ( selectElem ) . prop ( 'disabled' , true ) ;
320340 $ ( versionElem ) . prop ( 'disabled' , true ) ;
321341
322- const restoreResult = dfuDeviceRestore ( usbDevice , options ) ;
342+ const deviceId = usbDevice . id ;
343+
344+ let restoreResult = await dfuDeviceRestore ( usbDevice , options ) ;
345+
346+ if ( platformVersionInfo . isTracker && $ ( updateNcpCheckboxElem ) . prop ( 'checked' ) ) {
347+ // Update Tracker NCP
348+ let ncpOptions = Object . assign ( { } , baseOptions ) ;
349+ ncpOptions . ncpUpdate = true ;
350+
351+ nativeUsbDevice = null ;
352+
353+ setStatus ( 'Waiting for updates to be applied...' ) ;
354+ await new Promise ( function ( resolve , reject ) {
355+ setTimeout ( function ( ) {
356+ resolve ( ) ;
357+ } , 10000 ) ;
358+ } ) ;
359+
360+ for ( let tries = 1 ; tries <= 8 ; tries ++ ) {
361+ setStatus ( 'Attempting to reconnect to the device...' ) ;
362+ const nativeUsbDevices = await navigator . usb . getDevices ( )
363+
364+ if ( nativeUsbDevices . length > 0 ) {
365+ for ( let dev of nativeUsbDevices ) {
366+ if ( dev . serialNumber == deviceId ) {
367+ nativeUsbDevice = dev ;
368+ break ;
369+ }
370+ }
371+ }
372+ await new Promise ( function ( resolve , reject ) {
373+ setTimeout ( function ( ) {
374+ resolve ( ) ;
375+ } , 1000 ) ;
376+ } ) ;
377+ }
378+
379+ if ( nativeUsbDevice ) {
380+ setStatus ( 'Updating NCP...' ) ;
381+
382+ usbDevice = await ParticleUsb . openDeviceById ( nativeUsbDevice , { } ) ;
383+
384+ restoreResult = await dfuDeviceRestore ( usbDevice , ncpOptions ) ;
385+ }
386+ else {
387+ setStatus ( 'Failed to reconnect to device to update NCP' ) ;
388+ }
389+ }
323390
324391 resetRestorePanel ( ) ;
325392
393+ setTimeout ( function ( ) {
394+ setStatus ( '' ) ;
395+ } , 2000 ) ;
396+
326397 if ( options . downloadUrl ) {
327398 if ( $ ( modeSelectElem ) . val ( ) == 'url' ) {
328399 history . pushState ( null , '' , '?url=' + encodeURIComponent ( downloadUrl ) ) ;
0 commit comments