mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +03:00
Added warning for uncertified boards
This commit is contained in:
@ -29,18 +29,27 @@
|
||||
|
||||
package cc.arduino.packages.discoverers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import cc.arduino.packages.BoardPort;
|
||||
import cc.arduino.packages.Discovery;
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.Platform;
|
||||
import processing.app.Serial;
|
||||
import processing.app.debug.TargetBoard;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import cc.arduino.packages.BoardPort;
|
||||
import cc.arduino.packages.Discovery;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
public class SerialDiscovery implements Discovery {
|
||||
|
||||
static {
|
||||
//makes transifex happy
|
||||
_("Uncertified");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BoardPort> discovery() {
|
||||
Platform os = BaseNoGui.getPlatform();
|
||||
@ -51,16 +60,35 @@ public class SerialDiscovery implements Discovery {
|
||||
List<String> ports = Serial.list();
|
||||
|
||||
for (String port : ports) {
|
||||
String boardName = os.resolveDeviceAttachedTo(port, BaseNoGui.packages, devicesListOutput);
|
||||
String label = port;
|
||||
if (boardName != null)
|
||||
label += " (" + boardName + ")";
|
||||
Map<String, Object> boardData = os.resolveDeviceAttachedTo(port, BaseNoGui.packages, devicesListOutput);
|
||||
TargetBoard board = (TargetBoard) boardData.get("board");
|
||||
|
||||
BoardPort boardPort = new BoardPort();
|
||||
boardPort.setAddress(port);
|
||||
boardPort.setProtocol("serial");
|
||||
|
||||
PreferencesMap prefs = new PreferencesMap();
|
||||
prefs.put("vid", boardData.get("vid").toString());
|
||||
prefs.put("pid", boardData.get("pid").toString());
|
||||
String warningKey = "vid." + boardData.get("vid").toString() + ".warning";
|
||||
String warning = board.getPreferences().get(warningKey);
|
||||
prefs.put("warning", warning);
|
||||
|
||||
String boardName = board.getName();
|
||||
String label = port;
|
||||
if (boardName != null) {
|
||||
if (warning != null) {
|
||||
label += " (" + boardName + " - " + _(warning) + ")";
|
||||
} else {
|
||||
label += " (" + boardName + ")";
|
||||
}
|
||||
}
|
||||
boardPort.setBoardName(boardName);
|
||||
boardPort.setLabel(label);
|
||||
|
||||
|
||||
boardPort.setPrefs(prefs);
|
||||
|
||||
res.add(boardPort);
|
||||
}
|
||||
return res;
|
||||
|
@ -24,6 +24,7 @@ package processing.app;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -135,7 +136,7 @@ public class Platform {
|
||||
}
|
||||
}
|
||||
|
||||
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages, String devicesListOutput) {
|
||||
public Map<String, Object> resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages, String devicesListOutput) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -143,17 +144,21 @@ public class Platform {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String resolveDeviceByVendorIdProductId(Map<String, TargetPackage> packages, String readVIDPID) {
|
||||
protected Map<String, Object> resolveDeviceByVendorIdProductId(Map<String, TargetPackage> packages, String readVIDPID) {
|
||||
for (TargetPackage targetPackage : packages.values()) {
|
||||
for (TargetPlatform targetPlatform : targetPackage.getPlatforms().values()) {
|
||||
for (TargetBoard board : targetPlatform.getBoards().values()) {
|
||||
List<String> vids = new LinkedList<String>(board.getPreferences().subTree("vid").values());
|
||||
List<String> vids = new LinkedList<String>(board.getPreferences().subTree("vid", 1).values());
|
||||
if (!vids.isEmpty()) {
|
||||
List<String> pids = new LinkedList<String>(board.getPreferences().subTree("pid").values());
|
||||
for (int i = 0; i< vids.size(); i++) {
|
||||
List<String> pids = new LinkedList<String>(board.getPreferences().subTree("pid", 1).values());
|
||||
for (int i = 0; i < vids.size(); i++) {
|
||||
String vidPid = vids.get(i) + "_" + pids.get(i);
|
||||
if (vidPid.toUpperCase().equals(readVIDPID)) {
|
||||
return board.getName();
|
||||
Map<String, Object> boardData = new HashMap<String, Object>();
|
||||
boardData.put("board", board);
|
||||
boardData.put("vid", vids.get(i));
|
||||
boardData.put("pid", pids.get(i));
|
||||
return boardData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -222,12 +222,21 @@ public class PreferencesMap extends LinkedHashMap<String, String> {
|
||||
* @return
|
||||
*/
|
||||
public PreferencesMap subTree(String parent) {
|
||||
return subTree(parent, -1);
|
||||
}
|
||||
|
||||
public PreferencesMap subTree(String parent, int sublevels) {
|
||||
PreferencesMap res = new PreferencesMap();
|
||||
parent += ".";
|
||||
int parentLen = parent.length();
|
||||
for (String key : keySet()) {
|
||||
if (key.startsWith(parent))
|
||||
res.put(key.substring(parentLen), get(key));
|
||||
if (key.startsWith(parent)) {
|
||||
String newKey = key.substring(parentLen);
|
||||
int keySubLevels = newKey.split("\\.").length;
|
||||
if (sublevels == -1 || keySubLevels == sublevels) {
|
||||
res.put(newKey, get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ public class Platform extends processing.app.Platform {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages, String devicesListOutput) {
|
||||
public Map<String, Object> resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages, String devicesListOutput) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Executor executor = new ExternalProcessExecutor(baos);
|
||||
|
||||
|
@ -210,7 +210,7 @@ public class Platform extends processing.app.Platform {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages, String devicesListOutput) {
|
||||
public Map<String, Object> resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages, String devicesListOutput) {
|
||||
if (devicesListOutput == null) {
|
||||
return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput);
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ public class Platform extends processing.app.Platform {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages, String devicesListOutput) {
|
||||
public Map<String, Object> resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages, String devicesListOutput) {
|
||||
if (devicesListOutput == null) {
|
||||
return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput);
|
||||
}
|
||||
|
Reference in New Issue
Block a user