Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d95100b

Browse files
author
Federico Fissore
committedAug 27, 2015
Added support to VID+PID specific build properties
1 parent a3b5ab4 commit d95100b

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed
 
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* This file is part of Arduino.
3+
*
4+
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
5+
*
6+
* Arduino is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*
20+
* As a special exception, you may use this file as part of a free software
21+
* library without restriction. Specifically, if other files instantiate
22+
* templates or use macros or inline functions from this file, or you compile
23+
* this file and link it with other files to produce an executable, this
24+
* file does not by itself cause the resulting executable to be covered by
25+
* the GNU General Public License. This exception does not however
26+
* invalidate any other reasons why the executable file might be covered by
27+
* the GNU General Public License.
28+
*/
29+
30+
package cc.arduino;
31+
32+
import cc.arduino.packages.BoardPort;
33+
import processing.app.BaseNoGui;
34+
import processing.app.PreferencesData;
35+
import processing.app.helpers.PreferencesMap;
36+
37+
import java.util.Map;
38+
import java.util.Optional;
39+
40+
public class LoadVIDPIDSpecificPreferences {
41+
42+
public void load(PreferencesMap prefs) {
43+
BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port"));
44+
if (boardPort == null) {
45+
return;
46+
}
47+
48+
int VIDPIDIndex = findVIDPIDIndex(prefs, boardPort.getPrefs().get("vid").toUpperCase(), boardPort.getPrefs().get("pid").toUpperCase());
49+
if (VIDPIDIndex < 0) {
50+
return;
51+
}
52+
53+
prefs.putAll(prefs.subTree("vid." + VIDPIDIndex));
54+
}
55+
56+
private int findVIDPIDIndex(PreferencesMap preferences, String vid, String pid) {
57+
Optional<Integer> vidPid = preferences.subTree("vid").entrySet().stream()
58+
.filter(keyValue -> !keyValue.getKey().contains("."))
59+
.filter(keyValue -> vid.equals(keyValue.getValue().toUpperCase()) && pid.equals(preferences.get("pid." + keyValue.getKey()).toUpperCase()))
60+
.map(Map.Entry::getKey)
61+
.map(Integer::valueOf)
62+
.findFirst();
63+
64+
return vidPid.orElse(-1);
65+
}
66+
67+
}
68+

‎arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import cc.arduino.packages.Uploader;
3030
import processing.app.*;
31+
import cc.arduino.LoadVIDPIDSpecificPreferences;
3132
import processing.app.debug.RunnerException;
3233
import processing.app.debug.TargetPlatform;
3334
import processing.app.helpers.OSUtils;
@@ -343,6 +344,8 @@ public boolean burnBootloader() throws Exception {
343344
prefs.put("bootloader.verbose", prefs.getOrExcept("bootloader.params.quiet"));
344345
}
345346

347+
new LoadVIDPIDSpecificPreferences().load(prefs);
348+
346349
String pattern = prefs.getOrExcept("erase.pattern");
347350
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
348351
if (!executeUploadCommand(cmd))

‎arduino-core/src/processing/app/debug/Compiler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.Date;
3838
import java.util.GregorianCalendar;
3939

40+
import cc.arduino.LoadVIDPIDSpecificPreferences;
4041
import cc.arduino.MyStreamPumper;
4142
import cc.arduino.packages.BoardPort;
4243
import cc.arduino.packages.Uploader;
@@ -588,6 +589,8 @@ private PreferencesMap createBuildPreferences(String _buildPath,
588589
p.put("extra.time.zone", Long.toString(timezone));
589590
p.put("extra.time.dst", Long.toString(daylight));
590591

592+
new LoadVIDPIDSpecificPreferences().load(p);
593+
591594
return p;
592595
}
593596

0 commit comments

Comments
 (0)
Please sign in to comment.