Skip to content

Commit 43283ba

Browse files
author
Akos Kitta
committed
fix: unidentified vs. native port handling
a port is considered to be non-native serial if `protocol` is `'serial'` and the port has either at least one detected board or the VID+PID from the port properties. Signed-off-by: Akos Kitta <[email protected]>
1 parent 57ad5f4 commit 43283ba

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

arduino-ide-extension/src/browser/contributions/board-selection.ts

+21-20
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import { BoardsConfig } from '../boards/boards-config';
99
import { MainMenuManager } from '../../common/main-menu-manager';
1010
import { BoardsListWidget } from '../boards/boards-list-widget';
1111
import { NotificationCenter } from '../notification-center';
12-
import {
13-
AvailableBoard,
14-
BoardsServiceProvider,
15-
} from '../boards/boards-service-provider';
12+
import { BoardsServiceProvider } from '../boards/boards-service-provider';
1613
import {
1714
ArduinoMenus,
1815
PlaceholderMenuNode,
@@ -23,6 +20,7 @@ import {
2320
InstalledBoardWithPackage,
2421
AvailablePorts,
2522
Port,
23+
Board,
2624
} from '../../common/protocol';
2725
import { SketchContribution, Command, CommandRegistry } from './contribution';
2826
import { nls } from '@theia/core/lib/common';
@@ -84,7 +82,6 @@ export class BoardSelection extends SketchContribution {
8482
}
8583
// IDE2 must show the board info based on the selected port.
8684
// https://github.com/arduino/arduino-ide/issues/1489
87-
8885
// IDE 1.x does not support network ports
8986
if (selectedPort.protocol === 'network') {
9087
this.messageService.info(
@@ -95,21 +92,19 @@ export class BoardSelection extends SketchContribution {
9592
);
9693
return;
9794
}
95+
// serial protocol with one or many detected boards or available VID+PID properties from the port
96+
const isNonNativeSerial = (port: Port, boards: Board[]) => {
97+
return (
98+
port.protocol === 'serial' &&
99+
(boards.length ||
100+
(port.properties?.['vid'] && port.properties?.['pid']))
101+
);
102+
};
98103
const selectedPortKey = Port.keyOf(selectedPort);
99-
console.log('selectedportkey', JSON.stringify(selectedPortKey));
100-
console.log(
101-
'availableboards',
102-
JSON.stringify(
103-
this.boardsServiceProvider.availableBoards.filter(
104-
AvailableBoard.hasPort
105-
)
106-
)
107-
);
108-
109104
const state = await this.boardsService.getState();
110105
const boardListOnSelectedPort = Object.entries(state).filter(
111-
([portKey, [, boards]]) =>
112-
portKey === selectedPortKey && boards.length
106+
([portKey, [port, boards]]) =>
107+
portKey === selectedPortKey && isNonNativeSerial(port, boards)
113108
);
114109
// IDE 1.x show this when cannot identify for example a ESP8266MOD although compile and upload works
115110
if (!boardListOnSelectedPort.length) {
@@ -123,7 +118,6 @@ export class BoardSelection extends SketchContribution {
123118
}
124119

125120
const [, [port, boards]] = boardListOnSelectedPort[0];
126-
boardListOnSelectedPort.length && boardListOnSelectedPort[0];
127121
if (boardListOnSelectedPort.length > 1 || boards.length > 1) {
128122
console.warn(
129123
`Detected more than one available boards on the selected port : ${JSON.stringify(
@@ -139,10 +133,17 @@ export class BoardSelection extends SketchContribution {
139133
!!s ? s : '(null)';
140134
const readProperty = (property: string, port: Port) =>
141135
falsyToNullString(port.properties?.[property]);
142-
const BN = board.name;
136+
const BN =
137+
board?.name ??
138+
nls.localize('arduino/board/unknownBoard', 'Unknown board');
143139
const VID = readProperty('vid', port);
144140
const PID = readProperty('pid', port);
145-
const SN = readProperty('serialNumber', port);
141+
const SN = board
142+
? readProperty('serialNumber', port)
143+
: nls.localize(
144+
'arduino/board/unknownBoardSerialNumber',
145+
'Upload any sketch to obtain it.'
146+
);
146147
const detail = `
147148
BN: ${BN}
148149
VID: ${VID}

i18n/en.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
"showAllPorts": "Show all ports",
4040
"succesfullyInstalledPlatform": "Successfully installed platform {0}:{1}",
4141
"succesfullyUninstalledPlatform": "Successfully uninstalled platform {0}:{1}",
42-
"typeOfPorts": "{0} ports"
42+
"typeOfPorts": "{0} ports",
43+
"unknownBoard": "Unknown board",
44+
"unknownBoardSerialNumber": "Upload any sketch to obtain it."
4345
},
4446
"boardsManager": "Boards Manager",
4547
"boardsType": {

0 commit comments

Comments
 (0)