mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-13 12:05:21 +02:00
Arduino "menus" and stuff needed for ESP8266.
Change-Id: Ia275d697cb08b393445727a08768ca8d451c7537
This commit is contained in:
parent
daf1be845c
commit
a887378f70
16 changed files with 505 additions and 151 deletions
|
@ -64,7 +64,7 @@ public class ArduinoProjectGenerator {
|
|||
|
||||
IBuildConfiguration config = project.getBuildConfig("uno"); //$NON-NLS-1$
|
||||
ArduinoBuildConfiguration arduinoConfig = config.getAdapter(ArduinoBuildConfiguration.class);
|
||||
ArduinoBoard board = ArduinoManager.instance.getBoard("Arduino Uno", "Arduino AVR Boards", "arduino"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
ArduinoBoard board = ArduinoManager.instance.getBoard("Arduino/Genuino Uno", "Arduino AVR Boards", "arduino"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
arduinoConfig.setBoard(board);
|
||||
|
||||
// Generate files
|
||||
|
|
|
@ -8,11 +8,13 @@
|
|||
package org.eclipse.cdt.arduino.core.internal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
|
||||
public class HierarchicalProperties {
|
||||
|
||||
private String value;
|
||||
|
@ -52,7 +54,7 @@ public class HierarchicalProperties {
|
|||
|
||||
public void putProperty(String qualifiedKey, String value) {
|
||||
if (children == null) {
|
||||
children = new HashMap<>();
|
||||
children = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
int i = qualifiedKey.indexOf('.');
|
||||
|
@ -61,8 +63,8 @@ public class HierarchicalProperties {
|
|||
if (child == null) {
|
||||
child = new HierarchicalProperties();
|
||||
children.put(qualifiedKey, child);
|
||||
child.setValue(value);
|
||||
}
|
||||
child.setValue(value);
|
||||
} else {
|
||||
String key = qualifiedKey.substring(0, i);
|
||||
HierarchicalProperties child = children.get(key);
|
||||
|
@ -76,6 +78,27 @@ public class HierarchicalProperties {
|
|||
}
|
||||
|
||||
public String getValue() {
|
||||
if (value == null) {
|
||||
// Try a platform child
|
||||
String platName = null;
|
||||
switch (Platform.getOS()) {
|
||||
case Platform.OS_WIN32:
|
||||
platName = "windows"; //$NON-NLS-1$
|
||||
break;
|
||||
case Platform.OS_MACOSX:
|
||||
platName = "macosx"; //$NON-NLS-1$
|
||||
break;
|
||||
case Platform.OS_LINUX:
|
||||
platName = "linux"; //$NON-NLS-1$
|
||||
break;
|
||||
}
|
||||
if (platName != null) {
|
||||
HierarchicalProperties platChild = getChild(platName);
|
||||
if (platChild != null) {
|
||||
return platChild.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -93,7 +116,7 @@ public class HierarchicalProperties {
|
|||
|
||||
public void putChild(String key, HierarchicalProperties node) {
|
||||
if (children == null) {
|
||||
children = new HashMap<>();
|
||||
children = new LinkedHashMap<>();
|
||||
}
|
||||
children.put(key, node);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ import org.eclipse.cdt.arduino.core.internal.HierarchicalProperties;
|
|||
|
||||
public class ArduinoBoard {
|
||||
|
||||
public static final String MENU_QUALIFIER = "menu_"; //$NON-NLS-1$
|
||||
|
||||
private String name;
|
||||
|
||||
private String id;
|
||||
|
@ -50,10 +52,18 @@ public class ArduinoBoard {
|
|||
return properties.getProperty(key);
|
||||
}
|
||||
|
||||
public HierarchicalProperties getMenus() {
|
||||
return properties.getChild("menu"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public Properties getBoardProperties() {
|
||||
return properties.flatten();
|
||||
}
|
||||
|
||||
public Properties getMenuProperties(String id, String value) {
|
||||
return getMenus().getChild(id).getChild(value).flatten();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.arduino.core.internal.build.ArduinoBuildConfiguration;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
|
@ -178,7 +178,7 @@ public class ArduinoLibrary {
|
|||
getSources(project, sources, file.toPath(), recurse);
|
||||
}
|
||||
} else {
|
||||
if (CoreModel.isValidSourceUnitName(project, file.getName())) {
|
||||
if (ArduinoBuildConfiguration.isSource(file.getName())) {
|
||||
sources.add(file.toPath());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ public class ArduinoManager {
|
|||
}
|
||||
}
|
||||
|
||||
public List<PackageIndex> getPackageIndices() throws CoreException {
|
||||
public synchronized List<PackageIndex> getPackageIndices() throws CoreException {
|
||||
if (packageIndices == null) {
|
||||
String[] boardUrls = ArduinoPreferences.getBoardUrls().split("\n"); //$NON-NLS-1$
|
||||
packageIndices = new ArrayList<>(boardUrls.length);
|
||||
|
@ -146,7 +146,7 @@ public class ArduinoManager {
|
|||
}
|
||||
|
||||
public ArduinoBoard getBoard(String boardName, String platformName, String packageName) throws CoreException {
|
||||
for (PackageIndex index : packageIndices) {
|
||||
for (PackageIndex index : getPackageIndices()) {
|
||||
ArduinoPackage pkg = index.getPackage(packageName);
|
||||
if (pkg != null) {
|
||||
ArduinoPlatform platform = pkg.getPlatform(platformName);
|
||||
|
@ -163,7 +163,7 @@ public class ArduinoManager {
|
|||
|
||||
public List<ArduinoBoard> getBoards() throws CoreException {
|
||||
List<ArduinoBoard> boards = new ArrayList<>();
|
||||
for (PackageIndex index : packageIndices) {
|
||||
for (PackageIndex index : getPackageIndices()) {
|
||||
for (ArduinoPackage pkg : index.getPackages()) {
|
||||
for (ArduinoPlatform platform : pkg.getLatestPlatforms()) {
|
||||
boards.addAll(platform.getBoards());
|
||||
|
@ -175,7 +175,7 @@ public class ArduinoManager {
|
|||
|
||||
public List<ArduinoBoard> getInstalledBoards() throws CoreException {
|
||||
List<ArduinoBoard> boards = new ArrayList<>();
|
||||
for (PackageIndex index : packageIndices) {
|
||||
for (PackageIndex index : getPackageIndices()) {
|
||||
for (ArduinoPackage pkg : index.getPackages()) {
|
||||
for (ArduinoPlatform platform : pkg.getInstalledPlatforms()) {
|
||||
boards.addAll(platform.getBoards());
|
||||
|
@ -185,8 +185,8 @@ public class ArduinoManager {
|
|||
return boards;
|
||||
}
|
||||
|
||||
public ArduinoPackage getPackage(String packageName) {
|
||||
for (PackageIndex index : packageIndices) {
|
||||
public ArduinoPackage getPackage(String packageName) throws CoreException {
|
||||
for (PackageIndex index : getPackageIndices()) {
|
||||
ArduinoPackage pkg = index.getPackage(packageName);
|
||||
if (pkg != null) {
|
||||
return pkg;
|
||||
|
@ -195,8 +195,8 @@ public class ArduinoManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
public ArduinoTool getTool(String packageName, String toolName, String version) {
|
||||
for (PackageIndex index : packageIndices) {
|
||||
public ArduinoTool getTool(String packageName, String toolName, String version) throws CoreException {
|
||||
for (PackageIndex index : getPackageIndices()) {
|
||||
ArduinoPackage pkg = index.getPackage(packageName);
|
||||
if (pkg != null) {
|
||||
ArduinoTool tool = pkg.getTool(toolName, version);
|
||||
|
|
|
@ -17,6 +17,7 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
@ -28,6 +29,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.MultiStatus;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
|
||||
public class ArduinoPlatform {
|
||||
|
@ -44,8 +46,9 @@ public class ArduinoPlatform {
|
|||
private List<ToolDependency> toolsDependencies;
|
||||
|
||||
private ArduinoPackage pkg;
|
||||
private HierarchicalProperties boardsFile;
|
||||
private HierarchicalProperties boardsProperties;
|
||||
private Properties platformProperties;
|
||||
private Map<String, String> menus = new HashMap<>();
|
||||
|
||||
void setOwner(ArduinoPackage pkg) {
|
||||
this.pkg = pkg;
|
||||
|
@ -94,28 +97,40 @@ public class ArduinoPlatform {
|
|||
}
|
||||
|
||||
public List<ArduinoBoard> getBoards() throws CoreException {
|
||||
if (isInstalled() && boardsFile == null) {
|
||||
if (isInstalled() && boardsProperties == null) {
|
||||
Properties boardProps = new Properties();
|
||||
try (Reader reader = new FileReader(getInstallPath().resolve("boards.txt").toFile())) { //$NON-NLS-1$
|
||||
boardProps.load(reader);
|
||||
} catch (IOException e) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), "Loading boards.txt", e));
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), "Loading boards.txt", e)); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
boardsFile = new HierarchicalProperties(boardProps);
|
||||
boardsProperties = new HierarchicalProperties(boardProps);
|
||||
|
||||
// Replace the boards with a real ones
|
||||
boards = new ArrayList<>();
|
||||
for (Map.Entry<String, HierarchicalProperties> entry : boardsFile.getChildren().entrySet()) {
|
||||
for (Map.Entry<String, HierarchicalProperties> entry : boardsProperties.getChildren().entrySet()) {
|
||||
if (entry.getValue().getChild("name") != null) { //$NON-NLS-1$
|
||||
// assume things with names are boards
|
||||
boards.add(new ArduinoBoard(entry.getKey(), entry.getValue()).setOwners(this));
|
||||
}
|
||||
}
|
||||
|
||||
// Build the menu
|
||||
HierarchicalProperties menuProp = boardsProperties.getChild("menu"); //$NON-NLS-1$
|
||||
if (menuProp != null) {
|
||||
for (Map.Entry<String, HierarchicalProperties> entry : menuProp.getChildren().entrySet()) {
|
||||
menus.put(entry.getKey(), entry.getValue().getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return boards;
|
||||
}
|
||||
|
||||
public HierarchicalProperties getBoardsProperties() {
|
||||
return boardsProperties;
|
||||
}
|
||||
|
||||
public ArduinoBoard getBoard(String name) throws CoreException {
|
||||
for (ArduinoBoard board : getBoards()) {
|
||||
if (name.equals(board.getName())) {
|
||||
|
@ -125,6 +140,10 @@ public class ArduinoPlatform {
|
|||
return null;
|
||||
}
|
||||
|
||||
public String getMenuText(String id) {
|
||||
return menus.get(id);
|
||||
}
|
||||
|
||||
public List<ToolDependency> getToolsDependencies() {
|
||||
return toolsDependencies;
|
||||
}
|
||||
|
@ -153,7 +172,7 @@ public class ArduinoPlatform {
|
|||
platformProperties.load(reader1);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), "Loading platform.txt", e));
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), "Loading platform.txt", e)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
return platformProperties;
|
||||
|
@ -201,17 +220,18 @@ public class ArduinoPlatform {
|
|||
}
|
||||
|
||||
// On Windows install make from equations.org
|
||||
if (Platform.getOS().equals(Platform.OS_WIN32)) {
|
||||
try {
|
||||
Path makePath = ArduinoPreferences.getArduinoHome().resolve("tools/make/make.exe");
|
||||
Path makePath = ArduinoPreferences.getArduinoHome().resolve("tools/make/make.exe"); //$NON-NLS-1$
|
||||
if (!makePath.toFile().exists()) {
|
||||
Files.createDirectories(makePath.getParent());
|
||||
URL makeUrl = new URL("ftp://ftp.equation.com/make/32/make.exe");
|
||||
URL makeUrl = new URL("ftp://ftp.equation.com/make/32/make.exe"); //$NON-NLS-1$
|
||||
Files.copy(makeUrl.openStream(), makePath);
|
||||
makePath.toFile().setExecutable(true, false);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
mstatus.add(new Status(IStatus.ERROR, Activator.getId(), "downloading make.exe", e));
|
||||
mstatus.add(new Status(IStatus.ERROR, Activator.getId(), "downloading make.exe", e)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
return mstatus != null ? mstatus : Status.OK_STATUS;
|
||||
|
|
|
@ -70,12 +70,12 @@ public class ArduinoTool {
|
|||
}
|
||||
|
||||
// No valid system
|
||||
return new Status(IStatus.ERROR, Activator.getId(), "No valid system found for " + name);
|
||||
return new Status(IStatus.ERROR, Activator.getId(), "No valid system found for " + name); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public Properties getToolProperties() {
|
||||
Properties properties = new Properties();
|
||||
properties.put("runtime.tools." + name + ".path", ArduinoBuildConfiguration.pathString(getInstallPath())); // $NON-NLS-1$ //$NON-NLS-2$
|
||||
properties.put("runtime.tools." + name + ".path", ArduinoBuildConfiguration.pathString(getInstallPath())); // $NON-NLS-1$ //$NON-NLS-1$//$NON-NLS-2$
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.util.regex.Pattern;
|
|||
import org.eclipse.cdt.arduino.core.internal.Activator;
|
||||
import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
|
||||
import org.eclipse.cdt.arduino.core.internal.ArduinoTemplateGenerator;
|
||||
import org.eclipse.cdt.arduino.core.internal.HierarchicalProperties;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoard;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoLibrary;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager;
|
||||
|
@ -30,6 +31,7 @@ import org.eclipse.cdt.arduino.core.internal.board.ArduinoTool;
|
|||
import org.eclipse.cdt.arduino.core.internal.board.ToolDependency;
|
||||
import org.eclipse.cdt.arduino.core.internal.console.ArduinoConsoleParser;
|
||||
import org.eclipse.cdt.arduino.core.internal.console.ArduinoErrorParser;
|
||||
import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
|
@ -102,12 +104,14 @@ public class ArduinoBuildConfiguration {
|
|||
}
|
||||
}
|
||||
|
||||
public static ArduinoBuildConfiguration getConfig(IProject project, ArduinoBoard board, IProgressMonitor monitor)
|
||||
throws CoreException {
|
||||
public static ArduinoBuildConfiguration getConfig(IProject project, ArduinoRemoteConnection target,
|
||||
IProgressMonitor monitor) throws CoreException {
|
||||
ArduinoBoard board = target.getBoard();
|
||||
|
||||
// return it if it exists already
|
||||
for (IBuildConfiguration config : project.getBuildConfigs()) {
|
||||
ArduinoBuildConfiguration arduinoConfig = config.getAdapter(ArduinoBuildConfiguration.class);
|
||||
if (board.equals(arduinoConfig.getBoard())) {
|
||||
if (arduinoConfig.matches(target)) {
|
||||
return arduinoConfig;
|
||||
}
|
||||
}
|
||||
|
@ -130,7 +134,7 @@ public class ArduinoBuildConfiguration {
|
|||
// set it up for the board
|
||||
IBuildConfiguration config = project.getBuildConfig(newName);
|
||||
ArduinoBuildConfiguration arduinoConfig = config.getAdapter(ArduinoBuildConfiguration.class);
|
||||
arduinoConfig.setBoard(board);
|
||||
arduinoConfig.setBoard(target);
|
||||
|
||||
return arduinoConfig;
|
||||
}
|
||||
|
@ -165,10 +169,59 @@ public class ArduinoBuildConfiguration {
|
|||
try {
|
||||
settings.flush();
|
||||
} catch (BackingStoreException e) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), "Saving preferences", e));
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), "Saving preferences", e)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
public void setBoard(ArduinoRemoteConnection target) throws CoreException {
|
||||
this.board = target.getBoard();
|
||||
|
||||
ArduinoPlatform platform = board.getPlatform();
|
||||
ArduinoPackage pkg = platform.getPackage();
|
||||
|
||||
IEclipsePreferences settings = getSettings();
|
||||
settings.put(PACKAGE_NAME, pkg.getName());
|
||||
settings.put(PLATFORM_NAME, platform.getName());
|
||||
settings.put(BOARD_NAME, board.getName());
|
||||
|
||||
HierarchicalProperties menus = board.getMenus();
|
||||
if (menus != null) {
|
||||
for (String id : menus.getChildren().keySet()) {
|
||||
String key = ArduinoBoard.MENU_QUALIFIER + id;
|
||||
String value = target.getRemoteConnection().getAttribute(key);
|
||||
if (value != null) {
|
||||
settings.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
settings.flush();
|
||||
} catch (BackingStoreException e) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), "Saving preferences", e)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
public boolean matches(ArduinoRemoteConnection target) throws CoreException {
|
||||
ArduinoBoard otherBoard = target.getBoard();
|
||||
if (!getBoard().equals(otherBoard)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IEclipsePreferences settings = getSettings();
|
||||
HierarchicalProperties menus = board.getMenus();
|
||||
if (menus != null) {
|
||||
for (String id : menus.getChildren().keySet()) {
|
||||
String key = ArduinoBoard.MENU_QUALIFIER + id;
|
||||
if (!settings.get(key, "").equals(target.getRemoteConnection().getAttribute(key))) { //$NON-NLS-1$
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public ArduinoBoard getBoard() throws CoreException {
|
||||
if (board == null) {
|
||||
IEclipsePreferences settings = getSettings();
|
||||
|
@ -182,13 +235,32 @@ public class ArduinoBuildConfiguration {
|
|||
|
||||
private Properties getProperties() throws CoreException {
|
||||
if (properties == null) {
|
||||
// Board
|
||||
ArduinoBoard board = getBoard();
|
||||
ArduinoPlatform platform = board.getPlatform();
|
||||
properties = board.getBoardProperties();
|
||||
|
||||
// Menus
|
||||
IEclipsePreferences settings = getSettings();
|
||||
HierarchicalProperties menus = board.getMenus();
|
||||
if (menus != null) {
|
||||
for (String menuId : menus.getChildren().keySet()) {
|
||||
String value = settings.get(ArduinoBoard.MENU_QUALIFIER, ""); //$NON-NLS-1$
|
||||
if (!value.isEmpty()) {
|
||||
properties.putAll(board.getMenuProperties(menuId, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Platform
|
||||
ArduinoPlatform platform = board.getPlatform();
|
||||
properties.putAll(board.getPlatform().getPlatformProperties());
|
||||
|
||||
// Tools
|
||||
for (ToolDependency toolDep : platform.getToolsDependencies()) {
|
||||
properties.putAll(toolDep.getTool().getToolProperties());
|
||||
}
|
||||
|
||||
properties.put("runtime.platform.path", platform.getInstallPath().toString()); //$NON-NLS-1$
|
||||
properties.put("runtime.ide.version", "10607"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
properties.put("build.arch", platform.getArchitecture().toUpperCase()); //$NON-NLS-1$
|
||||
properties.put("build.path", config.getName()); //$NON-NLS-1$
|
||||
|
@ -246,7 +318,7 @@ public class ArduinoBuildConfiguration {
|
|||
@Override
|
||||
public boolean visit(IResourceProxy proxy) throws CoreException {
|
||||
if (proxy.getType() == IResource.FILE) {
|
||||
if (CoreModel.isValidSourceUnitName(project, proxy.getName())) {
|
||||
if (isSource(proxy.getName())) {
|
||||
Path sourcePath = new File(proxy.requestResource().getLocationURI()).toPath();
|
||||
sourceFiles.add(pathString(projectPath.relativize(sourcePath)));
|
||||
}
|
||||
|
@ -296,7 +368,7 @@ public class ArduinoBuildConfiguration {
|
|||
File[] platformFiles = corePath.toFile().listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".cpp") || name.endsWith(".c"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
return isSource(name);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -313,6 +385,7 @@ public class ArduinoBuildConfiguration {
|
|||
|
||||
buildModel.put("recipe_cpp_o_pattern", resolveProperty("recipe.cpp.o.pattern", properties)); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buildModel.put("recipe_c_o_pattern", resolveProperty("recipe.c.o.pattern", properties)); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buildModel.put("recipe_S_o_pattern", resolveProperty("recipe.S.o.pattern", properties)); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buildModel.put("recipe_ar_pattern", resolveProperty("recipe.ar.pattern", properties)); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buildModel.put("recipe_c_combine_pattern", resolveProperty("recipe.c.combine.pattern", properties)); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
buildModel.put("recipe_objcopy_eep_pattern", resolveProperty("recipe.objcopy.eep.pattern", properties)); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
@ -324,6 +397,19 @@ public class ArduinoBuildConfiguration {
|
|||
return makeFile;
|
||||
}
|
||||
|
||||
public static boolean isSource(String filename) {
|
||||
int i = filename.lastIndexOf('.');
|
||||
String ext = filename.substring(i + 1);
|
||||
switch (ext) {
|
||||
case "cpp": //$NON-NLS-1$
|
||||
case "c": //$NON-NLS-1$
|
||||
case "S": //$NON-NLS-1$
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private String resolveProperty(String property, Properties dict) {
|
||||
String res = dict.getProperty(property);
|
||||
if (res == null) {
|
||||
|
@ -368,7 +454,7 @@ public class ArduinoBuildConfiguration {
|
|||
List<Path> toolPaths = new ArrayList<>();
|
||||
if (isWindows) {
|
||||
// Add in the tools/make directory to pick up make
|
||||
toolPaths.add(ArduinoPreferences.getArduinoHome().resolve("tools/make"));
|
||||
toolPaths.add(ArduinoPreferences.getArduinoHome().resolve("tools/make")); //$NON-NLS-1$
|
||||
}
|
||||
ArduinoBoard board = getBoard();
|
||||
ArduinoPlatform platform = board.getPlatform();
|
||||
|
@ -415,7 +501,7 @@ public class ArduinoBuildConfiguration {
|
|||
}
|
||||
|
||||
public int getMaxCodeSize() throws CoreException {
|
||||
String sizeStr = (String) getBoard().getBoardProperties().getProperty("upload.maximum_size"); //$NON-NLS-1$
|
||||
String sizeStr = (String) getProperties().getProperty("upload.maximum_size"); //$NON-NLS-1$
|
||||
return sizeStr != null ? Integer.parseInt(sizeStr) : -1;
|
||||
}
|
||||
|
||||
|
@ -424,7 +510,7 @@ public class ArduinoBuildConfiguration {
|
|||
}
|
||||
|
||||
public int getMaxDataSize() throws CoreException {
|
||||
String sizeStr = (String) getBoard().getBoardProperties().getProperty("upload.maximum_data_size"); //$NON-NLS-1$
|
||||
String sizeStr = (String) getProperties().getProperty("upload.maximum_data_size"); //$NON-NLS-1$
|
||||
return sizeStr != null ? Integer.parseInt(sizeStr) : -1;
|
||||
}
|
||||
|
||||
|
@ -433,16 +519,29 @@ public class ArduinoBuildConfiguration {
|
|||
ArduinoTool tool = board.getPlatform().getTool(toolName);
|
||||
|
||||
Properties properties = getProperties();
|
||||
properties.put("runtime.tools." + toolName + ".path", pathString(tool.getInstallPath())); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
properties.put("serial.port", serialPort); //$NON-NLS-1$
|
||||
// to make up for some cheating in the platform.txt file
|
||||
properties.put("path", "{tools." + toolName + ".path}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
properties.put("cmd.path", "{tools." + toolName + ".cmd.path}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
properties.put("config.path", "{tools." + toolName + ".config.path}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
|
||||
properties.put("upload.verbose", "{tools." + toolName + ".upload.params.quiet}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
// properties for the tool flattened
|
||||
HierarchicalProperties toolsProps = new HierarchicalProperties(getBoard().getPlatform().getPlatformProperties())
|
||||
.getChild("tools"); //$NON-NLS-1$
|
||||
if (toolsProps != null) {
|
||||
HierarchicalProperties toolProps = toolsProps.getChild(toolName);
|
||||
if (toolProps != null) {
|
||||
properties.putAll(toolProps.flatten());
|
||||
}
|
||||
}
|
||||
|
||||
String command = resolveProperty("tools." + toolName + ".upload.pattern", properties); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// TODO make this a preference
|
||||
properties.put("upload.verbose", properties.getProperty("upload.params.verbose", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
|
||||
// TODO needed this for esptool
|
||||
properties.put("upload.resetmethod", "ck"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
String command = resolveProperty("upload.pattern", properties); //$NON-NLS-1$
|
||||
if (command == null) {
|
||||
return new String[] { "command not specified" }; //$NON-NLS-1$
|
||||
}
|
||||
if (isWindows) {
|
||||
return splitCommand(command);
|
||||
} else {
|
||||
|
@ -475,7 +574,7 @@ public class ArduinoBuildConfiguration {
|
|||
public static String pathString(Path path) {
|
||||
String str = path.toString();
|
||||
if (isWindows) {
|
||||
str = str.replaceAll("\\\\", "/");
|
||||
str = str.replaceAll("\\\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
@ -540,13 +639,13 @@ public class ArduinoBuildConfiguration {
|
|||
includePath.toArray(new String[includePath.size()]));
|
||||
return scannerInfo;
|
||||
} catch (IOException e) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), "Compiler built-ins", e));
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), "Compiler built-ins", e)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
private String[] splitCommand(String command) {
|
||||
// TODO deal with quotes properly, for now just strip
|
||||
return command.replaceAll("\"", "").split("\\s+");
|
||||
return command.replaceAll("\"", "").split("\\s+"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
|
||||
public ArduinoConsoleParser[] getBuildConsoleParsers() {
|
||||
|
|
|
@ -14,7 +14,6 @@ import java.io.IOException;
|
|||
|
||||
import org.eclipse.cdt.arduino.core.internal.Activator;
|
||||
import org.eclipse.cdt.arduino.core.internal.Messages;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoard;
|
||||
import org.eclipse.cdt.arduino.core.internal.build.ArduinoBuildConfiguration;
|
||||
import org.eclipse.cdt.arduino.core.internal.console.ArduinoConsoleService;
|
||||
import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection;
|
||||
|
@ -50,11 +49,10 @@ public class ArduinoLaunchConfigurationDelegate extends LaunchConfigurationDeleg
|
|||
IRemoteConnection target = getTarget(configuration);
|
||||
if (target != null) {
|
||||
ArduinoRemoteConnection arduinoTarget = target.getService(ArduinoRemoteConnection.class);
|
||||
ArduinoBoard targetBoard = arduinoTarget.getBoard();
|
||||
|
||||
// 1. make sure proper build config is set active
|
||||
IProject project = configuration.getMappedResources()[0].getProject();
|
||||
ArduinoBuildConfiguration arduinoConfig = ArduinoBuildConfiguration.getConfig(project, targetBoard,
|
||||
ArduinoBuildConfiguration arduinoConfig = ArduinoBuildConfiguration.getConfig(project, arduinoTarget,
|
||||
monitor);
|
||||
arduinoConfig.setActive(monitor);
|
||||
}
|
||||
|
@ -89,7 +87,7 @@ public class ArduinoLaunchConfigurationDelegate extends LaunchConfigurationDeleg
|
|||
|
||||
// The build config
|
||||
ArduinoBuildConfiguration arduinoConfig = ArduinoBuildConfiguration.getConfig(project,
|
||||
arduinoTarget.getBoard(), monitor);
|
||||
arduinoTarget, monitor);
|
||||
String[] uploadCmd = arduinoConfig.getUploadCommand(arduinoTarget.getPortName());
|
||||
|
||||
// If opened, temporarily close the connection so we can use
|
||||
|
@ -99,6 +97,14 @@ public class ArduinoLaunchConfigurationDelegate extends LaunchConfigurationDeleg
|
|||
arduinoTarget.pause();
|
||||
}
|
||||
|
||||
StringBuffer cmdStr = new StringBuffer(uploadCmd[0]);
|
||||
for (int i = 1; i < uploadCmd.length; ++i) {
|
||||
cmdStr.append(' ');
|
||||
cmdStr.append(uploadCmd[i]);
|
||||
}
|
||||
cmdStr.append('\n');
|
||||
consoleService.writeOutput(cmdStr.toString());
|
||||
|
||||
// Run the process and capture the results in the console
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(uploadCmd)
|
||||
.directory(arduinoConfig.getBuildDirectory());
|
||||
|
|
|
@ -31,10 +31,10 @@ public class ArduinoRemoteConnection
|
|||
implements IRemoteConnectionPropertyService, IRemoteCommandShellService, IRemoteConnectionChangeListener {
|
||||
|
||||
public static final String TYPE_ID = "org.eclipse.cdt.arduino.core.connectionType"; //$NON-NLS-1$
|
||||
public static final String PORT_NAME = "ardiuno.portname"; //$NON-NLS-1$
|
||||
public static final String PACKAGE_NAME = "packageName"; //$NON-NLS-1$
|
||||
public static final String PLATFORM_NAME = "platformName"; //$NON-NLS-1$
|
||||
public static final String BOARD_NAME = "boardName"; //$NON-NLS-1$
|
||||
public static final String PORT_NAME = "arduinoPortName"; //$NON-NLS-1$
|
||||
public static final String PACKAGE_NAME = "arduinoPackageName"; //$NON-NLS-1$
|
||||
public static final String PLATFORM_NAME = "arduinoPlatformName"; //$NON-NLS-1$
|
||||
public static final String BOARD_NAME = "arduinoBoardName"; //$NON-NLS-1$
|
||||
|
||||
private final IRemoteConnection remoteConnection;
|
||||
private SerialPort serialPort;
|
||||
|
|
|
@ -24,6 +24,10 @@ PLATFORM_OBJS = \
|
|||
<#if c>
|
||||
${build_path}/platform/${c?groups[1]}.o \
|
||||
</#if>
|
||||
<#assign S = file?matches("${platform_path}/(.*)\\.S")>
|
||||
<#if S>
|
||||
${build_path}/platform/${S?groups[1]}.S.o \
|
||||
</#if>
|
||||
</#list>
|
||||
|
||||
LIBRARIES_OBJS = \
|
||||
|
@ -83,6 +87,14 @@ ${build_path}/platform/${c?groups[1]}.o: ${file}
|
|||
${recipe_c_o_pattern}
|
||||
${recipe_ar_pattern}
|
||||
|
||||
</#if>
|
||||
<#assign S = file?matches("${platform_path}/(.*)\\.S")>
|
||||
<#if S>
|
||||
${build_path}/platform/${S?groups[1]}.S.o: ${file}
|
||||
@$(call mymkdir,$(dir $@))
|
||||
${recipe_S_o_pattern}
|
||||
${recipe_ar_pattern}
|
||||
|
||||
</#if>
|
||||
</#list>
|
||||
|
||||
|
|
|
@ -44,9 +44,10 @@
|
|||
name="Arduino"
|
||||
selectionFilter="single">
|
||||
<enabledWhen>
|
||||
<adapt
|
||||
type="org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection">
|
||||
</adapt>
|
||||
<test
|
||||
forcePluginActivation="false"
|
||||
property="org.eclipse.cdt.arduino.ui.isArduinoRemote">
|
||||
</test>
|
||||
</enabledWhen>
|
||||
</page>
|
||||
<page
|
||||
|
@ -96,4 +97,27 @@
|
|||
name="Boards">
|
||||
</page>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.perspectiveExtensions">
|
||||
<perspectiveExtension
|
||||
targetID="org.eclipse.cdt.ui.CPerspective">
|
||||
<view
|
||||
id="org.eclipse.remote.ui.view.connections"
|
||||
minimized="false"
|
||||
ratio="0.75"
|
||||
relationship="bottom"
|
||||
relative="org.eclipse.ui.navigator.ProjectExplorer">
|
||||
</view>
|
||||
</perspectiveExtension>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.core.expressions.propertyTesters">
|
||||
<propertyTester
|
||||
class="org.eclipse.cdt.arduino.ui.internal.project.ArduinoPropertyTester"
|
||||
id="temporaryRemoteTester"
|
||||
namespace="org.eclipse.cdt.arduino.ui"
|
||||
properties="isArduinoRemote"
|
||||
type="org.eclipse.remote.core.IRemoteConnection">
|
||||
</propertyTester>
|
||||
</extension>
|
||||
</plugin>
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package org.eclipse.cdt.arduino.ui.internal.project;
|
||||
|
||||
import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection;
|
||||
import org.eclipse.core.expressions.PropertyTester;
|
||||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
|
||||
public class ArduinoPropertyTester extends PropertyTester {
|
||||
|
||||
@Override
|
||||
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
|
||||
if (receiver instanceof IRemoteConnection) {
|
||||
IRemoteConnection remote = (IRemoteConnection) receiver;
|
||||
return remote.hasService(ArduinoRemoteConnection.class);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,208 @@
|
|||
package org.eclipse.cdt.arduino.ui.internal.remote;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.cdt.arduino.core.internal.HierarchicalProperties;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoard;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoPackage;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoPlatform;
|
||||
import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection;
|
||||
import org.eclipse.cdt.arduino.ui.internal.Activator;
|
||||
import org.eclipse.cdt.arduino.ui.internal.Messages;
|
||||
import org.eclipse.cdt.serial.SerialPort;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.remote.core.IRemoteConnectionWorkingCopy;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
|
||||
public class BoardPropertyControl extends Composite {
|
||||
|
||||
private Combo portCombo;
|
||||
private String[] portNames;
|
||||
private String portName;
|
||||
|
||||
private Combo boardCombo;
|
||||
private ArduinoBoard[] boards;
|
||||
private ArduinoBoard board;
|
||||
|
||||
private List<SelectionListener> listeners = Collections.synchronizedList(new ArrayList<SelectionListener>());
|
||||
private List<Control> menuControls = new ArrayList<>();
|
||||
|
||||
public BoardPropertyControl(Composite parent, int style) {
|
||||
super(parent, style);
|
||||
setLayout(new GridLayout(2, false));
|
||||
|
||||
Label portLabel = new Label(this, SWT.NONE);
|
||||
portLabel.setText(Messages.NewArduinoTargetWizardPage_4);
|
||||
|
||||
portCombo = new Combo(this, SWT.READ_ONLY);
|
||||
portCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
try {
|
||||
portNames = SerialPort.list();
|
||||
} catch (IOException e) {
|
||||
portNames = new String[0];
|
||||
Activator.log(e);
|
||||
}
|
||||
for (String portName : portNames) {
|
||||
portCombo.add(portName);
|
||||
}
|
||||
if (portNames.length > 0) {
|
||||
portCombo.select(0);
|
||||
portName = portNames[0];
|
||||
}
|
||||
portCombo.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
int index = portCombo.getSelectionIndex();
|
||||
portName = index < 0 ? null : portNames[index];
|
||||
fireSelection();
|
||||
}
|
||||
});
|
||||
|
||||
Label boardLabel = new Label(this, SWT.NONE);
|
||||
boardLabel.setText(Messages.ArduinoTargetPropertyPage_2);
|
||||
|
||||
boardCombo = new Combo(this, SWT.READ_ONLY);
|
||||
boardCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
|
||||
try {
|
||||
List<ArduinoBoard> boardList = ArduinoManager.instance.getInstalledBoards();
|
||||
Collections.sort(boardList, new Comparator<ArduinoBoard>() {
|
||||
@Override
|
||||
public int compare(ArduinoBoard o1, ArduinoBoard o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
});
|
||||
boards = boardList.toArray(new ArduinoBoard[boardList.size()]);
|
||||
|
||||
for (ArduinoBoard board : boards) {
|
||||
boardCombo.add(board.getName());
|
||||
}
|
||||
|
||||
boardCombo.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
boardChanged();
|
||||
fireSelection();
|
||||
}
|
||||
});
|
||||
|
||||
if (boards.length > 0) {
|
||||
// TODO use preference to remember the last selected board
|
||||
boardCombo.select(0);
|
||||
board = boards[0];
|
||||
updateBoardMenu();
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getPortName() {
|
||||
return portName;
|
||||
}
|
||||
|
||||
public ArduinoBoard getSelectedBoard() {
|
||||
return board;
|
||||
}
|
||||
|
||||
public void addSelectionListener(SelectionListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
private void updateBoardMenu() {
|
||||
HierarchicalProperties menus = board.getMenus();
|
||||
if (menus != null) {
|
||||
for (Entry<String, HierarchicalProperties> menuEntry : menus.getChildren().entrySet()) {
|
||||
Label label = new Label(this, SWT.NONE);
|
||||
label.setText(board.getPlatform().getMenuText(menuEntry.getKey()) + ':');
|
||||
label.setData(menuEntry.getKey());
|
||||
menuControls.add(label);
|
||||
|
||||
Combo combo = new Combo(this, SWT.READ_ONLY);
|
||||
combo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
|
||||
menuControls.add(combo);
|
||||
|
||||
List<String> ids = new ArrayList<>();
|
||||
for (Entry<String, HierarchicalProperties> valueEntry : menuEntry.getValue().getChildren().entrySet()) {
|
||||
String value = valueEntry.getValue().getValue();
|
||||
if (value != null) {
|
||||
combo.add(value);
|
||||
ids.add(valueEntry.getKey());
|
||||
}
|
||||
}
|
||||
combo.setData(ids);
|
||||
combo.select(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void boardChanged() {
|
||||
int index = boardCombo.getSelectionIndex();
|
||||
ArduinoBoard newBoard = index < 0 ? null : boards[index];
|
||||
if (newBoard != board) {
|
||||
// Clear out old menus
|
||||
for (Control control : menuControls) {
|
||||
control.dispose();
|
||||
}
|
||||
menuControls.clear();
|
||||
|
||||
board = newBoard;
|
||||
updateBoardMenu();
|
||||
|
||||
layout();
|
||||
getShell().pack();
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
private void fireSelection() {
|
||||
for (SelectionListener listener : listeners) {
|
||||
Event event = new Event();
|
||||
event.widget = this;
|
||||
listener.widgetSelected(new SelectionEvent(event));
|
||||
}
|
||||
}
|
||||
|
||||
public void apply(IRemoteConnectionWorkingCopy workingCopy) {
|
||||
workingCopy.setAttribute(ArduinoRemoteConnection.PORT_NAME, portName);
|
||||
|
||||
workingCopy.setAttribute(ArduinoRemoteConnection.BOARD_NAME, board.getName());
|
||||
|
||||
ArduinoPlatform platform = board.getPlatform();
|
||||
workingCopy.setAttribute(ArduinoRemoteConnection.PLATFORM_NAME, platform.getName());
|
||||
|
||||
ArduinoPackage pkg = platform.getPackage();
|
||||
workingCopy.setAttribute(ArduinoRemoteConnection.PACKAGE_NAME, pkg.getName());
|
||||
|
||||
String key = null;
|
||||
for (Control control : menuControls) {
|
||||
if (control instanceof Label) {
|
||||
key = (String) control.getData();
|
||||
} else if (control instanceof Combo) {
|
||||
Combo combo = (Combo) control;
|
||||
@SuppressWarnings("unchecked")
|
||||
String value = ((List<String>) combo.getData()).get(combo.getSelectionIndex());
|
||||
|
||||
if (key != null) {
|
||||
workingCopy.setAttribute(ArduinoBoard.MENU_QUALIFIER + key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -2,9 +2,6 @@ package org.eclipse.cdt.arduino.ui.internal.remote;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoard;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoPackage;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoPlatform;
|
||||
import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection;
|
||||
import org.eclipse.cdt.arduino.ui.internal.Activator;
|
||||
import org.eclipse.jface.wizard.Wizard;
|
||||
|
@ -31,15 +28,7 @@ public class NewArduinoTargetWizard extends Wizard implements IRemoteUIConnectio
|
|||
return false;
|
||||
}
|
||||
|
||||
workingCopy.setAttribute(ArduinoRemoteConnection.PORT_NAME, page.portName);
|
||||
|
||||
ArduinoBoard board = page.board;
|
||||
workingCopy.setAttribute(ArduinoRemoteConnection.BOARD_NAME, board.getName());
|
||||
ArduinoPlatform platform = board.getPlatform();
|
||||
workingCopy.setAttribute(ArduinoRemoteConnection.PLATFORM_NAME, platform.getName());
|
||||
ArduinoPackage pkg = platform.getPackage();
|
||||
workingCopy.setAttribute(ArduinoRemoteConnection.PACKAGE_NAME, pkg.getName());
|
||||
|
||||
page.performFinish(workingCopy);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,8 @@
|
|||
package org.eclipse.cdt.arduino.ui.internal.remote;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoard;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager;
|
||||
import org.eclipse.cdt.arduino.ui.internal.Activator;
|
||||
import org.eclipse.cdt.arduino.ui.internal.Messages;
|
||||
import org.eclipse.cdt.serial.SerialPort;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.wizard.WizardPage;
|
||||
import org.eclipse.remote.core.IRemoteConnectionWorkingCopy;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.KeyEvent;
|
||||
import org.eclipse.swt.events.KeyListener;
|
||||
|
@ -19,7 +10,6 @@ import org.eclipse.swt.events.SelectionAdapter;
|
|||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
@ -29,13 +19,7 @@ public class NewArduinoTargetWizardPage extends WizardPage {
|
|||
String name;
|
||||
private Text nameText;
|
||||
|
||||
String portName;
|
||||
private String[] portNames;
|
||||
private Combo portCombo;
|
||||
|
||||
ArduinoBoard board;
|
||||
private ArduinoBoard[] boards;
|
||||
private Combo boardCombo;
|
||||
BoardPropertyControl boardControl;
|
||||
|
||||
public NewArduinoTargetWizardPage() {
|
||||
super("NewArduinoTargetPage"); //$NON-NLS-1$
|
||||
|
@ -46,17 +30,22 @@ public class NewArduinoTargetWizardPage extends WizardPage {
|
|||
@Override
|
||||
public void createControl(Composite parent) {
|
||||
Composite comp = new Composite(parent, SWT.NONE);
|
||||
comp.setLayout(new GridLayout(2, false));
|
||||
comp.setLayout(new GridLayout());
|
||||
|
||||
Label nameLabel = new Label(comp, SWT.NONE);
|
||||
Composite nameComp = new Composite(comp, SWT.NONE);
|
||||
nameComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
|
||||
nameComp.setLayout(new GridLayout(2, false));
|
||||
|
||||
Label nameLabel = new Label(nameComp, SWT.NONE);
|
||||
nameLabel.setText(Messages.NewArduinoTargetWizardPage_2);
|
||||
|
||||
nameText = new Text(comp, SWT.BORDER | SWT.SINGLE);
|
||||
nameText = new Text(nameComp, SWT.BORDER | SWT.SINGLE);
|
||||
nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
nameText.setText(Messages.NewArduinoTargetWizardPage_3);
|
||||
nameText.addKeyListener(new KeyListener() {
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
name = nameText.getText();
|
||||
updateStatus();
|
||||
}
|
||||
|
||||
|
@ -65,51 +54,9 @@ public class NewArduinoTargetWizardPage extends WizardPage {
|
|||
}
|
||||
});
|
||||
|
||||
Label portLabel = new Label(comp, SWT.NONE);
|
||||
portLabel.setText(Messages.NewArduinoTargetWizardPage_4);
|
||||
|
||||
portCombo = new Combo(comp, SWT.READ_ONLY);
|
||||
portCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
try {
|
||||
portNames = SerialPort.list();
|
||||
} catch (IOException e) {
|
||||
portNames = new String[0];
|
||||
Activator.log(e);
|
||||
}
|
||||
for (String portName : portNames) {
|
||||
portCombo.add(portName);
|
||||
}
|
||||
portCombo.select(0);
|
||||
portCombo.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
updateStatus();
|
||||
}
|
||||
});
|
||||
|
||||
Label boardLabel = new Label(comp, SWT.NONE);
|
||||
boardLabel.setText(Messages.NewArduinoTargetWizardPage_5);
|
||||
|
||||
boardCombo = new Combo(comp, SWT.READ_ONLY);
|
||||
boardCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
try {
|
||||
List<ArduinoBoard> boardList = ArduinoManager.instance.getInstalledBoards();
|
||||
Collections.sort(boardList, new Comparator<ArduinoBoard>() {
|
||||
@Override
|
||||
public int compare(ArduinoBoard o1, ArduinoBoard o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
});
|
||||
boards = boardList.toArray(new ArduinoBoard[0]);
|
||||
|
||||
for (ArduinoBoard board : boards) {
|
||||
boardCombo.add(board.getName());
|
||||
}
|
||||
boardCombo.select(0);
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
boardCombo.addSelectionListener(new SelectionAdapter() {
|
||||
boardControl = new BoardPropertyControl(comp, SWT.NONE);
|
||||
boardControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
|
||||
boardControl.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
updateStatus();
|
||||
|
@ -121,15 +68,12 @@ public class NewArduinoTargetWizardPage extends WizardPage {
|
|||
}
|
||||
|
||||
private void updateStatus() {
|
||||
name = nameText.getText();
|
||||
setPageComplete(name != null && !name.isEmpty() && boardControl.getPortName() != null
|
||||
&& boardControl.getSelectedBoard() != null);
|
||||
}
|
||||
|
||||
int portIndex = portCombo.getSelectionIndex();
|
||||
portName = portIndex < 0 ? null : portNames[portIndex];
|
||||
|
||||
int boardIndex = boardCombo.getSelectionIndex();
|
||||
board = boardIndex < 0 ? null : boards[boardIndex];
|
||||
|
||||
setPageComplete(!name.isEmpty() && portName != null && board != null);
|
||||
public void performFinish(IRemoteConnectionWorkingCopy workingCopy) {
|
||||
boardControl.apply(workingCopy);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue