Skip to content

Commit 892ceef

Browse files
sandeepmistryfacchinm
authored andcommitted
Select (first) target board when port is selected and has known board
1 parent 5b502ec commit 892ceef

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
@@ -115,6 +115,8 @@ public class Base {
115115
// int editorCount;
116116
List<Editor> editors = Collections.synchronizedList(new ArrayList<Editor>());
117117
Editor activeEditor;
118+
119+
private static JMenu boardMenu;
118120

119121
// these menus are shared so that the board and serial port selections
120122
// are the same for all windows (since the board and serial port that are
@@ -1327,6 +1329,28 @@ public void rebuildExamplesMenu(JMenu menu) {
13271329

13281330
private static String priorPlatformFolder;
13291331
private static boolean newLibraryImported;
1332+
1333+
public void selectTargetBoard(TargetBoard targetBoard) {
1334+
for (int i = 0; i < boardMenu.getItemCount(); i++) {
1335+
JMenuItem menuItem = boardMenu.getItem(i);
1336+
if (!(menuItem instanceof JRadioButtonMenuItem)) {
1337+
continue;
1338+
}
1339+
1340+
JRadioButtonMenuItem radioButtonMenuItem = ((JRadioButtonMenuItem) menuItem);
1341+
if (targetBoard.getName().equals(radioButtonMenuItem.getText())) {
1342+
radioButtonMenuItem.setSelected(true);
1343+
break;
1344+
}
1345+
}
1346+
1347+
BaseNoGui.selectBoard(targetBoard);
1348+
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, targetBoard, 1);
1349+
1350+
onBoardOrPortChange();
1351+
rebuildImportMenu(Editor.importMenu);
1352+
rebuildExamplesMenu(Editor.examplesMenu);
1353+
}
13301354

13311355
public synchronized void onBoardOrPortChange() {
13321356
BaseNoGui.onBoardOrPortChange();
@@ -1421,7 +1445,7 @@ public void rebuildBoardsMenu() throws Exception {
14211445
boardsCustomMenus = new LinkedList<>();
14221446

14231447
// The first custom menu is the "Board" selection submenu
1424-
JMenu boardMenu = new JMenu(tr("Board"));
1448+
boardMenu = new JMenu(tr("Board"));
14251449
boardMenu.putClientProperty("removeOnWindowDeactivation", true);
14261450
MenuScroller.setScrollerFor(boardMenu).setTopFixedCount(1);
14271451

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;
@@ -1005,19 +1008,21 @@ private void addInternalTools(JMenu menu) {
10051008
class SerialMenuListener implements ActionListener {
10061009

10071010
private final String serialPort;
1011+
private final String boardId;
10081012

1009-
public SerialMenuListener(String serialPort) {
1013+
public SerialMenuListener(String serialPort, String boardId) {
10101014
this.serialPort = serialPort;
1015+
this.boardId = boardId;
10111016
}
10121017

10131018
public void actionPerformed(ActionEvent e) {
1014-
selectSerialPort(serialPort);
1019+
selectSerialPort(serialPort, boardId);
10151020
base.onBoardOrPortChange();
10161021
}
10171022

10181023
}
10191024

1020-
private void selectSerialPort(String name) {
1025+
private void selectSerialPort(String name, String boardId) {
10211026
if(portMenu == null) {
10221027
System.out.println(tr("serialMenu is null"));
10231028
return;
@@ -1055,6 +1060,13 @@ private void selectSerialPort(String name) {
10551060
} catch (Exception e) {
10561061
// ignore
10571062
}
1063+
1064+
if (boardId != null) {
1065+
TargetBoard targetBoard = BaseNoGui.getPlatform().resolveBoardById(BaseNoGui.packages, boardId);
1066+
if (targetBoard != null) {
1067+
base.selectTargetBoard(targetBoard);
1068+
}
1069+
}
10581070

10591071
onBoardOrPortChange();
10601072
base.onBoardOrPortChange();
@@ -1099,9 +1111,10 @@ public int compare(BoardPort o1, BoardPort o2) {
10991111
}
11001112
String address = port.getAddress();
11011113
String label = port.getLabel();
1114+
String boardId = port.getBoardId();
11021115

11031116
JCheckBoxMenuItem item = new JCheckBoxMenuItem(label, address.equals(selectedPort));
1104-
item.addActionListener(new SerialMenuListener(address));
1117+
item.addActionListener(new SerialMenuListener(address, boardId));
11051118
portMenu.add(item);
11061119
}
11071120

@@ -2012,7 +2025,7 @@ private boolean serialPrompt() {
20122025
names,
20132026
0);
20142027
if (result == null) return false;
2015-
selectSerialPort(result);
2028+
selectSerialPort(result, null);
20162029
base.onBoardOrPortChange();
20172030
return true;
20182031
}

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)