|
33 | 33 |
|
34 | 34 | public class BoardPort { |
35 | 35 |
|
36 | | - private String address; |
37 | | - private String protocol; |
| 36 | + private String address; // unique name for this port, used by Preferences |
| 37 | + private String protocol; // how to communicate, used for Ports menu sections |
38 | 38 | private String boardName; |
39 | | - private String vid; |
40 | | - private String pid; |
41 | | - private String iserial; |
42 | | - private String label; |
43 | | - private final PreferencesMap prefs; |
44 | | - private boolean online; |
| 39 | + private String label; // friendly name shown in Ports menu |
| 40 | + private final PreferencesMap prefs; // "vendorId", "productId", "serialNumber" |
| 41 | + private boolean online; // used by SerialBoardsLister (during upload??) |
45 | 42 |
|
46 | 43 | public BoardPort() { |
47 | 44 | this.prefs = new PreferencesMap(); |
48 | 45 | } |
49 | 46 |
|
50 | 47 | public BoardPort(BoardPort bp) { |
51 | | - prefs = new PreferencesMap(); |
52 | | - // TODO: copy bp.prefs to prefs |
| 48 | + prefs = new PreferencesMap(bp.prefs); |
53 | 49 | address = bp.address; |
54 | 50 | protocol = bp.protocol; |
55 | 51 | boardName = bp.boardName; |
56 | | - vid = bp.vid; |
57 | | - pid = bp.pid; |
58 | | - iserial = bp.iserial; |
59 | 52 | label = bp.label; |
| 53 | + online = bp.online; |
60 | 54 | } |
61 | 55 |
|
62 | 56 | public String getAddress() { |
@@ -104,27 +98,39 @@ public boolean isOnline() { |
104 | 98 | } |
105 | 99 |
|
106 | 100 | public void setVIDPID(String vid, String pid) { |
107 | | - this.vid = vid; |
108 | | - this.pid = pid; |
| 101 | + if (vid == null) { |
| 102 | + prefs.remove("vendorId"); |
| 103 | + } else { |
| 104 | + prefs.put("vendorId", vid); |
| 105 | + } |
| 106 | + if (pid == null) { |
| 107 | + prefs.remove("productId"); |
| 108 | + } else { |
| 109 | + prefs.put("productId", pid); |
| 110 | + } |
109 | 111 | } |
110 | 112 |
|
111 | 113 | public String getVID() { |
112 | | - return vid; |
| 114 | + return prefs.get("vendorId"); |
113 | 115 | } |
114 | 116 |
|
115 | 117 | public String getPID() { |
116 | | - return pid; |
| 118 | + return prefs.get("productId"); |
117 | 119 | } |
118 | 120 |
|
119 | 121 | public void setISerial(String iserial) { |
120 | | - this.iserial = iserial; |
| 122 | + if (iserial == null) { |
| 123 | + prefs.remove("serialNumber"); |
| 124 | + } else { |
| 125 | + prefs.put("serialNumber", iserial); |
| 126 | + } |
121 | 127 | } |
122 | 128 | public String getISerial() { |
123 | | - return iserial; |
| 129 | + return prefs.get("serialNumber"); |
124 | 130 | } |
125 | 131 |
|
126 | 132 | @Override |
127 | 133 | public String toString() { |
128 | | - return this.address+"_"+this.vid+"_"+this.pid; |
| 134 | + return this.address+"_"+getVID()+"_"+getPID(); |
129 | 135 | } |
130 | 136 | } |
0 commit comments