Skip to content

Commit 4ecc037

Browse files
sandeepmistryfacchinm
authored andcommitted
Select (first) target board when port is selected and has known board
1 parent 781d84b commit 4ecc037

File tree

6 files changed

+64
-8
lines changed

6 files changed

+64
-8
lines changed

app/src/processing/app/Base.java

+25-1
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

+18-5
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;
@@ -1043,19 +1046,21 @@ private void addInternalTools(JMenu menu) {
10431046
class SerialMenuListener implements ActionListener {
10441047

10451048
private final String serialPort;
1049+
private final String boardId;
10461050

1047-
public SerialMenuListener(String serialPort) {
1051+
public SerialMenuListener(String serialPort, String boardId) {
10481052
this.serialPort = serialPort;
1053+
this.boardId = boardId;
10491054
}
10501055

10511056
public void actionPerformed(ActionEvent e) {
1052-
selectSerialPort(serialPort);
1057+
selectSerialPort(serialPort, boardId);
10531058
base.onBoardOrPortChange();
10541059
}
10551060

10561061
}
10571062

1058-
private void selectSerialPort(String name) {
1063+
private void selectSerialPort(String name, String boardId) {
10591064
if(portMenu == null) {
10601065
System.out.println(tr("serialMenu is null"));
10611066
return;
@@ -1095,6 +1100,13 @@ private void selectSerialPort(String name) {
10951100
// ignore
10961101
}
10971102
}
1103+
1104+
if (boardId != null) {
1105+
TargetBoard targetBoard = BaseNoGui.getPlatform().resolveBoardById(BaseNoGui.packages, boardId);
1106+
if (targetBoard != null) {
1107+
base.selectTargetBoard(targetBoard);
1108+
}
1109+
}
10981110

10991111
onBoardOrPortChange();
11001112
base.onBoardOrPortChange();
@@ -1139,9 +1151,10 @@ public int compare(BoardPort o1, BoardPort o2) {
11391151
}
11401152
String address = port.getAddress();
11411153
String label = port.getLabel();
1154+
String boardId = port.getBoardId();
11421155

11431156
JCheckBoxMenuItem item = new JCheckBoxMenuItem(label, address.equals(selectedPort));
1144-
item.addActionListener(new SerialMenuListener(address));
1157+
item.addActionListener(new SerialMenuListener(address, boardId));
11451158
portMenu.add(item);
11461159
}
11471160

@@ -2175,7 +2188,7 @@ private boolean serialPrompt() {
21752188
names,
21762189
0);
21772190
if (result == null) return false;
2178-
selectSerialPort(result);
2191+
selectSerialPort(result, null);
21792192
base.onBoardOrPortChange();
21802193
return true;
21812194
}

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

+9
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

+1
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

+1
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

+10-2
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)