1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-29 10:24:12 +01:00

Added support to VID+PID specific build properties

This commit is contained in:
Federico Fissore 2015-08-26 16:05:10 +02:00
parent 64cee7bbbc
commit f605d1d99b
3 changed files with 81 additions and 9 deletions

View File

@ -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<Integer> 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);
}
}

View File

@ -28,6 +28,7 @@ package cc.arduino.packages.uploaders;
import cc.arduino.packages.Uploader; import cc.arduino.packages.Uploader;
import processing.app.*; import processing.app.*;
import cc.arduino.LoadVIDPIDSpecificPreferences;
import processing.app.debug.RunnerException; import processing.app.debug.RunnerException;
import processing.app.debug.TargetPlatform; import processing.app.debug.TargetPlatform;
import processing.app.helpers.OSUtils; import processing.app.helpers.OSUtils;
@ -343,6 +344,8 @@ public class SerialUploader extends Uploader {
prefs.put("bootloader.verbose", prefs.getOrExcept("bootloader.params.quiet")); prefs.put("bootloader.verbose", prefs.getOrExcept("bootloader.params.quiet"));
} }
new LoadVIDPIDSpecificPreferences().load(prefs);
String pattern = prefs.getOrExcept("erase.pattern"); String pattern = prefs.getOrExcept("erase.pattern");
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true); String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
if (!executeUploadCommand(cmd)) if (!executeUploadCommand(cmd))

View File

@ -24,6 +24,7 @@
package processing.app.debug; package processing.app.debug;
import cc.arduino.Constants; import cc.arduino.Constants;
import cc.arduino.LoadVIDPIDSpecificPreferences;
import cc.arduino.MyStreamPumper; import cc.arduino.MyStreamPumper;
import cc.arduino.contributions.packages.ContributedPlatform; import cc.arduino.contributions.packages.ContributedPlatform;
import cc.arduino.contributions.packages.ContributedTool; import cc.arduino.contributions.packages.ContributedTool;
@ -648,13 +649,13 @@ public class Compiler implements MessageConsumer {
.collect(Collectors.toList()); .collect(Collectors.toList());
buildPref.entrySet().stream() buildPref.entrySet().stream()
.filter(entry -> { .filter(entry -> unsetPrefs.stream()
return unsetPrefs.stream() .filter(unsetPrefEntry -> entry.getValue().contains(unsetPrefEntry.getKey()))
.filter(unsetPrefEntry -> entry.getValue().contains(unsetPrefEntry.getKey())) .count() > 0)
.count() > 0;
})
.forEach(invalidEntry -> buildPref.put(invalidEntry.getKey(), "")); .forEach(invalidEntry -> buildPref.put(invalidEntry.getKey(), ""));
new LoadVIDPIDSpecificPreferences().load(buildPref);
return buildPref; return buildPref;
} }