diff --git a/arduino-core/src/cc/arduino/LoadVIDPIDSpecificPreferences.java b/arduino-core/src/cc/arduino/LoadVIDPIDSpecificPreferences.java new file mode 100644 index 000000000..09a99d11a --- /dev/null +++ b/arduino-core/src/cc/arduino/LoadVIDPIDSpecificPreferences.java @@ -0,0 +1,68 @@ +/* + * This file is part of Arduino. + * + * Copyright 2015 Arduino LLC (http://www.arduino.cc/) + * + * Arduino is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As a special exception, you may use this file as part of a free software + * library without restriction. Specifically, if other files instantiate + * templates or use macros or inline functions from this file, or you compile + * this file and link it with other files to produce an executable, this + * file does not by itself cause the resulting executable to be covered by + * the GNU General Public License. This exception does not however + * invalidate any other reasons why the executable file might be covered by + * the GNU General Public License. + */ + +package cc.arduino; + +import cc.arduino.packages.BoardPort; +import processing.app.BaseNoGui; +import processing.app.PreferencesData; +import processing.app.helpers.PreferencesMap; + +import java.util.Map; +import java.util.Optional; + +public class LoadVIDPIDSpecificPreferences { + + public void load(PreferencesMap prefs) { + BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port")); + if (boardPort == null) { + return; + } + + int VIDPIDIndex = findVIDPIDIndex(prefs, boardPort.getPrefs().get("vid").toUpperCase(), boardPort.getPrefs().get("pid").toUpperCase()); + if (VIDPIDIndex < 0) { + return; + } + + prefs.putAll(prefs.subTree("vid." + VIDPIDIndex)); + } + + private int findVIDPIDIndex(PreferencesMap preferences, String vid, String pid) { + Optional vidPid = preferences.subTree("vid").entrySet().stream() + .filter(keyValue -> !keyValue.getKey().contains(".")) + .filter(keyValue -> vid.equals(keyValue.getValue().toUpperCase()) && pid.equals(preferences.get("pid." + keyValue.getKey()).toUpperCase())) + .map(Map.Entry::getKey) + .map(Integer::valueOf) + .findFirst(); + + return vidPid.orElse(-1); + } + +} + diff --git a/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java b/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java index dc8cf8f67..8470eb66d 100644 --- a/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java +++ b/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java @@ -28,6 +28,7 @@ package cc.arduino.packages.uploaders; import cc.arduino.packages.Uploader; import processing.app.*; +import cc.arduino.LoadVIDPIDSpecificPreferences; import processing.app.debug.RunnerException; import processing.app.debug.TargetPlatform; import processing.app.helpers.OSUtils; @@ -343,6 +344,8 @@ public class SerialUploader extends Uploader { prefs.put("bootloader.verbose", prefs.getOrExcept("bootloader.params.quiet")); } + new LoadVIDPIDSpecificPreferences().load(prefs); + String pattern = prefs.getOrExcept("erase.pattern"); String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true); if (!executeUploadCommand(cmd)) diff --git a/arduino-core/src/processing/app/debug/Compiler.java b/arduino-core/src/processing/app/debug/Compiler.java index a3a42487f..ad1cb914f 100644 --- a/arduino-core/src/processing/app/debug/Compiler.java +++ b/arduino-core/src/processing/app/debug/Compiler.java @@ -24,6 +24,7 @@ package processing.app.debug; import cc.arduino.Constants; +import cc.arduino.LoadVIDPIDSpecificPreferences; import cc.arduino.MyStreamPumper; import cc.arduino.contributions.packages.ContributedPlatform; import cc.arduino.contributions.packages.ContributedTool; @@ -536,7 +537,7 @@ public class Compiler implements MessageConsumer { private PreferencesMap createBuildPreferences(String _buildPath, String _primaryClassName) throws RunnerException { - + if (BaseNoGui.getBoardPreferences() == null) { RunnerException re = new RunnerException( tr("No board selected; please choose a board from the Tools > Board menu.")); @@ -561,7 +562,7 @@ public class Compiler implements MessageConsumer { throw re; } } - + // Merge all the global preference configuration in order of priority PreferencesMap buildPref = new PreferencesMap(); buildPref.putAll(PreferencesData.getMap()); @@ -579,7 +580,7 @@ public class Compiler implements MessageConsumer { buildPref.put("build.path", _buildPath); buildPref.put("build.project_name", _primaryClassName); buildPref.put("build.arch", targetPlatform.getId().toUpperCase()); - + // Platform.txt should define its own compiler.path. For // compatibility with earlier 1.5 versions, we define a (ugly, // avr-specific) default for it, but this should be removed at some @@ -603,7 +604,7 @@ public class Compiler implements MessageConsumer { coreFolder = new File(coreFolder, core); buildPref.put("build.core", core); buildPref.put("build.core.path", coreFolder.getAbsolutePath()); - + // System Folder File systemFolder = referencePlatform.getFolder(); systemFolder = new File(systemFolder, "system"); @@ -648,13 +649,13 @@ public class Compiler implements MessageConsumer { .collect(Collectors.toList()); buildPref.entrySet().stream() - .filter(entry -> { - return unsetPrefs.stream() - .filter(unsetPrefEntry -> entry.getValue().contains(unsetPrefEntry.getKey())) - .count() > 0; - }) + .filter(entry -> unsetPrefs.stream() + .filter(unsetPrefEntry -> entry.getValue().contains(unsetPrefEntry.getKey())) + .count() > 0) .forEach(invalidEntry -> buildPref.put(invalidEntry.getKey(), "")); + new LoadVIDPIDSpecificPreferences().load(buildPref); + return buildPref; }