@@ -158,15 +158,9 @@ export class BoardsServiceProvider
158
158
this . lastAvailablePortsOnUpload = undefined ;
159
159
}
160
160
161
- private portToAutoSelectCanBeDerived ( ) : boolean {
162
- return Boolean (
163
- this . lastBoardsConfigOnUpload && this . lastAvailablePortsOnUpload
164
- ) ;
165
- }
166
-
167
161
attemptPostUploadAutoSelect ( ) : void {
168
162
setTimeout ( ( ) => {
169
- if ( this . portToAutoSelectCanBeDerived ( ) ) {
163
+ if ( this . lastBoardsConfigOnUpload && this . lastAvailablePortsOnUpload ) {
170
164
this . attemptAutoSelect ( {
171
165
ports : this . _availablePorts ,
172
166
boards : this . _availableBoards ,
@@ -185,12 +179,12 @@ export class BoardsServiceProvider
185
179
private deriveBoardConfigToAutoSelect (
186
180
newState : AttachedBoardsChangeEvent [ 'newState' ]
187
181
) : void {
188
- if ( ! this . portToAutoSelectCanBeDerived ( ) ) {
182
+ if ( ! this . lastBoardsConfigOnUpload || ! this . lastAvailablePortsOnUpload ) {
189
183
this . boardConfigToAutoSelect = undefined ;
190
184
return ;
191
185
}
192
186
193
- const oldPorts = this . lastAvailablePortsOnUpload ! ;
187
+ const oldPorts = this . lastAvailablePortsOnUpload ;
194
188
const { ports : newPorts , boards : newBoards } = newState ;
195
189
196
190
const appearedPorts =
@@ -205,20 +199,36 @@ export class BoardsServiceProvider
205
199
Port . sameAs ( board . port , port )
206
200
) ;
207
201
208
- const lastBoardsConfigOnUpload = this . lastBoardsConfigOnUpload ! ;
202
+ const lastBoardsConfigOnUpload = this . lastBoardsConfigOnUpload ;
209
203
210
- if (
211
- boardOnAppearedPort &&
212
- lastBoardsConfigOnUpload . selectedBoard &&
213
- Board . sameAs (
204
+ if ( boardOnAppearedPort && lastBoardsConfigOnUpload . selectedBoard ) {
205
+ const boardIsSameHardware = Board . sameDistinctHardwareAs (
214
206
boardOnAppearedPort ,
215
207
lastBoardsConfigOnUpload . selectedBoard
216
- )
217
- ) {
208
+ ) ;
209
+
210
+ const boardIsSameFqbn = Board . sameAs (
211
+ boardOnAppearedPort ,
212
+ lastBoardsConfigOnUpload . selectedBoard
213
+ ) ;
214
+
215
+ if ( ! boardIsSameHardware && ! boardIsSameFqbn ) return ;
216
+
217
+ let boardToAutoSelect = boardOnAppearedPort ;
218
+ if ( boardIsSameHardware && ! boardIsSameFqbn ) {
219
+ const { name, fqbn } = lastBoardsConfigOnUpload . selectedBoard ;
220
+
221
+ boardToAutoSelect = {
222
+ ...boardToAutoSelect ,
223
+ name,
224
+ fqbn,
225
+ } ;
226
+ }
227
+
218
228
this . clearBoardDiscoverySnapshot ( ) ;
219
229
220
230
this . boardConfigToAutoSelect = {
221
- selectedBoard : boardOnAppearedPort ,
231
+ selectedBoard : boardToAutoSelect ,
222
232
selectedPort : port ,
223
233
} ;
224
234
return ;
@@ -326,8 +336,10 @@ export class BoardsServiceProvider
326
336
// it is just a FQBN, so we need to find the `selected` board among the `AvailableBoards`
327
337
const selectedAvailableBoard = AvailableBoard . is ( selectedBoard )
328
338
? selectedBoard
329
- : this . _availableBoards . find ( ( availableBoard ) =>
330
- Board . sameAs ( availableBoard , selectedBoard )
339
+ : this . _availableBoards . find (
340
+ ( availableBoard ) =>
341
+ Board . sameDistinctHardwareAs ( availableBoard , selectedBoard ) ||
342
+ Board . sameAs ( availableBoard , selectedBoard )
331
343
) ;
332
344
if (
333
345
selectedAvailableBoard &&
@@ -353,24 +365,33 @@ export class BoardsServiceProvider
353
365
354
366
protected tryReconnect ( ) : boolean {
355
367
if ( this . latestValidBoardsConfig && ! this . canUploadTo ( this . boardsConfig ) ) {
368
+ // ** Reconnect to a board unplugged from, and plugged back into the same port
356
369
for ( const board of this . availableBoards . filter (
357
370
( { state } ) => state !== AvailableBoard . State . incomplete
358
371
) ) {
359
372
if (
360
- this . latestValidBoardsConfig . selectedBoard . fqbn === board . fqbn &&
361
- this . latestValidBoardsConfig . selectedBoard . name === board . name &&
373
+ ( Board . sameDistinctHardwareAs (
374
+ this . latestValidBoardsConfig . selectedBoard ,
375
+ board
376
+ ) ||
377
+ ( this . latestValidBoardsConfig . selectedBoard . fqbn === board . fqbn &&
378
+ this . latestValidBoardsConfig . selectedBoard . name ===
379
+ board . name ) ) &&
362
380
Port . sameAs ( this . latestValidBoardsConfig . selectedPort , board . port )
363
381
) {
364
382
this . boardsConfig = this . latestValidBoardsConfig ;
365
383
return true ;
366
384
}
367
385
}
386
+ // **
368
387
388
+ // ** Reconnect to a board whose port changed due to an upload
369
389
if ( ! this . boardConfigToAutoSelect ) return false ;
370
390
371
391
this . boardsConfig = this . boardConfigToAutoSelect ;
372
392
this . boardConfigToAutoSelect = undefined ;
373
393
return true ;
394
+ // **
374
395
}
375
396
return false ;
376
397
}
0 commit comments