mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-06-15 00:26:33 +00:00
Enhance board config auto-selection with hardwareId (#1913)
This commit is contained in:
parent
fe19e0ef26
commit
43b5d4e22f
@ -158,15 +158,9 @@ export class BoardsServiceProvider
|
|||||||
this.lastAvailablePortsOnUpload = undefined;
|
this.lastAvailablePortsOnUpload = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
private portToAutoSelectCanBeDerived(): boolean {
|
|
||||||
return Boolean(
|
|
||||||
this.lastBoardsConfigOnUpload && this.lastAvailablePortsOnUpload
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
attemptPostUploadAutoSelect(): void {
|
attemptPostUploadAutoSelect(): void {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (this.portToAutoSelectCanBeDerived()) {
|
if (this.lastBoardsConfigOnUpload && this.lastAvailablePortsOnUpload) {
|
||||||
this.attemptAutoSelect({
|
this.attemptAutoSelect({
|
||||||
ports: this._availablePorts,
|
ports: this._availablePorts,
|
||||||
boards: this._availableBoards,
|
boards: this._availableBoards,
|
||||||
@ -185,12 +179,12 @@ export class BoardsServiceProvider
|
|||||||
private deriveBoardConfigToAutoSelect(
|
private deriveBoardConfigToAutoSelect(
|
||||||
newState: AttachedBoardsChangeEvent['newState']
|
newState: AttachedBoardsChangeEvent['newState']
|
||||||
): void {
|
): void {
|
||||||
if (!this.portToAutoSelectCanBeDerived()) {
|
if (!this.lastBoardsConfigOnUpload || !this.lastAvailablePortsOnUpload) {
|
||||||
this.boardConfigToAutoSelect = undefined;
|
this.boardConfigToAutoSelect = undefined;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldPorts = this.lastAvailablePortsOnUpload!;
|
const oldPorts = this.lastAvailablePortsOnUpload;
|
||||||
const { ports: newPorts, boards: newBoards } = newState;
|
const { ports: newPorts, boards: newBoards } = newState;
|
||||||
|
|
||||||
const appearedPorts =
|
const appearedPorts =
|
||||||
@ -205,20 +199,39 @@ export class BoardsServiceProvider
|
|||||||
Port.sameAs(board.port, port)
|
Port.sameAs(board.port, port)
|
||||||
);
|
);
|
||||||
|
|
||||||
const lastBoardsConfigOnUpload = this.lastBoardsConfigOnUpload!;
|
const lastBoardsConfigOnUpload = this.lastBoardsConfigOnUpload;
|
||||||
|
|
||||||
if (
|
if (boardOnAppearedPort && lastBoardsConfigOnUpload.selectedBoard) {
|
||||||
boardOnAppearedPort &&
|
const boardIsSameHardware = Board.hardwareIdEquals(
|
||||||
lastBoardsConfigOnUpload.selectedBoard &&
|
|
||||||
Board.sameAs(
|
|
||||||
boardOnAppearedPort,
|
boardOnAppearedPort,
|
||||||
lastBoardsConfigOnUpload.selectedBoard
|
lastBoardsConfigOnUpload.selectedBoard
|
||||||
)
|
);
|
||||||
) {
|
|
||||||
|
const boardIsSameFqbn = Board.sameAs(
|
||||||
|
boardOnAppearedPort,
|
||||||
|
lastBoardsConfigOnUpload.selectedBoard
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!boardIsSameHardware && !boardIsSameFqbn) continue;
|
||||||
|
|
||||||
|
let boardToAutoSelect = boardOnAppearedPort;
|
||||||
|
if (boardIsSameHardware && !boardIsSameFqbn) {
|
||||||
|
const { name, fqbn } = lastBoardsConfigOnUpload.selectedBoard;
|
||||||
|
|
||||||
|
boardToAutoSelect = {
|
||||||
|
...boardToAutoSelect,
|
||||||
|
name:
|
||||||
|
boardToAutoSelect.name === Unknown || !boardToAutoSelect.name
|
||||||
|
? name
|
||||||
|
: boardToAutoSelect.name,
|
||||||
|
fqbn: boardToAutoSelect.fqbn || fqbn,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
this.clearBoardDiscoverySnapshot();
|
this.clearBoardDiscoverySnapshot();
|
||||||
|
|
||||||
this.boardConfigToAutoSelect = {
|
this.boardConfigToAutoSelect = {
|
||||||
selectedBoard: boardOnAppearedPort,
|
selectedBoard: boardToAutoSelect,
|
||||||
selectedPort: port,
|
selectedPort: port,
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
@ -326,8 +339,10 @@ export class BoardsServiceProvider
|
|||||||
// it is just a FQBN, so we need to find the `selected` board among the `AvailableBoards`
|
// it is just a FQBN, so we need to find the `selected` board among the `AvailableBoards`
|
||||||
const selectedAvailableBoard = AvailableBoard.is(selectedBoard)
|
const selectedAvailableBoard = AvailableBoard.is(selectedBoard)
|
||||||
? selectedBoard
|
? selectedBoard
|
||||||
: this._availableBoards.find((availableBoard) =>
|
: this._availableBoards.find(
|
||||||
Board.sameAs(availableBoard, selectedBoard)
|
(availableBoard) =>
|
||||||
|
Board.hardwareIdEquals(availableBoard, selectedBoard) ||
|
||||||
|
Board.sameAs(availableBoard, selectedBoard)
|
||||||
);
|
);
|
||||||
if (
|
if (
|
||||||
selectedAvailableBoard &&
|
selectedAvailableBoard &&
|
||||||
@ -353,9 +368,28 @@ export class BoardsServiceProvider
|
|||||||
|
|
||||||
protected tryReconnect(): boolean {
|
protected tryReconnect(): boolean {
|
||||||
if (this.latestValidBoardsConfig && !this.canUploadTo(this.boardsConfig)) {
|
if (this.latestValidBoardsConfig && !this.canUploadTo(this.boardsConfig)) {
|
||||||
|
// ** Reconnect to a board unplugged from, and plugged back into the same port
|
||||||
for (const board of this.availableBoards.filter(
|
for (const board of this.availableBoards.filter(
|
||||||
({ state }) => state !== AvailableBoard.State.incomplete
|
({ state }) => state !== AvailableBoard.State.incomplete
|
||||||
)) {
|
)) {
|
||||||
|
if (
|
||||||
|
Board.hardwareIdEquals(
|
||||||
|
this.latestValidBoardsConfig.selectedBoard,
|
||||||
|
board
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
const { name, fqbn } = this.latestValidBoardsConfig.selectedBoard;
|
||||||
|
this.boardsConfig = {
|
||||||
|
selectedBoard: {
|
||||||
|
name: board.name === Unknown || !board.name ? name : board.name,
|
||||||
|
fqbn: board.fqbn || fqbn,
|
||||||
|
port: board.port,
|
||||||
|
},
|
||||||
|
selectedPort: board.port,
|
||||||
|
};
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.latestValidBoardsConfig.selectedBoard.fqbn === board.fqbn &&
|
this.latestValidBoardsConfig.selectedBoard.fqbn === board.fqbn &&
|
||||||
this.latestValidBoardsConfig.selectedBoard.name === board.name &&
|
this.latestValidBoardsConfig.selectedBoard.name === board.name &&
|
||||||
@ -365,12 +399,15 @@ export class BoardsServiceProvider
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// **
|
||||||
|
|
||||||
|
// ** Reconnect to a board whose port changed due to an upload
|
||||||
if (!this.boardConfigToAutoSelect) return false;
|
if (!this.boardConfigToAutoSelect) return false;
|
||||||
|
|
||||||
this.boardsConfig = this.boardConfigToAutoSelect;
|
this.boardsConfig = this.boardConfigToAutoSelect;
|
||||||
this.boardConfigToAutoSelect = undefined;
|
this.boardConfigToAutoSelect = undefined;
|
||||||
return true;
|
return true;
|
||||||
|
// **
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -245,6 +245,7 @@ export interface Port {
|
|||||||
readonly protocol: string;
|
readonly protocol: string;
|
||||||
readonly protocolLabel: string;
|
readonly protocolLabel: string;
|
||||||
readonly properties?: Record<string, string>;
|
readonly properties?: Record<string, string>;
|
||||||
|
readonly hardwareId?: string;
|
||||||
}
|
}
|
||||||
export namespace Port {
|
export namespace Port {
|
||||||
export type Properties = Record<string, string>;
|
export type Properties = Record<string, string>;
|
||||||
@ -553,6 +554,19 @@ export namespace Board {
|
|||||||
return left.name === right.name && left.fqbn === right.fqbn;
|
return left.name === right.name && left.fqbn === right.fqbn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function hardwareIdEquals(left: Board, right: Board): boolean {
|
||||||
|
if (left.port && right.port) {
|
||||||
|
const { hardwareId: leftHardwareId } = left.port;
|
||||||
|
const { hardwareId: rightHardwareId } = right.port;
|
||||||
|
|
||||||
|
if (leftHardwareId && rightHardwareId) {
|
||||||
|
return leftHardwareId === rightHardwareId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
export function sameAs(left: Board, right: string | Board): boolean {
|
export function sameAs(left: Board, right: string | Board): boolean {
|
||||||
// How to associate a selected board with one of the available cores: https://typefox.slack.com/archives/CJJHJCJSJ/p1571142327059200
|
// How to associate a selected board with one of the available cores: https://typefox.slack.com/archives/CJJHJCJSJ/p1571142327059200
|
||||||
// 1. How to use the FQBN if any and infer the package ID from it: https://typefox.slack.com/archives/CJJHJCJSJ/p1571147549069100
|
// 1. How to use the FQBN if any and infer the package ID from it: https://typefox.slack.com/archives/CJJHJCJSJ/p1571147549069100
|
||||||
|
@ -323,14 +323,14 @@ export class BoardDiscovery
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fromRpcPort(rpcPort: RpcPort): Port {
|
private fromRpcPort(rpcPort: RpcPort): Port {
|
||||||
const port = {
|
return {
|
||||||
address: rpcPort.getAddress(),
|
address: rpcPort.getAddress(),
|
||||||
addressLabel: rpcPort.getLabel(),
|
addressLabel: rpcPort.getLabel(),
|
||||||
protocol: rpcPort.getProtocol(),
|
protocol: rpcPort.getProtocol(),
|
||||||
protocolLabel: rpcPort.getProtocolLabel(),
|
protocolLabel: rpcPort.getProtocolLabel(),
|
||||||
properties: Port.Properties.create(rpcPort.getPropertiesMap().toObject()),
|
properties: Port.Properties.create(rpcPort.getPropertiesMap().toObject()),
|
||||||
|
hardwareId: rpcPort.getHardwareId(),
|
||||||
};
|
};
|
||||||
return port;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user