@@ -88,6 +88,10 @@ public PreferencesMap getPrefs() {
88
88
return prefs ;
89
89
}
90
90
91
+ public PreferencesMap getIdentificationPrefs () {
92
+ return identificationPrefs ;
93
+ }
94
+
91
95
public void setLabel (String label ) {
92
96
this .label = label ;
93
97
}
@@ -117,7 +121,7 @@ public TargetBoard searchMatchingBoard() {
117
121
for (TargetPackage targetPackage : BaseNoGui .packages .values ()) {
118
122
for (TargetPlatform targetPlatform : targetPackage .getPlatforms ().values ()) {
119
123
for (TargetBoard board : targetPlatform .getBoards ().values ()) {
120
- if (matchesIdentificationPrefs (board )) {
124
+ if (matchesBoard (board )) {
121
125
setBoardName (board .getName ());
122
126
return board ;
123
127
}
@@ -126,21 +130,44 @@ public TargetBoard searchMatchingBoard() {
126
130
}
127
131
return null ;
128
132
}
129
- // Check whether a board matches all identificationPrefs fields
130
- private boolean matchesIdentificationPrefs (TargetBoard board ) {
131
- for (String key : identificationPrefs .keySet ()) {
132
- if (!matchesIdentificationPref (board , key )) return false ;
133
- }
134
- return true ;
135
- }
136
- // Check whether a board matches a single identificationPrefs field
137
- private boolean matchesIdentificationPref (TargetBoard board , String key ) {
138
- String value = identificationPrefs .get (key );
139
- if (value == null ) return false ;
140
- for (String property : board .getPreferences ().subTree (key ).values ()) {
141
- if (property .equalsIgnoreCase (value )) return true ;
133
+
134
+ public boolean matchesBoard (TargetBoard board ) {
135
+ PreferencesMap identificationProps = getIdentificationPrefs ();
136
+ PreferencesMap boardProps = board .getPreferences ();
137
+
138
+ // Identification properties are defined in boards.txt with a ".N" suffix
139
+ // for example:
140
+ //
141
+ // uno.name=Arduino/Genuino Uno
142
+ // uno.vid.0=0x2341
143
+ // uno.pid.0=0x0043
144
+ // uno.vid.1=0x2341
145
+ // uno.pid.1=0x0001
146
+ // uno.vid.2=0x2A03
147
+ // uno.pid.2=0x0043
148
+ // uno.vid.3=0x2341
149
+ // uno.pid.3=0x0243
150
+ //
151
+ // so we must search starting from suffix ".0" and increasing until we
152
+ // found a match or the board has no more identification properties defined
153
+
154
+ for (int suffix = 0 ;; suffix ++) {
155
+ boolean found = true ;
156
+ for (String prop : identificationProps .keySet ()) {
157
+ String value = identificationProps .get (prop );
158
+ prop += "." + suffix ;
159
+ if (!boardProps .containsKey (prop )) {
160
+ return false ;
161
+ }
162
+ if (!value .equalsIgnoreCase (boardProps .get (prop ))) {
163
+ found = false ;
164
+ break ;
165
+ }
166
+ }
167
+ if (found ) {
168
+ return true ;
169
+ }
142
170
}
143
- return false ;
144
171
}
145
172
146
173
}
0 commit comments