Skip to content

Pluggable discovery: search in platform.txt (WIP) #8038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f81798b
Pluggable discovery: search in platform.txt (WIP)
cmaglie Sep 10, 2018
f5bf6e5
Add BoardPort copy constructor
PaulStoffregen Sep 29, 2018
5ba56ab
Initial PluggableDiscovery using BoardPort for JSON
PaulStoffregen Sep 29, 2018
b606657
PluggableDiscovery check for START_SYNC not supported
PaulStoffregen Sep 29, 2018
e029acc
Add PluggableDiscoveryMessage for BoardPort change metadata
PaulStoffregen Oct 1, 2018
05092bf
Move BoardPort fixed fields into prefs
PaulStoffregen Oct 1, 2018
d7143d6
Add BoardPort identificationPrefs and searchMatchingBoard
PaulStoffregen Oct 3, 2018
8d6fa72
Removing fixed fields in BoardPort
cmaglie Oct 4, 2018
3ccb2d9
Merged SerialDiscovery and SerialBoardLister
cmaglie Oct 4, 2018
80fb9a0
Optimized forceRefresh() method by removing redundant boolean paramater
cmaglie Oct 4, 2018
5bc9665
Slightly optimized method by removing redundant boolean flag
cmaglie Oct 4, 2018
ec4787a
Fixed board identification in BoardPort
cmaglie Oct 4, 2018
9ba172b
Show BoardName.boardName field in 'Ports' menu
cmaglie Nov 23, 2018
cfd3cf2
Use correctly the setBoardName() method in NetworkDiscovery
cmaglie Nov 23, 2018
c03a8bc
Minor fix in indentation and style
cmaglie Nov 23, 2018
349af4b
Added BoardPort.protocolLabel and simplified port menu rendering
cmaglie Nov 29, 2018
7186213
Slightly changed pluggable discovery json parsing
cmaglie Nov 30, 2018
8e9f0cf
PluggableDiscovery: added a 'port' field in json messages
cmaglie Nov 30, 2018
4c188c9
PluggableDiscovery: Factored out method to umarshal BoardPort from JSON
cmaglie Nov 30, 2018
4ae740a
PluggableDiscovery: BoardPort.label sanity check in the correct place
cmaglie Nov 30, 2018
7bc086a
PluggableDiscovery: correct synchronization on 'portList' access
cmaglie Nov 30, 2018
6c50007
Editor: renamed status bar field serialport -> port
cmaglie Dec 7, 2018
4fffcd6
Editor: use TargetBoard.getName() to get board name
cmaglie Dec 7, 2018
651dcd5
Removed unused field
cmaglie Dec 7, 2018
e1caaf1
Perform port selection after initializing packages
cmaglie Jan 23, 2019
feb863d
PluggableDiscovery: allow patterns to contain runtime variables
facchinm Dec 13, 2018
be1a840
Add TargetBoard.getFQBN helper
facchinm Mar 7, 2019
d4bbf71
Match wildcard property "." with board fqbn/name
facchinm Mar 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added BoardPort.protocolLabel and simplified port menu rendering
  • Loading branch information
cmaglie committed Jan 23, 2019
commit 349af4b5cfa7410726ba4e163903c8d03f82170f
57 changes: 34 additions & 23 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -147,9 +146,6 @@ public boolean test(SketchController controller) {
}
}

private final static List<String> BOARD_PROTOCOLS_ORDER = Arrays.asList("serial", "network");
private final static List<String> BOARD_PROTOCOLS_ORDER_TRANSLATIONS = Arrays.asList(tr("Serial ports"), tr("Network ports"));

final Base base;

// otherwise, if the window is resized with the message label
Expand Down Expand Up @@ -1062,6 +1058,9 @@ public String toString() {
}

