Skip to content

Commit 6ff2dde

Browse files
committed
Select (first) target board when port is selected and has known board
1 parent 534d626 commit 6ff2dde

File tree

6 files changed

+65
-14
lines changed

6 files changed

+65
-14
lines changed

app/src/processing/app/Base.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ public class Base {
109109
// int editorCount;
110110
List<Editor> editors = Collections.synchronizedList(new ArrayList<Editor>());
111111
Editor activeEditor;
112+
113+
private static JMenu boardMenu;
112114

113115
// these menus are shared so that the board and serial port selections
114116
// are the same for all windows (since the board and serial port that are
@@ -1312,6 +1314,28 @@ public void rebuildExamplesMenu(JMenu menu) {
13121314

13131315
private static String priorPlatformFolder;
13141316
private static boolean newLibraryImported;
1317+
1318+
public void selectTargetBoard(TargetBoard targetBoard) {
1319+
for (int i = 0; i < boardMenu.getItemCount(); i++) {
1320+
JMenuItem menuItem = boardMenu.getItem(i);
1321+
if (!(menuItem instanceof JRadioButtonMenuItem)) {
1322+
continue;
1323+
}
1324+
1325+
JRadioButtonMenuItem radioButtonMenuItem = ((JRadioButtonMenuItem) menuItem);
1326+
if (targetBoard.getName().equals(radioButtonMenuItem.getText())) {
1327+
radioButtonMenuItem.setSelected(true);
1328+
break;
1329+
}
1330+
}
1331+
1332+
BaseNoGui.selectBoard(targetBoard);
1333+
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, targetBoard, 1);
1334+
1335+
onBoardOrPortChange();
1336+
rebuildImportMenu(Editor.importMenu);
1337+
rebuildExamplesMenu(Editor.examplesMenu);
1338+
}
13151339

13161340
public void onBoardOrPortChange() {
13171341
BaseNoGui.onBoardOrPortChange();
@@ -1406,7 +1430,7 @@ public void rebuildBoardsMenu() throws Exception {
14061430
boardsCustomMenus = new LinkedList<>();
14071431

14081432
// The first custom menu is the "Board" selection submenu
1409-
JMenu boardMenu = new JMenu(tr("Board"));
1433+
boardMenu = new JMenu(tr("Board"));
14101434
boardMenu.putClientProperty("removeOnWindowDeactivation", true);
14111435
MenuScroller.setScrollerFor(boardMenu).setTopFixedCount(1);
14121436

@@ -1512,12 +1536,7 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
15121536
@SuppressWarnings("serial")
15131537
Action action = new AbstractAction(board.getName()) {
15141538
public void actionPerformed(ActionEvent actionevent) {
1515-
BaseNoGui.selectBoard((TargetBoard) getValue("b"));
1516-
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
1517-
1518-
onBoardOrPortChange();
1519-
rebuildImportMenu(Editor.importMenu);
1520-
rebuildExamplesMenu(Editor.examplesMenu);
1539+
selectTargetBoard((TargetBoard) getValue("b"));
15211540
}
15221541
};
15231542
action.putValue("b", board);

app/src/processing/app/Editor.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
import com.jcraft.jsch.JSchException;
3434
import jssc.SerialPortException;
3535
import processing.app.debug.RunnerException;
36+
import processing.app.debug.TargetBoard;
37+
import processing.app.debug.TargetPackage;
38+
import processing.app.debug.TargetPlatform;
3639
import processing.app.forms.PasswordAuthorizationDialog;
3740
import processing.app.helpers.DocumentTextChangeListener;
3841
import processing.app.helpers.Keys;
@@ -1006,19 +1009,21 @@ private void addInternalTools(JMenu menu) {
10061009
class SerialMenuListener implements ActionListener {
10071010

10081011
private final String serialPort;
1012+
private final String boardId;
10091013

1010-
public SerialMenuListener(String serialPort) {
1014+
public SerialMenuListener(String serialPort, String boardId) {
10111015
this.serialPort = serialPort;
1016+
this.boardId = boardId;
10121017
}
10131018

10141019
public void actionPerformed(ActionEvent e) {
1015-
selectSerialPort(serialPort);
1020+
selectSerialPort(serialPort, boardId);
10161021
base.onBoardOrPortChange();
10171022
}
10181023

10191024
}
10201025

1021-
private void selectSerialPort(String name) {
1026+
private void selectSerialPort(String name, String boardId) {
10221027
if(portMenu == null) {
10231028
System.out.println(tr("serialMenu is null"));
10241029
return;
@@ -1058,6 +1063,13 @@ private void selectSerialPort(String name) {
10581063
// ignore
10591064
}
10601065
}
1066+
1067+
if (boardId != null) {
1068+
TargetBoard targetBoard = BaseNoGui.getPlatform().resolveBoardById(BaseNoGui.packages, boardId);
1069+
if (targetBoard != null) {
1070+
base.selectTargetBoard(targetBoard);
1071+
}
1072+
}
10611073

10621074
onBoardOrPortChange();
10631075
base.onBoardOrPortChange();
@@ -1102,9 +1114,10 @@ public int compare(BoardPort o1, BoardPort o2) {
11021114
}
11031115
String address = port.getAddress();
11041116
String label = port.getLabel();
1117+
String boardId = port.getBoardId();
11051118

11061119
JCheckBoxMenuItem item = new JCheckBoxMenuItem(label, address.equals(selectedPort));
1107-
item.addActionListener(new SerialMenuListener(address));
1120+
item.addActionListener(new SerialMenuListener(address, boardId));
11081121
portMenu.add(item);
11091122
}
11101123

@@ -2111,7 +2124,7 @@ private boolean serialPrompt() {
21112124
names,
21122125
0);
21132126
if (result == null) return false;
2114-
selectSerialPort(result);
2127+
selectSerialPort(result, null);
21152128
base.onBoardOrPortChange();
21162129
return true;
21172130
}

arduino-core/src/cc/arduino/packages/BoardPort.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class BoardPort {
3636
private String address;
3737
private String protocol;
3838
private String boardName;
39+
private String boardId;
3940
private String vid;
4041
private String pid;
4142
private String iserial;
@@ -71,6 +72,14 @@ public void setBoardName(String boardName) {
7172
this.boardName = boardName;
7273
}
7374

75+
public String getBoardId() {
76+
return boardId;
77+
}
78+
79+
public void setBoardId(String boardId) {
80+
this.boardId = boardId;
81+
}
82+
7483
public PreferencesMap getPrefs() {
7584
return prefs;
7685
}

arduino-core/src/cc/arduino/packages/discoverers/NetworkDiscovery.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public void serviceResolved(ServiceEvent serviceEvent) {
124124

125125
port.setAddress(address);
126126
port.setBoardName(name);
127+
port.setBoardId(board);
127128
port.setProtocol("network");
128129
port.setLabel(label);
129130

arduino-core/src/cc/arduino/packages/discoverers/serial/SerialBoardsLister.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ public synchronized void retriggerDiscovery(boolean polled) {
155155
label += " (" + boardName + ")";
156156
}
157157
boardPort.setBoardName(boardName);
158+
boardPort.setBoardId(board.getId());
158159
}
159160
} else {
160161
if (!parts[1].equals("0000")) {

arduino-core/src/processing/app/Platform.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,21 +269,29 @@ public synchronized Map<String, Object> resolveDeviceByVendorIdProductId(String
269269
return null;
270270
}
271271

272-
public String resolveDeviceByBoardID(Map<String, TargetPackage> packages, String boardId) {
272+
public TargetBoard resolveBoardById(Map<String, TargetPackage> packages, String boardId) {
273273
assert packages != null;
274274
assert boardId != null;
275275
for (TargetPackage targetPackage : packages.values()) {
276276
for (TargetPlatform targetPlatform : targetPackage.getPlatforms().values()) {
277277
for (TargetBoard board : targetPlatform.getBoards().values()) {
278278
if (boardId.equals(board.getId())) {
279-
return board.getName();
279+
return board;
280280
}
281281
}
282282
}
283283
}
284284
return null;
285285
}
286286

287+
public String resolveDeviceByBoardID(Map<String, TargetPackage> packages, String boardId) {
288+
TargetBoard targetBoard = resolveBoardById(packages, boardId);
289+
if (targetBoard != null) {
290+
return targetBoard.getName();
291+
}
292+
return null;
293+
}
294+
287295
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
288296

289297
public String getName() {

0 commit comments

Comments
 (0)