Skip to content

Commit

Permalink
fix: unidentified vs. native port handling
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Akos Kitta committed Jan 9, 2023
1 parent 57ad5f4 commit 43283ba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
41 changes: 21 additions & 20 deletions arduino-ide-extension/src/browser/contributions/board-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import { BoardsConfig } from '../boards/boards-config';
import { MainMenuManager } from '../../common/main-menu-manager';
import { BoardsListWidget } from '../boards/boards-list-widget';
import { NotificationCenter } from '../notification-center';
import {
AvailableBoard,
BoardsServiceProvider,
} from '../boards/boards-service-provider';
import { BoardsServiceProvider } from '../boards/boards-service-provider';
import {
ArduinoMenus,
PlaceholderMenuNode,
Expand All @@ -23,6 +20,7 @@ import {
InstalledBoardWithPackage,
AvailablePorts,
Port,
Board,
} from '../../common/protocol';
import { SketchContribution, Command, CommandRegistry } from './contribution';
import { nls } from '@theia/core/lib/common';
Expand Down Expand Up @@ -84,7 +82,6 @@ export class BoardSelection extends SketchContribution {
}
// IDE2 must show the board info based on the selected port.
// https://github.com/arduino/arduino-ide/issues/1489

// IDE 1.x does not support network ports
if (selectedPort.protocol === 'network') {
this.messageService.info(
Expand All @@ -95,21 +92,19 @@ export class BoardSelection extends SketchContribution {
);
return;
}
// serial protocol with one or many detected boards or available VID+PID properties from the port
const isNonNativeSerial = (port: Port, boards: Board[]) => {
return (
port.protocol === 'serial' &&
(boards.length ||
(port.properties?.['vid'] && port.properties?.['pid']))
);
};
const selectedPortKey = Port.keyOf(selectedPort);
console.log('selectedportkey', JSON.stringify(selectedPortKey));
console.log(
'availableboards',
JSON.stringify(
this.boardsServiceProvider.availableBoards.filter(
AvailableBoard.hasPort
)
)
);

const state = await this.boardsService.getState();
const boardListOnSelectedPort = Object.entries(state).filter(
([portKey, [, boards]]) =>
portKey === selectedPortKey && boards.length
([portKey, [port, boards]]) =>
portKey === selectedPortKey && isNonNativeSerial(port, boards)
);
// IDE 1.x show this when cannot identify for example a ESP8266MOD although compile and upload works
if (!boardListOnSelectedPort.length) {
Expand All @@ -123,7 +118,6 @@ export class BoardSelection extends SketchContribution {
}

const [, [port, boards]] = boardListOnSelectedPort[0];
boardListOnSelectedPort.length && boardListOnSelectedPort[0];
if (boardListOnSelectedPort.length > 1 || boards.length > 1) {
console.warn(
`Detected more than one available boards on the selected port : ${JSON.stringify(
Expand All @@ -139,10 +133,17 @@ export class BoardSelection extends SketchContribution {
!!s ? s : '(null)';
const readProperty = (property: string, port: Port) =>
falsyToNullString(port.properties?.[property]);
const BN = board.name;
const BN =
board?.name ??
nls.localize('arduino/board/unknownBoard', 'Unknown board');
const VID = readProperty('vid', port);
const PID = readProperty('pid', port);
const SN = readProperty('serialNumber', port);
const SN = board
? readProperty('serialNumber', port)
: nls.localize(
'arduino/board/unknownBoardSerialNumber',
'Upload any sketch to obtain it.'
);
const detail = `
BN: ${BN}
VID: ${VID}
Expand Down
4 changes: 3 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
"showAllPorts": "Show all ports",
"succesfullyInstalledPlatform": "Successfully installed platform {0}:{1}",
"succesfullyUninstalledPlatform": "Successfully uninstalled platform {0}:{1}",
"typeOfPorts": "{0} ports"
"typeOfPorts": "{0} ports",
"unknownBoard": "Unknown board",
"unknownBoardSerialNumber": "Upload any sketch to obtain it."
},
"boardsManager": "Boards Manager",
"boardsType": {
Expand Down

0 comments on commit 43283ba

Please sign in to comment.