Skip to content

Commit 57ad5f4

Browse files
author
Akos Kitta
committed
fix: show board info based on the selected port
include serial number of board if available Closes #1489 Closes #1435 Signed-off-by: Akos Kitta <[email protected]>
1 parent 76f9f63 commit 57ad5f4

File tree

2 files changed

+79
-16
lines changed

2 files changed

+79
-16
lines changed

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

+77-16
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ 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 { BoardsServiceProvider } from '../boards/boards-service-provider';
12+
import {
13+
AvailableBoard,
14+
BoardsServiceProvider,
15+
} from '../boards/boards-service-provider';
1316
import {
1417
ArduinoMenus,
1518
PlaceholderMenuNode,
@@ -79,22 +82,80 @@ export class BoardSelection extends SketchContribution {
7982
);
8083
return;
8184
}
82-
const boardDetails = await this.boardsService.getBoardDetails({
83-
fqbn: selectedBoard.fqbn,
84-
});
85-
if (boardDetails) {
86-
const { VID, PID } = boardDetails;
87-
const detail = `BN: ${selectedBoard.name}
88-
VID: ${VID}
89-
PID: ${PID}`;
90-
await remote.dialog.showMessageBox(remote.getCurrentWindow(), {
91-
message: nls.localize('arduino/board/boardInfo', 'Board Info'),
92-
title: nls.localize('arduino/board/boardInfo', 'Board Info'),
93-
type: 'info',
94-
detail,
95-
buttons: [nls.localize('vscode/issueMainService/ok', 'OK')],
96-
});
85+
// IDE2 must show the board info based on the selected port.
86+
// https://github.com/arduino/arduino-ide/issues/1489
87+
88+
// IDE 1.x does not support network ports
89+
if (selectedPort.protocol === 'network') {
90+
this.messageService.info(
91+
nls.localize(
92+
'arduino/board/noNetworkPort',
93+
"Network port, can't obtain info."
94+
)
95+
);
96+
return;
97+
}
98+
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+
109+
const state = await this.boardsService.getState();
110+
const boardListOnSelectedPort = Object.entries(state).filter(
111+
([portKey, [, boards]]) =>
112+
portKey === selectedPortKey && boards.length
113+
);
114+
// IDE 1.x show this when cannot identify for example a ESP8266MOD although compile and upload works
115+
if (!boardListOnSelectedPort.length) {
116+
this.messageService.info(
117+
nls.localize(
118+
'arduino/board/noNativeSerialPort',
119+
"Native serial port, can't obtain info."
120+
)
121+
);
122+
return;
97123
}
124+
125+
const [, [port, boards]] = boardListOnSelectedPort[0];
126+
boardListOnSelectedPort.length && boardListOnSelectedPort[0];
127+
if (boardListOnSelectedPort.length > 1 || boards.length > 1) {
128+
console.warn(
129+
`Detected more than one available boards on the selected port : ${JSON.stringify(
130+
selectedPort
131+
)}. Detected boards were: ${JSON.stringify(
132+
boardListOnSelectedPort
133+
)}. Using the first one: ${JSON.stringify([port, boards])}`
134+
);
135+
}
136+
137+
const board = boards[0];
138+
const falsyToNullString = (s: string | undefined) =>
139+
!!s ? s : '(null)';
140+
const readProperty = (property: string, port: Port) =>
141+
falsyToNullString(port.properties?.[property]);
142+
const BN = board.name;
143+
const VID = readProperty('vid', port);
144+
const PID = readProperty('pid', port);
145+
const SN = readProperty('serialNumber', port);
146+
const detail = `
147+
BN: ${BN}
148+
VID: ${VID}
149+
PID: ${PID}
150+
SN: ${SN}
151+
`.trim();
152+
await remote.dialog.showMessageBox(remote.getCurrentWindow(), {
153+
message: nls.localize('arduino/board/boardInfo', 'Board Info'),
154+
title: nls.localize('arduino/board/boardInfo', 'Board Info'),
155+
type: 'info',
156+
detail,
157+
buttons: [nls.localize('vscode/issueMainService/ok', 'OK')],
158+
});
98159
},
99160
});
100161
}

Diff for: i18n/en.json

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
"installNow": "The \"{0} {1}\" core has to be installed for the currently selected \"{2}\" board. Do you want to install it now?",
1919
"noBoardsFound": "No boards found for \"{0}\"",
2020
"noFQBN": "The FQBN is not available for the selected board \"{0}\". Do you have the corresponding core installed?",
21+
"noNativeSerialPort": "Native serial port, can't obtain info.",
22+
"noNetworkPort": "Network port, can't obtain info.",
2123
"noPortsDiscovered": "No ports discovered",
2224
"noPortsSelected": "No ports selected for board: '{0}'.",
2325
"noneSelected": "No boards selected.",

0 commit comments

Comments
 (0)