1
0
Fork 0
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:
Doug Schaefer 2015-09-02 20:51:40 -04:00
parent daf1be845c
commit a887378f70
16 changed files with 505 additions and 151 deletions

View file

@ -64,7 +64,7 @@ public class ArduinoProjectGenerator {
IBuildConfiguration config = project.getBuildConfig("uno"); //$NON-NLS-1$ IBuildConfiguration config = project.getBuildConfig("uno"); //$NON-NLS-1$
ArduinoBuildConfiguration arduinoConfig = config.getAdapter(ArduinoBuildConfiguration.class); 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); arduinoConfig.setBoard(board);
// Generate files // Generate files

View file

@ -8,11 +8,13 @@
package org.eclipse.cdt.arduino.core.internal; package org.eclipse.cdt.arduino.core.internal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.eclipse.core.runtime.Platform;
public class HierarchicalProperties { public class HierarchicalProperties {
private String value; private String value;
@ -52,7 +54,7 @@ public class HierarchicalProperties {
public void putProperty(String qualifiedKey, String value) { public void putProperty(String qualifiedKey, String value) {
if (children == null) { if (children == null) {
children = new HashMap<>(); children = new LinkedHashMap<>();
} }
int i = qualifiedKey.indexOf('.'); int i = qualifiedKey.indexOf('.');
@ -61,8 +63,8 @@ public class HierarchicalProperties {
if (child == null) { if (child == null) {
child = new HierarchicalProperties(); child = new HierarchicalProperties();
children.put(qualifiedKey, child); children.put(qualifiedKey, child);
child.setValue(value);
} }
child.setValue(value);
} else { } else {
String key = qualifiedKey.substring(0, i); String key = qualifiedKey.substring(0, i);
HierarchicalProperties child = children.get(key); HierarchicalProperties child = children.get(key);
@ -76,6 +78,27 @@ public class HierarchicalProperties {
} }
public String getValue() { 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; return value;
} }
@ -93,7 +116,7 @@ public class HierarchicalProperties {
public void putChild(String key, HierarchicalProperties node) { public void putChild(String key, HierarchicalProperties node) {
if (children == null) { if (children == null) {
children = new HashMap<>(); children = new LinkedHashMap<>();
} }
children.put(key, node); children.put(key, node);
} }

View file

@ -13,6 +13,8 @@ import org.eclipse.cdt.arduino.core.internal.HierarchicalProperties;
public class ArduinoBoard { public class ArduinoBoard {
public static final String MENU_QUALIFIER = "menu_"; //$NON-NLS-1$
private String name; private String name;
private String id; private String id;
@ -50,10 +52,18 @@ public class ArduinoBoard {
return properties.getProperty(key); return properties.getProperty(key);
} }
public HierarchicalProperties getMenus() {
return properties.getChild("menu"); //$NON-NLS-1$
}
public Properties getBoardProperties() { public Properties getBoardProperties() {
return properties.flatten(); return properties.flatten();
} }
public Properties getMenuProperties(String id, String value) {
return getMenus().getChild(id).getChild(value).flatten();
}
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;

View file

@ -8,7 +8,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences; 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.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
@ -178,7 +178,7 @@ public class ArduinoLibrary {
getSources(project, sources, file.toPath(), recurse); getSources(project, sources, file.toPath(), recurse);
} }
} else { } else {
if (CoreModel.isValidSourceUnitName(project, file.getName())) { if (ArduinoBuildConfiguration.isSource(file.getName())) {
sources.add(file.toPath()); sources.add(file.toPath());
} }
} }

View file

@ -107,7 +107,7 @@ public class ArduinoManager {
} }
} }
public List<PackageIndex> getPackageIndices() throws CoreException { public synchronized List<PackageIndex> getPackageIndices() throws CoreException {
if (packageIndices == null) { if (packageIndices == null) {
String[] boardUrls = ArduinoPreferences.getBoardUrls().split("\n"); //$NON-NLS-1$ String[] boardUrls = ArduinoPreferences.getBoardUrls().split("\n"); //$NON-NLS-1$
packageIndices = new ArrayList<>(boardUrls.length); packageIndices = new ArrayList<>(boardUrls.length);
@ -146,7 +146,7 @@ public class ArduinoManager {
} }
public ArduinoBoard getBoard(String boardName, String platformName, String packageName) throws CoreException { public ArduinoBoard getBoard(String boardName, String platformName, String packageName) throws CoreException {
for (PackageIndex index : packageIndices) { for (PackageIndex index : getPackageIndices()) {
ArduinoPackage pkg = index.getPackage(packageName); ArduinoPackage pkg = index.getPackage(packageName);
if (pkg != null) { if (pkg != null) {
ArduinoPlatform platform = pkg.getPlatform(platformName); ArduinoPlatform platform = pkg.getPlatform(platformName);
@ -163,7 +163,7 @@ public class ArduinoManager {
public List<ArduinoBoard> getBoards() throws CoreException { public List<ArduinoBoard> getBoards() throws CoreException {
List<ArduinoBoard> boards = new ArrayList<>(); List<ArduinoBoard> boards = new ArrayList<>();
for (PackageIndex index : packageIndices) { for (PackageIndex index : getPackageIndices()) {
for (ArduinoPackage pkg : index.getPackages()) { for (ArduinoPackage pkg : index.getPackages()) {
for (ArduinoPlatform platform : pkg.getLatestPlatforms()) { for (ArduinoPlatform platform : pkg.getLatestPlatforms()) {
boards.addAll(platform.getBoards()); boards.addAll(platform.getBoards());
@ -175,7 +175,7 @@ public class ArduinoManager {
public List<ArduinoBoard> getInstalledBoards() throws CoreException { public List<ArduinoBoard> getInstalledBoards() throws CoreException {
List<ArduinoBoard> boards = new ArrayList<>(); List<ArduinoBoard> boards = new ArrayList<>();
for (PackageIndex index : packageIndices) { for (PackageIndex index : getPackageIndices()) {
for (ArduinoPackage pkg : index.getPackages()) { for (ArduinoPackage pkg : index.getPackages()) {
for (ArduinoPlatform platform : pkg.getInstalledPlatforms()) { for (ArduinoPlatform platform : pkg.getInstalledPlatforms()) {
boards.addAll(platform.getBoards()); boards.addAll(platform.getBoards());
@ -185,8 +185,8 @@ public class ArduinoManager {
return boards; return boards;
} }
public ArduinoPackage getPackage(String packageName) { public ArduinoPackage getPackage(String packageName) throws CoreException {
for (PackageIndex index : packageIndices) { for (PackageIndex index : getPackageIndices()) {
ArduinoPackage pkg = index.getPackage(packageName); ArduinoPackage pkg = index.getPackage(packageName);
if (pkg != null) { if (pkg != null) {
return pkg; return pkg;
@ -195,8 +195,8 @@ public class ArduinoManager {
return null; return null;
} }
public ArduinoTool getTool(String packageName, String toolName, String version) { public ArduinoTool getTool(String packageName, String toolName, String version) throws CoreException {
for (PackageIndex index : packageIndices) { for (PackageIndex index : getPackageIndices()) {
ArduinoPackage pkg = index.getPackage(packageName); ArduinoPackage pkg = index.getPackage(packageName);
if (pkg != null) { if (pkg != null) {
ArduinoTool tool = pkg.getTool(toolName, version); ArduinoTool tool = pkg.getTool(toolName, version);

View file

@ -17,6 +17,7 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; 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.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
public class ArduinoPlatform { public class ArduinoPlatform {
@ -44,8 +46,9 @@ public class ArduinoPlatform {
private List<ToolDependency> toolsDependencies; private List<ToolDependency> toolsDependencies;
private ArduinoPackage pkg; private ArduinoPackage pkg;
private HierarchicalProperties boardsFile; private HierarchicalProperties boardsProperties;
private Properties platformProperties; private Properties platformProperties;
private Map<String, String> menus = new HashMap<>();
void setOwner(ArduinoPackage pkg) { void setOwner(ArduinoPackage pkg) {
this.pkg = pkg; this.pkg = pkg;
@ -94,28 +97,40 @@ public class ArduinoPlatform {
} }
public List<ArduinoBoard> getBoards() throws CoreException { public List<ArduinoBoard> getBoards() throws CoreException {
if (isInstalled() && boardsFile == null) { if (isInstalled() && boardsProperties == null) {
Properties boardProps = new Properties(); Properties boardProps = new Properties();
try (Reader reader = new FileReader(getInstallPath().resolve("boards.txt").toFile())) { //$NON-NLS-1$ try (Reader reader = new FileReader(getInstallPath().resolve("boards.txt").toFile())) { //$NON-NLS-1$
boardProps.load(reader); boardProps.load(reader);
} catch (IOException e) { } 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 // Replace the boards with a real ones
boards = new ArrayList<>(); 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$ if (entry.getValue().getChild("name") != null) { //$NON-NLS-1$
// assume things with names are boards // assume things with names are boards
boards.add(new ArduinoBoard(entry.getKey(), entry.getValue()).setOwners(this)); 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; return boards;
} }
public HierarchicalProperties getBoardsProperties() {
return boardsProperties;
}
public ArduinoBoard getBoard(String name) throws CoreException { public ArduinoBoard getBoard(String name) throws CoreException {
for (ArduinoBoard board : getBoards()) { for (ArduinoBoard board : getBoards()) {
if (name.equals(board.getName())) { if (name.equals(board.getName())) {
@ -125,6 +140,10 @@ public class ArduinoPlatform {
return null; return null;
} }
public String getMenuText(String id) {
return menus.get(id);
}
public List<ToolDependency> getToolsDependencies() { public List<ToolDependency> getToolsDependencies() {
return toolsDependencies; return toolsDependencies;
} }
@ -153,7 +172,7 @@ public class ArduinoPlatform {
platformProperties.load(reader1); platformProperties.load(reader1);
} }
} catch (IOException e) { } 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; return platformProperties;
@ -201,17 +220,18 @@ public class ArduinoPlatform {
} }
// On Windows install make from equations.org // On Windows install make from equations.org
try { if (Platform.getOS().equals(Platform.OS_WIN32)) {
Path makePath = ArduinoPreferences.getArduinoHome().resolve("tools/make/make.exe"); try {
if (!makePath.toFile().exists()) { Path makePath = ArduinoPreferences.getArduinoHome().resolve("tools/make/make.exe"); //$NON-NLS-1$
Files.createDirectories(makePath.getParent()); if (!makePath.toFile().exists()) {
URL makeUrl = new URL("ftp://ftp.equation.com/make/32/make.exe"); Files.createDirectories(makePath.getParent());
Files.copy(makeUrl.openStream(), makePath); URL makeUrl = new URL("ftp://ftp.equation.com/make/32/make.exe"); //$NON-NLS-1$
makePath.toFile().setExecutable(true, false); 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)); //$NON-NLS-1$
} }
} catch (IOException e) {
mstatus.add(new Status(IStatus.ERROR, Activator.getId(), "downloading make.exe", e));
} }
return mstatus != null ? mstatus : Status.OK_STATUS; return mstatus != null ? mstatus : Status.OK_STATUS;

View file

@ -70,12 +70,12 @@ public class ArduinoTool {
} }
// No valid system // 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() { public Properties getToolProperties() {
Properties properties = new Properties(); 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; return properties;
} }

View file

@ -21,6 +21,7 @@ import java.util.regex.Pattern;
import org.eclipse.cdt.arduino.core.internal.Activator; import org.eclipse.cdt.arduino.core.internal.Activator;
import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences; import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
import org.eclipse.cdt.arduino.core.internal.ArduinoTemplateGenerator; 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.ArduinoBoard;
import org.eclipse.cdt.arduino.core.internal.board.ArduinoLibrary; import org.eclipse.cdt.arduino.core.internal.board.ArduinoLibrary;
import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager; 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.board.ToolDependency;
import org.eclipse.cdt.arduino.core.internal.console.ArduinoConsoleParser; 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.console.ArduinoErrorParser;
import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
@ -102,12 +104,14 @@ public class ArduinoBuildConfiguration {
} }
} }
public static ArduinoBuildConfiguration getConfig(IProject project, ArduinoBoard board, IProgressMonitor monitor) public static ArduinoBuildConfiguration getConfig(IProject project, ArduinoRemoteConnection target,
throws CoreException { IProgressMonitor monitor) throws CoreException {
ArduinoBoard board = target.getBoard();
// return it if it exists already // return it if it exists already
for (IBuildConfiguration config : project.getBuildConfigs()) { for (IBuildConfiguration config : project.getBuildConfigs()) {
ArduinoBuildConfiguration arduinoConfig = config.getAdapter(ArduinoBuildConfiguration.class); ArduinoBuildConfiguration arduinoConfig = config.getAdapter(ArduinoBuildConfiguration.class);
if (board.equals(arduinoConfig.getBoard())) { if (arduinoConfig.matches(target)) {
return arduinoConfig; return arduinoConfig;
} }
} }
@ -130,7 +134,7 @@ public class ArduinoBuildConfiguration {
// set it up for the board // set it up for the board
IBuildConfiguration config = project.getBuildConfig(newName); IBuildConfiguration config = project.getBuildConfig(newName);
ArduinoBuildConfiguration arduinoConfig = config.getAdapter(ArduinoBuildConfiguration.class); ArduinoBuildConfiguration arduinoConfig = config.getAdapter(ArduinoBuildConfiguration.class);
arduinoConfig.setBoard(board); arduinoConfig.setBoard(target);
return arduinoConfig; return arduinoConfig;
} }
@ -165,10 +169,59 @@ public class ArduinoBuildConfiguration {
try { try {
settings.flush(); settings.flush();
} catch (BackingStoreException e) { } 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 { public ArduinoBoard getBoard() throws CoreException {
if (board == null) { if (board == null) {
IEclipsePreferences settings = getSettings(); IEclipsePreferences settings = getSettings();
@ -182,13 +235,32 @@ public class ArduinoBuildConfiguration {
private Properties getProperties() throws CoreException { private Properties getProperties() throws CoreException {
if (properties == null) { if (properties == null) {
// Board
ArduinoBoard board = getBoard(); ArduinoBoard board = getBoard();
ArduinoPlatform platform = board.getPlatform();
properties = board.getBoardProperties(); 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()); properties.putAll(board.getPlatform().getPlatformProperties());
// Tools
for (ToolDependency toolDep : platform.getToolsDependencies()) { for (ToolDependency toolDep : platform.getToolsDependencies()) {
properties.putAll(toolDep.getTool().getToolProperties()); 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("runtime.ide.version", "10607"); //$NON-NLS-1$ //$NON-NLS-2$
properties.put("build.arch", platform.getArchitecture().toUpperCase()); //$NON-NLS-1$ properties.put("build.arch", platform.getArchitecture().toUpperCase()); //$NON-NLS-1$
properties.put("build.path", config.getName()); //$NON-NLS-1$ properties.put("build.path", config.getName()); //$NON-NLS-1$
@ -246,7 +318,7 @@ public class ArduinoBuildConfiguration {
@Override @Override
public boolean visit(IResourceProxy proxy) throws CoreException { public boolean visit(IResourceProxy proxy) throws CoreException {
if (proxy.getType() == IResource.FILE) { if (proxy.getType() == IResource.FILE) {
if (CoreModel.isValidSourceUnitName(project, proxy.getName())) { if (isSource(proxy.getName())) {
Path sourcePath = new File(proxy.requestResource().getLocationURI()).toPath(); Path sourcePath = new File(proxy.requestResource().getLocationURI()).toPath();
sourceFiles.add(pathString(projectPath.relativize(sourcePath))); sourceFiles.add(pathString(projectPath.relativize(sourcePath)));
} }
@ -296,7 +368,7 @@ public class ArduinoBuildConfiguration {
File[] platformFiles = corePath.toFile().listFiles(new FilenameFilter() { File[] platformFiles = corePath.toFile().listFiles(new FilenameFilter() {
@Override @Override
public boolean accept(File dir, String name) { 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_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_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_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_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$ 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; 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) { private String resolveProperty(String property, Properties dict) {
String res = dict.getProperty(property); String res = dict.getProperty(property);
if (res == null) { if (res == null) {
@ -368,7 +454,7 @@ public class ArduinoBuildConfiguration {
List<Path> toolPaths = new ArrayList<>(); List<Path> toolPaths = new ArrayList<>();
if (isWindows) { if (isWindows) {
// Add in the tools/make directory to pick up make // 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(); ArduinoBoard board = getBoard();
ArduinoPlatform platform = board.getPlatform(); ArduinoPlatform platform = board.getPlatform();
@ -415,7 +501,7 @@ public class ArduinoBuildConfiguration {
} }
public int getMaxCodeSize() throws CoreException { 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; return sizeStr != null ? Integer.parseInt(sizeStr) : -1;
} }
@ -424,7 +510,7 @@ public class ArduinoBuildConfiguration {
} }
public int getMaxDataSize() throws CoreException { 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; return sizeStr != null ? Integer.parseInt(sizeStr) : -1;
} }
@ -433,16 +519,29 @@ public class ArduinoBuildConfiguration {
ArduinoTool tool = board.getPlatform().getTool(toolName); ArduinoTool tool = board.getPlatform().getTool(toolName);
Properties properties = getProperties(); 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$ 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) { if (isWindows) {
return splitCommand(command); return splitCommand(command);
} else { } else {
@ -475,7 +574,7 @@ public class ArduinoBuildConfiguration {
public static String pathString(Path path) { public static String pathString(Path path) {
String str = path.toString(); String str = path.toString();
if (isWindows) { if (isWindows) {
str = str.replaceAll("\\\\", "/"); str = str.replaceAll("\\\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$
} }
return str; return str;
} }
@ -540,13 +639,13 @@ public class ArduinoBuildConfiguration {
includePath.toArray(new String[includePath.size()])); includePath.toArray(new String[includePath.size()]));
return scannerInfo; return scannerInfo;
} catch (IOException e) { } 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) { private String[] splitCommand(String command) {
// TODO deal with quotes properly, for now just strip // 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() { public ArduinoConsoleParser[] getBuildConsoleParsers() {

View file

@ -14,7 +14,6 @@ import java.io.IOException;
import org.eclipse.cdt.arduino.core.internal.Activator; import org.eclipse.cdt.arduino.core.internal.Activator;
import org.eclipse.cdt.arduino.core.internal.Messages; 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.build.ArduinoBuildConfiguration;
import org.eclipse.cdt.arduino.core.internal.console.ArduinoConsoleService; import org.eclipse.cdt.arduino.core.internal.console.ArduinoConsoleService;
import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection; import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection;
@ -50,11 +49,10 @@ public class ArduinoLaunchConfigurationDelegate extends LaunchConfigurationDeleg
IRemoteConnection target = getTarget(configuration); IRemoteConnection target = getTarget(configuration);
if (target != null) { if (target != null) {
ArduinoRemoteConnection arduinoTarget = target.getService(ArduinoRemoteConnection.class); ArduinoRemoteConnection arduinoTarget = target.getService(ArduinoRemoteConnection.class);
ArduinoBoard targetBoard = arduinoTarget.getBoard();
// 1. make sure proper build config is set active // 1. make sure proper build config is set active
IProject project = configuration.getMappedResources()[0].getProject(); IProject project = configuration.getMappedResources()[0].getProject();
ArduinoBuildConfiguration arduinoConfig = ArduinoBuildConfiguration.getConfig(project, targetBoard, ArduinoBuildConfiguration arduinoConfig = ArduinoBuildConfiguration.getConfig(project, arduinoTarget,
monitor); monitor);
arduinoConfig.setActive(monitor); arduinoConfig.setActive(monitor);
} }
@ -89,7 +87,7 @@ public class ArduinoLaunchConfigurationDelegate extends LaunchConfigurationDeleg
// The build config // The build config
ArduinoBuildConfiguration arduinoConfig = ArduinoBuildConfiguration.getConfig(project, ArduinoBuildConfiguration arduinoConfig = ArduinoBuildConfiguration.getConfig(project,
arduinoTarget.getBoard(), monitor); arduinoTarget, monitor);
String[] uploadCmd = arduinoConfig.getUploadCommand(arduinoTarget.getPortName()); String[] uploadCmd = arduinoConfig.getUploadCommand(arduinoTarget.getPortName());
// If opened, temporarily close the connection so we can use // If opened, temporarily close the connection so we can use
@ -99,6 +97,14 @@ public class ArduinoLaunchConfigurationDelegate extends LaunchConfigurationDeleg
arduinoTarget.pause(); 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 // Run the process and capture the results in the console
ProcessBuilder processBuilder = new ProcessBuilder(uploadCmd) ProcessBuilder processBuilder = new ProcessBuilder(uploadCmd)
.directory(arduinoConfig.getBuildDirectory()); .directory(arduinoConfig.getBuildDirectory());

View file

@ -31,10 +31,10 @@ public class ArduinoRemoteConnection
implements IRemoteConnectionPropertyService, IRemoteCommandShellService, IRemoteConnectionChangeListener { implements IRemoteConnectionPropertyService, IRemoteCommandShellService, IRemoteConnectionChangeListener {
public static final String TYPE_ID = "org.eclipse.cdt.arduino.core.connectionType"; //$NON-NLS-1$ 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 PORT_NAME = "arduinoPortName"; //$NON-NLS-1$
public static final String PACKAGE_NAME = "packageName"; //$NON-NLS-1$ public static final String PACKAGE_NAME = "arduinoPackageName"; //$NON-NLS-1$
public static final String PLATFORM_NAME = "platformName"; //$NON-NLS-1$ public static final String PLATFORM_NAME = "arduinoPlatformName"; //$NON-NLS-1$
public static final String BOARD_NAME = "boardName"; //$NON-NLS-1$ public static final String BOARD_NAME = "arduinoBoardName"; //$NON-NLS-1$
private final IRemoteConnection remoteConnection; private final IRemoteConnection remoteConnection;
private SerialPort serialPort; private SerialPort serialPort;

View file

@ -24,6 +24,10 @@ PLATFORM_OBJS = \
<#if c> <#if c>
${build_path}/platform/${c?groups[1]}.o \ ${build_path}/platform/${c?groups[1]}.o \
</#if> </#if>
<#assign S = file?matches("${platform_path}/(.*)\\.S")>
<#if S>
${build_path}/platform/${S?groups[1]}.S.o \
</#if>
</#list> </#list>
LIBRARIES_OBJS = \ LIBRARIES_OBJS = \
@ -83,6 +87,14 @@ ${build_path}/platform/${c?groups[1]}.o: ${file}
${recipe_c_o_pattern} ${recipe_c_o_pattern}
${recipe_ar_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> </#if>
</#list> </#list>

View file

@ -44,9 +44,10 @@
name="Arduino" name="Arduino"
selectionFilter="single"> selectionFilter="single">
<enabledWhen> <enabledWhen>
<adapt <test
type="org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection"> forcePluginActivation="false"
</adapt> property="org.eclipse.cdt.arduino.ui.isArduinoRemote">
</test>
</enabledWhen> </enabledWhen>
</page> </page>
<page <page
@ -96,4 +97,27 @@
name="Boards"> name="Boards">
</page> </page>
</extension> </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> </plugin>

View file

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

View file

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

View file

@ -2,9 +2,6 @@ package org.eclipse.cdt.arduino.ui.internal.remote;
import java.util.Set; 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.core.internal.remote.ArduinoRemoteConnection;
import org.eclipse.cdt.arduino.ui.internal.Activator; import org.eclipse.cdt.arduino.ui.internal.Activator;
import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.Wizard;
@ -31,15 +28,7 @@ public class NewArduinoTargetWizard extends Wizard implements IRemoteUIConnectio
return false; return false;
} }
workingCopy.setAttribute(ArduinoRemoteConnection.PORT_NAME, page.portName); page.performFinish(workingCopy);
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());
return true; return true;
} }

View file

@ -1,17 +1,8 @@
package org.eclipse.cdt.arduino.ui.internal.remote; 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.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.jface.wizard.WizardPage;
import org.eclipse.remote.core.IRemoteConnectionWorkingCopy;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener; 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.events.SelectionEvent;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Text;
@ -29,13 +19,7 @@ public class NewArduinoTargetWizardPage extends WizardPage {
String name; String name;
private Text nameText; private Text nameText;
String portName; BoardPropertyControl boardControl;
private String[] portNames;
private Combo portCombo;
ArduinoBoard board;
private ArduinoBoard[] boards;
private Combo boardCombo;
public NewArduinoTargetWizardPage() { public NewArduinoTargetWizardPage() {
super("NewArduinoTargetPage"); //$NON-NLS-1$ super("NewArduinoTargetPage"); //$NON-NLS-1$
@ -46,17 +30,22 @@ public class NewArduinoTargetWizardPage extends WizardPage {
@Override @Override
public void createControl(Composite parent) { public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE); 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); 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.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
nameText.setText(Messages.NewArduinoTargetWizardPage_3); nameText.setText(Messages.NewArduinoTargetWizardPage_3);
nameText.addKeyListener(new KeyListener() { nameText.addKeyListener(new KeyListener() {
@Override @Override
public void keyReleased(KeyEvent e) { public void keyReleased(KeyEvent e) {
name = nameText.getText();
updateStatus(); updateStatus();
} }
@ -65,51 +54,9 @@ public class NewArduinoTargetWizardPage extends WizardPage {
} }
}); });
Label portLabel = new Label(comp, SWT.NONE); boardControl = new BoardPropertyControl(comp, SWT.NONE);
portLabel.setText(Messages.NewArduinoTargetWizardPage_4); boardControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
boardControl.addSelectionListener(new SelectionAdapter() {
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() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
updateStatus(); updateStatus();
@ -121,15 +68,12 @@ public class NewArduinoTargetWizardPage extends WizardPage {
} }
private void updateStatus() { private void updateStatus() {
name = nameText.getText(); setPageComplete(name != null && !name.isEmpty() && boardControl.getPortName() != null
&& boardControl.getSelectedBoard() != null);
}
int portIndex = portCombo.getSelectionIndex(); public void performFinish(IRemoteConnectionWorkingCopy workingCopy) {
portName = portIndex < 0 ? null : portNames[portIndex]; boardControl.apply(workingCopy);
int boardIndex = boardCombo.getSelectionIndex();
board = boardIndex < 0 ? null : boards[boardIndex];
setPageComplete(!name.isEmpty() && portName != null && board != null);
} }
} }