@@ -12,6 +12,7 @@ import {
12
12
BoardsPackage ,
13
13
AttachedBoardsChangeEvent ,
14
14
BoardWithPackage ,
15
+ BoardUserField ,
15
16
} from '../../common/protocol' ;
16
17
import { BoardsConfig } from './boards-config' ;
17
18
import { naturalCompare } from '../../common/utils' ;
@@ -68,7 +69,8 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
68
69
* This event is also emitted when the board package for the currently selected board was uninstalled.
69
70
*/
70
71
readonly onBoardsConfigChanged = this . onBoardsConfigChangedEmitter . event ;
71
- readonly onAvailableBoardsChanged = this . onAvailableBoardsChangedEmitter . event ;
72
+ readonly onAvailableBoardsChanged =
73
+ this . onAvailableBoardsChangedEmitter . event ;
72
74
readonly onAvailablePortsChanged = this . onAvailablePortsChangedEmitter . event ;
73
75
74
76
onStart ( ) : void {
@@ -183,8 +185,8 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
183
185
const selectedAvailableBoard = AvailableBoard . is ( selectedBoard )
184
186
? selectedBoard
185
187
: this . _availableBoards . find ( ( availableBoard ) =>
186
- Board . sameAs ( availableBoard , selectedBoard )
187
- ) ;
188
+ Board . sameAs ( availableBoard , selectedBoard )
189
+ ) ;
188
190
if (
189
191
selectedAvailableBoard &&
190
192
selectedAvailableBoard . selected &&
@@ -274,6 +276,18 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
274
276
return boards ;
275
277
}
276
278
279
+ async selectedBoardUserFields ( ) : Promise < BoardUserField [ ] > {
280
+ if ( ! this . _boardsConfig . selectedBoard || ! this . _boardsConfig . selectedPort ) {
281
+ return [ ] ;
282
+ }
283
+ const fqbn = this . _boardsConfig . selectedBoard . fqbn ;
284
+ if ( ! fqbn ) {
285
+ return [ ] ;
286
+ }
287
+ const protocol = this . _boardsConfig . selectedPort . protocol ;
288
+ return await this . boardsService . getBoardUserFields ( { fqbn, protocol } ) ;
289
+ }
290
+
277
291
/**
278
292
* `true` if the `config.selectedBoard` is defined; hence can compile against the board. Otherwise, `false`.
279
293
*/
@@ -361,14 +375,14 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
361
375
const timeoutTask =
362
376
! ! timeout && timeout > 0
363
377
? new Promise < void > ( ( _ , reject ) =>
364
- setTimeout (
365
- ( ) => reject ( new Error ( `Timeout after ${ timeout } ms.` ) ) ,
366
- timeout
378
+ setTimeout (
379
+ ( ) => reject ( new Error ( `Timeout after ${ timeout } ms.` ) ) ,
380
+ timeout
381
+ )
367
382
)
368
- )
369
383
: new Promise < void > ( ( ) => {
370
- /* never */
371
- } ) ;
384
+ /* never */
385
+ } ) ;
372
386
const waitUntilTask = new Promise < void > ( ( resolve ) => {
373
387
let candidate = find ( what , this . availableBoards ) ;
374
388
if ( candidate ) {
@@ -406,7 +420,7 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
406
420
const availableBoards : AvailableBoard [ ] = [ ] ;
407
421
const attachedBoards = this . _attachedBoards . filter ( ( { port } ) => ! ! port ) ;
408
422
const availableBoardPorts = availablePorts . filter ( ( port ) => {
409
- if ( port . protocol === " serial" ) {
423
+ if ( port . protocol === ' serial' ) {
410
424
// We always show all serial ports, even if there
411
425
// is no recognized board connected to it
412
426
return true ;
@@ -424,8 +438,12 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
424
438
} ) ;
425
439
426
440
for ( const boardPort of availableBoardPorts ) {
427
- let board = attachedBoards . find ( ( { port } ) => Port . sameAs ( boardPort , port ) ) ;
428
- const lastSelectedBoard = await this . getLastSelectedBoardOnPort ( boardPort ) ;
441
+ const board = attachedBoards . find ( ( { port } ) =>
442
+ Port . sameAs ( boardPort , port )
443
+ ) ;
444
+ const lastSelectedBoard = await this . getLastSelectedBoardOnPort (
445
+ boardPort
446
+ ) ;
429
447
430
448
let availableBoard = { } as AvailableBoard ;
431
449
if ( board ) {
@@ -454,11 +472,16 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
454
472
availableBoards . push ( availableBoard ) ;
455
473
}
456
474
457
- if ( boardsConfig . selectedBoard && ! availableBoards . some ( ( { selected } ) => selected ) ) {
475
+ if (
476
+ boardsConfig . selectedBoard &&
477
+ ! availableBoards . some ( ( { selected } ) => selected )
478
+ ) {
458
479
// If the selected board has the same port of an unknown board
459
480
// that is already in availableBoards we might get a duplicate port.
460
481
// So we remove the one already in the array and add the selected one.
461
- const found = availableBoards . findIndex ( board => board . port ?. address === boardsConfig . selectedPort ?. address ) ;
482
+ const found = availableBoards . findIndex (
483
+ ( board ) => board . port ?. address === boardsConfig . selectedPort ?. address
484
+ ) ;
462
485
if ( found >= 0 ) {
463
486
availableBoards . splice ( found , 1 ) ;
464
487
}
@@ -475,15 +498,19 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
475
498
let hasChanged = availableBoards . length !== currentAvailableBoards . length ;
476
499
for ( let i = 0 ; ! hasChanged && i < availableBoards . length ; i ++ ) {
477
500
const [ left , right ] = [ availableBoards [ i ] , currentAvailableBoards [ i ] ] ;
478
- hasChanged = ! ! AvailableBoard . compare ( left , right ) || left . selected !== right . selected ;
501
+ hasChanged =
502
+ ! ! AvailableBoard . compare ( left , right ) ||
503
+ left . selected !== right . selected ;
479
504
}
480
505
if ( hasChanged ) {
481
506
this . _availableBoards = availableBoards ;
482
507
this . onAvailableBoardsChangedEmitter . fire ( this . _availableBoards ) ;
483
508
}
484
509
}
485
510
486
- protected async getLastSelectedBoardOnPort ( port : Port ) : Promise < Board | undefined > {
511
+ protected async getLastSelectedBoardOnPort (
512
+ port : Port
513
+ ) : Promise < Board | undefined > {
487
514
const key = this . getLastSelectedBoardOnPortKey ( port ) ;
488
515
return this . getData < Board > ( key ) ;
489
516
}
@@ -504,8 +531,11 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
504
531
] ) ;
505
532
}
506
533
507
- protected getLastSelectedBoardOnPortKey ( port : Port ) : string {
508
- return `last-selected-board-on-port:${ Port . toString ( port ) } ` ;
534
+ protected getLastSelectedBoardOnPortKey ( port : Port | string ) : string {
535
+ // TODO: we lose the port's `protocol` info (`serial`, `network`, etc.) here if the `port` is a `string`.
536
+ return `last-selected-board-on-port:${
537
+ typeof port === 'string' ? port : Port . toString ( port )
538
+ } `;
509
539
}
510
540
511
541
protected async loadState ( ) : Promise < void > {
@@ -596,13 +626,22 @@ export namespace AvailableBoard {
596
626
// 4. Network with recognized boards
597
627
// 5. Other protocols with recognized boards
598
628
export const compare = ( left : AvailableBoard , right : AvailableBoard ) => {
599
- if ( left . port ?. protocol === " serial" && right . port ?. protocol !== " serial" ) {
629
+ if ( left . port ?. protocol === ' serial' && right . port ?. protocol !== ' serial' ) {
600
630
return - 1 ;
601
- } else if ( left . port ?. protocol !== "serial" && right . port ?. protocol === "serial" ) {
631
+ } else if (
632
+ left . port ?. protocol !== 'serial' &&
633
+ right . port ?. protocol === 'serial'
634
+ ) {
602
635
return 1 ;
603
- } else if ( left . port ?. protocol === "network" && right . port ?. protocol !== "network" ) {
636
+ } else if (
637
+ left . port ?. protocol === 'network' &&
638
+ right . port ?. protocol !== 'network'
639
+ ) {
604
640
return - 1 ;
605
- } else if ( left . port ?. protocol !== "network" && right . port ?. protocol === "network" ) {
641
+ } else if (
642
+ left . port ?. protocol !== 'network' &&
643
+ right . port ?. protocol === 'network'
644
+ ) {
606
645
return 1 ;
607
646
} else if ( left . port ?. protocol === right . port ?. protocol ) {
608
647
// We show all ports, including those that have guessed
@@ -614,5 +653,5 @@ export namespace AvailableBoard {
614
653
}
615
654
}
616
655
return naturalCompare ( left . port ?. address ! , right . port ?. address ! ) ;
617
- }
656
+ } ;
618
657
}
0 commit comments