1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-31 20:52:13 +01:00

SerialDiscovery: refactor search loop

This commit is contained in:
Cristian Maglie 2020-03-23 17:31:12 +01:00 committed by Cristian Maglie
parent bb629d1ba0
commit 8208376507

View File

@ -148,29 +148,20 @@ public class SerialDiscovery implements Discovery, Runnable {
Map<String, Object> boardData = platform.resolveDeviceByVendorIdProductId(port, BaseNoGui.packages);
BoardPort boardPort = null;
int i = 0;
// create new board if in ports but not in boardPorts
for (BoardPort board : boardPorts) {
if (board.toCompleteString().equalsIgnoreCase(newPort)) {
boardPort = boardPorts.get(i);
boardPorts.get(i).setOnlineStatus(true);
break;
}
i++;
}
if (boardPort != null) {
// if port has been already discovered bring it back online
BoardPort oldBoardPort = boardPorts.stream() //
.filter(bp -> bp.toCompleteString().equalsIgnoreCase(newPort)) //
.findAny().orElse(null);
if (oldBoardPort != null) {
oldBoardPort.setOnlineStatus(true);
continue;
}
boardPort = new BoardPort();
BoardPort boardPort = new BoardPort();
boardPorts.add(boardPort);
boardPort.setAddress(port);
boardPort.setProtocol("serial");
boardPort.setOnlineStatus(true);
boardPort.setLabel(port);
if (boardData != null) {