mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-02 13:24:12 +01:00
SerialDiscovery: refactor search loop
This commit is contained in:
parent
bb629d1ba0
commit
8208376507
@ -148,29 +148,20 @@ public class SerialDiscovery implements Discovery, Runnable {
|
|||||||
|
|
||||||
Map<String, Object> boardData = platform.resolveDeviceByVendorIdProductId(port, BaseNoGui.packages);
|
Map<String, Object> boardData = platform.resolveDeviceByVendorIdProductId(port, BaseNoGui.packages);
|
||||||
|
|
||||||
BoardPort boardPort = null;
|
// if port has been already discovered bring it back online
|
||||||
int i = 0;
|
BoardPort oldBoardPort = boardPorts.stream() //
|
||||||
|
.filter(bp -> bp.toCompleteString().equalsIgnoreCase(newPort)) //
|
||||||
// create new board if in ports but not in boardPorts
|
.findAny().orElse(null);
|
||||||
for (BoardPort board : boardPorts) {
|
if (oldBoardPort != null) {
|
||||||
if (board.toCompleteString().equalsIgnoreCase(newPort)) {
|
oldBoardPort.setOnlineStatus(true);
|
||||||
boardPort = boardPorts.get(i);
|
|
||||||
boardPorts.get(i).setOnlineStatus(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (boardPort != null) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
boardPort = new BoardPort();
|
BoardPort boardPort = new BoardPort();
|
||||||
boardPorts.add(boardPort);
|
boardPorts.add(boardPort);
|
||||||
boardPort.setAddress(port);
|
boardPort.setAddress(port);
|
||||||
boardPort.setProtocol("serial");
|
boardPort.setProtocol("serial");
|
||||||
boardPort.setOnlineStatus(true);
|
boardPort.setOnlineStatus(true);
|
||||||
|
|
||||||
boardPort.setLabel(port);
|
boardPort.setLabel(port);
|
||||||
|
|
||||||
if (boardData != null) {
|
if (boardData != null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user