private void populatePortMenu() {
final List<String> PROTOCOLS_ORDER = Arrays.asList("serial", "network");
final List<String> PROTOCOLS_LABELS = Arrays.asList(tr("Serial ports"), tr("Network ports"));

portMenu.removeAll();

String selectedPort = PreferencesData.get("serial.port");
Expand All @@ -1070,31 +1069,43 @@ private void populatePortMenu() {

ports = platform.filterPorts(ports, PreferencesData.getBoolean("serial.ports.showall"));

Collections.sort(ports, new Comparator<BoardPort>() {
@Override
public int compare(BoardPort o1, BoardPort o2) {
return (BOARD_PROTOCOLS_ORDER.indexOf(o1.getProtocol()) - BOARD_PROTOCOLS_ORDER.indexOf(o2.getProtocol())) * 10 +
o1.getAddress().compareTo(o2.getAddress());
}
ports.stream() //
.filter(port -> port.getProtocolLabel() == null || port.getProtocolLabel().isEmpty())
.forEach(port -> {
int labelIdx = PROTOCOLS_ORDER.indexOf(port.getProtocol());
if (labelIdx != -1) {
port.setProtocolLabel(PROTOCOLS_LABELS.get(labelIdx));
} else {
port.setProtocolLabel(port.getProtocol());
}
});

Collections.sort(ports, (port1, port2) -> {
String pr1 = port1.getProtocol();
String pr2 = port2.getProtocol();
int prIdx1 = PROTOCOLS_ORDER.contains(pr1) ? PROTOCOLS_ORDER.indexOf(pr1) : 999;
int prIdx2 = PROTOCOLS_ORDER.contains(pr2) ? PROTOCOLS_ORDER.indexOf(pr2) : 999;
int r = prIdx1 - prIdx2;
if (r != 0)
return r;
r = port1.getProtocolLabel().compareTo(port2.getProtocolLabel());
if (r != 0)
return r;
return port1.getAddress().compareTo(port2.getAddress());
});

String lastProtocol = null;
String lastProtocolTranslated;
String lastProtocol = "";
String lastProtocolLabel = "";
for (BoardPort port : ports) {
if (lastProtocol == null || !port.getProtocol().equals(lastProtocol)) {
if (lastProtocol != null) {
if (!port.getProtocol().equals(lastProtocol) || !port.getProtocolLabel().equals(lastProtocolLabel)) {
if (!lastProtocol.isEmpty()) {
portMenu.addSeparator();
}
lastProtocol = port.getProtocol();

if (BOARD_PROTOCOLS_ORDER.indexOf(port.getProtocol()) != -1) {
lastProtocolTranslated = BOARD_PROTOCOLS_ORDER_TRANSLATIONS.get(BOARD_PROTOCOLS_ORDER.indexOf(port.getProtocol()));
} else {
lastProtocolTranslated = port.getProtocol();
}
JMenuItem lastProtocolMenuItem = new JMenuItem(tr(lastProtocolTranslated));
lastProtocolMenuItem.setEnabled(false);
portMenu.add(lastProtocolMenuItem);
lastProtocolLabel = port.getProtocolLabel();
JMenuItem item = new JMenuItem(tr(lastProtocolLabel));
item.setEnabled(false);
portMenu.add(item);
}
String address = port.getAddress();

Expand Down
9 changes: 9 additions & 0 deletions arduino-core/src/cc/arduino/packages/BoardPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class BoardPort {

private String address; // unique name for this port, used by Preferences
private String protocol; // how to communicate, used for Ports menu sections
private String protocolLabel; // protocol extended name to display on GUI
private String boardName;
private String label; // friendly name shown in Ports menu
private final PreferencesMap identificationPrefs; // data to match with boards.txt
Expand Down Expand Up @@ -76,6 +77,14 @@ public void setProtocol(String protocol) {
this.protocol = protocol;
}

public String getProtocolLabel() {
return protocolLabel;
}

public void setProtocolLabel(String protocolLabel) {
this.protocolLabel = protocolLabel;
}

public String getBoardName() {
return boardName;
}
Expand Down