Skip to content

Commit 1ee0965

Browse files
sandeepmistryfacchinm
authored andcommitted
Select (first) target board when port is selected and has known board
1 parent 3e2c1db commit 1ee0965

File tree

6 files changed

+64
-8
lines changed

6 files changed

+64
-8
lines changed

app/src/processing/app/Base.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ public class Base {
110110
// int editorCount;
111111
List<Editor> editors = Collections.synchronizedList(new ArrayList<Editor>());
112112
Editor activeEditor;
113+
114+
private static JMenu boardMenu;
113115

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

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

13121336
public synchronized void onBoardOrPortChange() {
13131337
BaseNoGui.onBoardOrPortChange();
@@ -1402,7 +1426,7 @@ public void rebuildBoardsMenu() throws Exception {
14021426
boardsCustomMenus = new LinkedList<>();
14031427

14041428
// The first custom menu is the "Board" selection submenu
1405-
JMenu boardMenu = new JMenu(tr("Board"));
1429+
boardMenu = new JMenu(tr("Board"));
14061430
boardMenu.putClientProperty("removeOnWindowDeactivation", true);
14071431
MenuScroller.setScrollerFor(boardMenu).setTopFixedCount(1);
14081432

app/src/processing/app/Editor.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@
9595
import cc.arduino.view.findreplace.FindReplace;
9696
import jssc.SerialPortException;
9797
import processing.app.debug.RunnerException;
98+
import processing.app.debug.TargetBoard;
99+
import processing.app.debug.TargetPackage;
100+
import processing.app.debug.TargetPlatform;
98101
import processing.app.forms.PasswordAuthorizationDialog;
99102
import processing.app.helpers.DocumentTextChangeListener;
100103
import processing.app.helpers.Keys;
@@ -1007,19 +1010,21 @@ private void addInternalTools(JMenu menu) {
10071010
class SerialMenuListener implements ActionListener {
10081011

10091012
private final String serialPort;
1013+
private final String boardId;
10101014

1011-
public SerialMenuListener(String serialPort) {
1015+
public SerialMenuListener(String serialPort, String boardId) {
10121016
this.serialPort = serialPort;
1017+
this.boardId = boardId;
10131018
}
10141019

10151020
public void actionPerformed(ActionEvent e) {
1016-
selectSerialPort(serialPort);
1021+
selectSerialPort(serialPort, boardId);
10171022
base.onBoardOrPortChange();
10181023
}
10191024

10201025
}
10211026

1022-
private void selectSerialPort(String name) {
1027+
private void selectSerialPort(String name, String boardId) {
10231028
if(portMenu == null) {
10241029
System.out.println(tr("serialMenu is null"));
10251030
return;
@@ -1059,6 +1064,13 @@ private void selectSerialPort(String name) {
10591064
// ignore
10601065
}
10611066
}
1067+
1068+
if (boardId != null) {
1069+
TargetBoard targetBoard = BaseNoGui.getPlatform().resolveBoardById(BaseNoGui.packages, boardId);
1070+
if (targetBoard != null) {
1071+
base.selectTargetBoard(targetBoard);
1072+
}
1073+
}
10621074

10631075
onBoardOrPortChange();
10641076
base.onBoardOrPortChange();
@@ -1103,9 +1115,10 @@ public int compare(BoardPort o1, BoardPort o2) {
11031115
}
11041116
String address = port.getAddress();
11051117
String label = port.getLabel();
1118+
String boardId = port.getBoardId();
11061119

11071120
JCheckBoxMenuItem item = new JCheckBoxMenuItem(label, address.equals(selectedPort));
1108-
item.addActionListener(new SerialMenuListener(address));
1121+
item.addActionListener(new SerialMenuListener(address, boardId));
11091122
portMenu.add(item);
11101123
}
11111124

@@ -2016,7 +2029,7 @@ private boolean serialPrompt() {
20162029
names,
20172030
0);
20182031
if (result == null) return false;
2019-
selectSerialPort(result);
2032+
selectSerialPort(result, null);
20202033
base.onBoardOrPortChange();
20212034
return true;
20222035
}

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
@@ -122,6 +122,7 @@ public void serviceResolved(ServiceEvent serviceEvent) {
122122

123123
port.setAddress(address);
124124
port.setBoardName(name);
125+
port.setBoardId(board);
125126
port.setProtocol("network");
126127
port.setLabel(label);
127128

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)