Skip to content

Commit f605d1d

Browse files
author
Federico Fissore
committed
Added support to VID+PID specific build properties
1 parent 64cee7b commit f605d1d

File tree

3 files changed

+81
-9
lines changed

3 files changed

+81
-9
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: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package processing.app.debug;
2525

2626
import cc.arduino.Constants;
27+
import cc.arduino.LoadVIDPIDSpecificPreferences;
2728
import cc.arduino.MyStreamPumper;
2829
import cc.arduino.contributions.packages.ContributedPlatform;
2930
import cc.arduino.contributions.packages.ContributedTool;
@@ -536,7 +537,7 @@ private void adviseDuplicateLibraries() {
536537
private PreferencesMap createBuildPreferences(String _buildPath,
537538
String _primaryClassName)
538539
throws RunnerException {
539-
540+
540541
if (BaseNoGui.getBoardPreferences() == null) {
541542
RunnerException re = new RunnerException(
542543
tr("No board selected; please choose a board from the Tools > Board menu."));
@@ -561,7 +562,7 @@ private PreferencesMap createBuildPreferences(String _buildPath,
561562
throw re;
562563
}
563564
}
564-
565+
565566
// Merge all the global preference configuration in order of priority
566567
PreferencesMap buildPref = new PreferencesMap();
567568
buildPref.putAll(PreferencesData.getMap());
@@ -579,7 +580,7 @@ private PreferencesMap createBuildPreferences(String _buildPath,
579580
buildPref.put("build.path", _buildPath);
580581
buildPref.put("build.project_name", _primaryClassName);
581582
buildPref.put("build.arch", targetPlatform.getId().toUpperCase());
582-
583+
583584
// Platform.txt should define its own compiler.path. For
584585
// compatibility with earlier 1.5 versions, we define a (ugly,
585586
// avr-specific) default for it, but this should be removed at some
@@ -603,7 +604,7 @@ private PreferencesMap createBuildPreferences(String _buildPath,
603604
coreFolder = new File(coreFolder, core);
604605
buildPref.put("build.core", core);
605606
buildPref.put("build.core.path", coreFolder.getAbsolutePath());
606-
607+
607608
// System Folder
608609
File systemFolder = referencePlatform.getFolder();
609610
systemFolder = new File(systemFolder, "system");
@@ -648,13 +649,13 @@ private PreferencesMap createBuildPreferences(String _buildPath,
648649
.collect(Collectors.toList());
649650

650651
buildPref.entrySet().stream()
651-
.filter(entry -> {
652-
return unsetPrefs.stream()
653-
.filter(unsetPrefEntry -> entry.getValue().contains(unsetPrefEntry.getKey()))
654-
.count() > 0;
655-
})
652+
.filter(entry -> unsetPrefs.stream()
653+
.filter(unsetPrefEntry -> entry.getValue().contains(unsetPrefEntry.getKey()))
654+
.count() > 0)
656655
.forEach(invalidEntry -> buildPref.put(invalidEntry.getKey(), ""));
657656

657+
new LoadVIDPIDSpecificPreferences().load(buildPref);
658+
658659
return buildPref;
659660
}
660661

0 commit comments

Comments
 (0)