From 076e141b69bb543d45f41b0c10317fde3ef959ea Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Sat, 2 May 2015 22:58:18 -0400 Subject: Bug 466209 - Initial commit of Arduino plugins. Includes freemarker jar which we have CQ approval for. Change-Id: I8f36cd7f4539497bab5f106f84216f75a25da3a0 --- build/org.eclipse.cdt.autotools.docs/.gitignore | 1 + .../src/org/eclipse/cdt/serial/SerialPort.java | 81 +++++++- pom.xml | 4 + releng/org.eclipse.cdt.target/cdt-e4.5.target | 11 +- toolchains/arduino/.project | 22 +++ .../org.eclipse.cdt.arduino-feature/.gitignore | 1 + .../org.eclipse.cdt.arduino-feature/.project | 23 +++ .../.settings/org.eclipse.m2e.core.prefs | 4 + .../org.eclipse.cdt.arduino-feature/arduino.mk | 113 +++++++++++ .../build.properties | 1 + .../feature.properties | 32 ++++ .../org.eclipse.cdt.arduino-feature/feature.xml | 43 +++++ .../org.eclipse.cdt.arduino-feature/pom.xml | 16 ++ .../org.eclipse.cdt.arduino.core/.classpath | 8 + .../org.eclipse.cdt.arduino.core/.gitignore | 2 + .../arduino/org.eclipse.cdt.arduino.core/.project | 34 ++++ .../.settings/org.eclipse.jdt.core.prefs | 7 + .../.settings/org.eclipse.m2e.core.prefs | 4 + .../META-INF/MANIFEST.MF | 22 +++ .../org.eclipse.cdt.arduino.core/about.html | 24 +++ .../org.eclipse.cdt.arduino.core/build.properties | 8 + .../libs/freemarker-2.3.22.jar | Bin 0 -> 1300487 bytes .../org.eclipse.cdt.arduino.core/plugin.xml | 151 +++++++++++++++ .../arduino/org.eclipse.cdt.arduino.core/pom.xml | 17 ++ .../schema/consoleService.exsd | 102 ++++++++++ .../arduino/core/ArduinoLaunchConsoleService.java | 23 +++ .../cdt/arduino/core/ArduinoProjectGenerator.java | 211 +++++++++++++++++++++ .../src/org/eclipse/cdt/arduino/core/Board.java | 41 ++++ .../cdt/arduino/core/IArduinoBoardManager.java | 21 ++ .../cdt/arduino/core/IArduinoRemoteConnection.java | 45 +++++ .../cdt/arduino/core/internal/Activator.java | 61 ++++++ .../cdt/arduino/core/internal/ArduinoHome.java | 40 ++++ .../core/internal/ArduinoProjectNature.java | 50 +++++ .../core/internal/AvrLanguageSettingsProvider.java | 71 +++++++ .../cdt/arduino/core/internal/EnvVarSupplier.java | 154 +++++++++++++++ .../cdt/arduino/core/internal/Messages.java | 28 +++ .../launch/ArduinoLaunchConfigurationDelegate.java | 182 ++++++++++++++++++ .../launch/ArduinoLaunchConfigurationProvider.java | 24 +++ .../launch/ArduinoLaunchDescriptorType.java | 40 ++++ .../cdt/arduino/core/internal/messages.properties | 13 ++ .../core/internal/remote/ArduinoBoardManager.java | 85 +++++++++ .../internal/remote/ArduinoRemoteConnection.java | 115 +++++++++++ .../templates/Makefile | 3 + .../templates/arduino.cpp | 9 + .../arduino/org.eclipse.cdt.arduino.ui/.classpath | 7 + .../arduino/org.eclipse.cdt.arduino.ui/.gitignore | 1 + .../arduino/org.eclipse.cdt.arduino.ui/.project | 39 ++++ .../.settings/org.eclipse.jdt.core.prefs | 7 + .../.settings/org.eclipse.m2e.core.prefs | 4 + .../META-INF/MANIFEST.MF | 22 +++ .../arduino/org.eclipse.cdt.arduino.ui/about.html | 24 +++ .../org.eclipse.cdt.arduino.ui/build.properties | 6 + .../org.eclipse.cdt.arduino.ui/icons/arduino.png | Bin 0 -> 913 bytes .../org.eclipse.cdt.arduino.ui/icons/cprojects.gif | Bin 0 -> 365 bytes .../org.eclipse.cdt.arduino.ui/icons/newcc_app.gif | Bin 0 -> 630 bytes .../arduino/org.eclipse.cdt.arduino.ui/plugin.xml | 68 +++++++ .../arduino/org.eclipse.cdt.arduino.ui/pom.xml | 17 ++ .../eclipse/cdt/arduino/ui/internal/Activator.java | 83 ++++++++ .../launch/ArduinoDescriptorLabelProvider.java | 32 ++++ .../ui/internal/launch/ArduinoLaunchConsole.java | 80 ++++++++ .../internal/project/NewArduinoProjectWizard.java | 53 ++++++ .../internal/remote/ArduinoRemoteServicesUI.java | 67 +++++++ .../internal/remote/ArduinoTargetPropertyPage.java | 111 +++++++++++ .../ui/internal/remote/NewArduinoTargetWizard.java | 72 +++++++ .../remote/NewArduinoTargetWizardPage.java | 120 ++++++++++++ 65 files changed, 2754 insertions(+), 6 deletions(-) create mode 100644 toolchains/arduino/.project create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino-feature/.gitignore create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino-feature/.project create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino-feature/.settings/org.eclipse.m2e.core.prefs create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino-feature/arduino.mk create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino-feature/build.properties create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino-feature/feature.properties create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino-feature/feature.xml create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino-feature/pom.xml create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/.classpath create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/.gitignore create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/.project create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/.settings/org.eclipse.jdt.core.prefs create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/.settings/org.eclipse.m2e.core.prefs create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/META-INF/MANIFEST.MF create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/about.html create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/build.properties create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/libs/freemarker-2.3.22.jar create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/plugin.xml create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/pom.xml create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/schema/consoleService.exsd create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/ArduinoLaunchConsoleService.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/ArduinoProjectGenerator.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/Board.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/IArduinoBoardManager.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/IArduinoRemoteConnection.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/Activator.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/ArduinoHome.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/ArduinoProjectNature.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/AvrLanguageSettingsProvider.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/EnvVarSupplier.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/Messages.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/launch/ArduinoLaunchConfigurationDelegate.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/launch/ArduinoLaunchConfigurationProvider.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/launch/ArduinoLaunchDescriptorType.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/messages.properties create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/remote/ArduinoBoardManager.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/remote/ArduinoRemoteConnection.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/templates/Makefile create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.core/templates/arduino.cpp create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/.classpath create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/.gitignore create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/.project create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/.settings/org.eclipse.jdt.core.prefs create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/.settings/org.eclipse.m2e.core.prefs create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/META-INF/MANIFEST.MF create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/about.html create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/build.properties create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/icons/arduino.png create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/icons/cprojects.gif create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/icons/newcc_app.gif create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/plugin.xml create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/pom.xml create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/Activator.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/launch/ArduinoDescriptorLabelProvider.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/launch/ArduinoLaunchConsole.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/project/NewArduinoProjectWizard.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/ArduinoRemoteServicesUI.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/ArduinoTargetPropertyPage.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/NewArduinoTargetWizard.java create mode 100644 toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/NewArduinoTargetWizardPage.java diff --git a/build/org.eclipse.cdt.autotools.docs/.gitignore b/build/org.eclipse.cdt.autotools.docs/.gitignore index 8d94ef8debe..6d9667aae0f 100644 --- a/build/org.eclipse.cdt.autotools.docs/.gitignore +++ b/build/org.eclipse.cdt.autotools.docs/.gitignore @@ -3,3 +3,4 @@ bin javaCompiler...args build.xml target +/workspace/ diff --git a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java index fc0f9f23833..b15c7178c8a 100644 --- a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java +++ b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java @@ -28,6 +28,8 @@ public class SerialPort { private final String portName; private boolean isOpen; + private boolean isPaused; + private Object pauseMutex = new Object(); private BaudRate baudRate = BaudRate.B115200; private ByteSize byteSize = ByteSize.B8; private Parity parity = Parity.None; @@ -56,7 +58,19 @@ public class SerialPort { while (true) { rlen = read1(handle, rbuff, 0, rbuff.length); if (rlen < 0) { - return -1; + if (isPaused) { + synchronized (pauseMutex) { + while (isPaused) { + try { + pauseMutex.wait(); + } catch (InterruptedException e) { + return -1; + } + } + } + } else { + return -1; + } } else if (rlen > 0) { break; } @@ -79,8 +93,22 @@ public class SerialPort { System.arraycopy(rbuff, rpos, b, off, n); rpos += n; return n; - } else { - return read1(handle, b, off, len); + } else { + n = read1(handle, b, off, len); + if (n < 0 && isPaused) { + synchronized (pauseMutex) { + while (isPaused) { + try { + pauseMutex.wait(); + } catch (InterruptedException e) { + return -1; + } + } + } + return read1(handle, b, off, len); + } else { + return n; + } } } else { return -1; @@ -97,14 +125,44 @@ public class SerialPort { @Override public void write(int b) throws IOException { if (isOpen()) { - write0(handle, b); + try { + write0(handle, b); + } catch (IOException e) { + if (isPaused) { + synchronized (pauseMutex) { + while (isPaused) { + try { + pauseMutex.wait(); + } catch (InterruptedException e1) { + throw e; + } + } + } + write0(handle, b); + } + } } } @Override public void write(byte[] buff, int off, int len) throws IOException { if (isOpen()) { - write1(handle, buff, off, len); + try { + write1(handle, buff, off, len); + } catch (IOException e) { + if (isPaused) { + synchronized (pauseMutex) { + while (isPaused) { + try { + pauseMutex.wait(); + } catch (InterruptedException e1) { + throw e; + } + } + } + write1(handle, buff, off, len); + } + } } } @@ -212,6 +270,19 @@ public class SerialPort { return isOpen; } + public void pause() throws IOException { + isPaused = true; + close0(handle); + } + + public void resume() throws IOException { + synchronized (pauseMutex) { + isPaused = false; + open(); + pauseMutex.notifyAll(); + } + } + public void setBaudRate(BaudRate rate) throws IOException { if (isOpen) { throw new IOException(PORT_OPEN); diff --git a/pom.xml b/pom.xml index 7a76e9cc7c3..102cde69a38 100644 --- a/pom.xml +++ b/pom.xml @@ -216,6 +216,10 @@ remote/org.eclipse.cdt.remote.core remote/org.eclipse.cdt.remote-feature + toolchains/arduino/org.eclipse.cdt.arduino.core + toolchains/arduino/org.eclipse.cdt.arduino.ui + toolchains/arduino/org.eclipse.cdt.arduino-feature + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/ArduinoLaunchConsoleService.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/ArduinoLaunchConsoleService.java new file mode 100644 index 00000000000..41b871d0152 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/ArduinoLaunchConsoleService.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.arduino.core; + + +public interface ArduinoLaunchConsoleService { + + /** + * Capture the output for the process and display on the console. + * + * @param process + */ + void monitor(Process process); + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/ArduinoProjectGenerator.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/ArduinoProjectGenerator.java new file mode 100644 index 00000000000..d80377612f6 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/ArduinoProjectGenerator.java @@ -0,0 +1,211 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.arduino.core; + +import java.io.File; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; +import java.io.Writer; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.cdt.arduino.core.internal.Activator; +import org.eclipse.cdt.arduino.core.internal.ArduinoProjectNature; +import org.eclipse.cdt.arduino.core.internal.Messages; +import org.eclipse.cdt.arduino.core.internal.launch.ArduinoLaunchConfigurationDelegate; +import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection; +import org.eclipse.cdt.core.CCProjectNature; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.CProjectNature; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; +import org.eclipse.cdt.managedbuilder.core.BuildException; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.IOption; +import org.eclipse.cdt.managedbuilder.core.IToolChain; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo; +import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject; +import org.eclipse.cdt.managedbuilder.internal.core.ToolChain; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.IRemoteServicesManager; +import org.eclipse.remote.core.launch.IRemoteLaunchConfigService; + +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; + +@SuppressWarnings("restriction") +public class ArduinoProjectGenerator { + + public static final String BOARD_OPTION_ID = "org.eclipse.cdt.arduino.option.board"; //$NON-NLS-1$ + public static final String AVR_TOOLCHAIN_ID = "org.eclipse.cdt.arduino.toolChain.avr"; //$NON-NLS-1$ + + private final IProject project; + private IFile sourceFile; + + public ArduinoProjectGenerator(IProject project) { + this.project = project; + } + + public void setupArduinoProject(IProgressMonitor monitor) throws CoreException { + // create the CDT-ness of the project + IProjectDescription projDesc = project.getDescription(); + CCorePlugin.getDefault().createCDTProject(projDesc, project, monitor); + + String[] oldIds = projDesc.getNatureIds(); + String[] newIds = new String[oldIds.length + 3]; + System.arraycopy(oldIds, 0, newIds, 0, oldIds.length); + newIds[newIds.length - 1] = ArduinoProjectNature.ID; + newIds[newIds.length - 2] = CCProjectNature.CC_NATURE_ID; + newIds[newIds.length - 3] = CProjectNature.C_NATURE_ID; + projDesc.setNatureIds(newIds); + project.setDescription(projDesc, monitor); + + ICProjectDescription cprojDesc = CCorePlugin.getDefault().createProjectDescription(project, false); + ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project); + ManagedProject mProj = new ManagedProject(cprojDesc); + info.setManagedProject(mProj); + + Board board = null; + + IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class); + IRemoteLaunchConfigService remoteLaunchService = Activator.getService(IRemoteLaunchConfigService.class); + IRemoteConnection remoteConnection = remoteLaunchService.getLastActiveConnection(ArduinoLaunchConfigurationDelegate.getLaunchConfigurationType()); + if (remoteConnection != null) { + IArduinoRemoteConnection arduinoRemote = remoteConnection.getService(IArduinoRemoteConnection.class); + board = arduinoRemote.getBoard(); + } else { + IRemoteConnectionType connectionType = remoteManager.getConnectionType(ArduinoRemoteConnection.TYPE_ID); + Collection connections = connectionType.getConnections(); + if (!connections.isEmpty()) { + IRemoteConnection firstConnection = connections.iterator().next(); + IArduinoRemoteConnection firstArduino = firstConnection.getService(IArduinoRemoteConnection.class); + board = firstArduino.getBoard(); + } + } + + if (board == null) { + IArduinoBoardManager boardManager = Activator.getService(IArduinoBoardManager.class); + board = boardManager.getBoard("uno"); // the default //$NON-NLS-1$ + } + + createBuildConfiguration(cprojDesc, board); + + CCorePlugin.getDefault().setProjectDescription(project, cprojDesc, true, monitor); + + // Generate files + try { + Configuration fmConfig = new Configuration(Configuration.VERSION_2_3_22); + URL templateDirURL = FileLocator.find(Activator.getContext().getBundle(), new Path("/templates"), null); //$NON-NLS-1$ + fmConfig.setDirectoryForTemplateLoading(new File(FileLocator.toFileURL(templateDirURL).toURI())); + + final Map fmModel = new HashMap<>(); + fmModel.put("projectName", project.getName()); //$NON-NLS-1$ + + generateFile(fmModel, fmConfig.getTemplate("Makefile"), project.getFile("Makefile")); //$NON-NLS-1$ //$NON-NLS-2$ + + sourceFile = project.getFile(project.getName() + ".cpp"); //$NON-NLS-1$ + generateFile(fmModel, fmConfig.getTemplate("arduino.cpp"), sourceFile); //$NON-NLS-1$ + } catch (IOException e) { + throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), e.getLocalizedMessage(), e)); + } catch (URISyntaxException e) { + throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), e.getLocalizedMessage(), e)); + } catch (TemplateException e) { + throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), e.getLocalizedMessage(), e)); + } + + // Do the initial build + project.build(IncrementalProjectBuilder.FULL_BUILD, monitor); + } + + private static void generateFile(Object model, Template template, final IFile outputFile) throws TemplateException, IOException, CoreException { + final PipedInputStream in = new PipedInputStream(); + PipedOutputStream out = new PipedOutputStream(in); + final Writer writer = new OutputStreamWriter(out); + Job job = new Job(Messages.ArduinoProjectGenerator_0) { + protected IStatus run(IProgressMonitor monitor) { + try { + outputFile.create(in, true, monitor); + } catch (CoreException e) { + return e.getStatus(); + } + return Status.OK_STATUS; + } + }; + job.setRule(outputFile.getProject()); + job.schedule(); + template.process(model, writer); + writer.close(); + try { + job.join(); + } catch (InterruptedException e) { + // TODO anything? + } + IStatus status = job.getResult(); + if (!status.isOK()) + throw new CoreException(status); + } + + public static ICConfigurationDescription createBuildConfiguration(ICProjectDescription projDesc, Board board) throws CoreException { + ManagedProject managedProject = new ManagedProject(projDesc); + String configId = ManagedBuildManager.calculateChildId(AVR_TOOLCHAIN_ID, null); + IToolChain avrToolChain = ManagedBuildManager.getExtensionToolChain(AVR_TOOLCHAIN_ID); + org.eclipse.cdt.managedbuilder.internal.core.Configuration newConfig = new org.eclipse.cdt.managedbuilder.internal.core.Configuration(managedProject, (ToolChain) avrToolChain, configId, board.getId()); + IToolChain newToolChain = newConfig.getToolChain(); + IOption newOption = newToolChain.getOptionBySuperClassId(BOARD_OPTION_ID); + ManagedBuildManager.setOption(newConfig, newToolChain, newOption, board.getId()); + + CConfigurationData data = newConfig.getConfigurationData(); + return projDesc.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data); + } + + public static Board getBoard(IConfiguration configuration) throws CoreException { + try { + IToolChain toolChain = configuration.getToolChain(); + IOption boardOption = toolChain.getOptionBySuperClassId(BOARD_OPTION_ID); + String boardId = boardOption.getStringValue(); + + IArduinoBoardManager boardManager = Activator.getService(IArduinoBoardManager.class); + Board board = boardManager.getBoard(boardId); + if (board == null) { + board = boardManager.getBoard("uno"); //$NON-NLS-1$ + } + return board; + } catch (BuildException e) { + throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), e.getLocalizedMessage(), e)); + } + + } + + public IFile getSourceFile() { + return sourceFile; + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/Board.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/Board.java new file mode 100644 index 00000000000..d072d6c0a72 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/Board.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.arduino.core; + +import java.util.Properties; + +public class Board { + + private final String id; + private final Properties properties; + + public Board(String key, Properties properties) { + this.id = key; + this.properties = properties; + } + + public String getId() { + return id; + } + + public String getProperty(String localKey) { + return properties.getProperty(id + '.' + localKey); + } + + public String getName() { + return getProperty("name"); //$NON-NLS-1$ + } + + public String getMCU() { + return getProperty("build.mcu"); //$NON-NLS-1$ + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/IArduinoBoardManager.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/IArduinoBoardManager.java new file mode 100644 index 00000000000..8930f73d974 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/IArduinoBoardManager.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.arduino.core; + +import java.util.Collection; + +public interface IArduinoBoardManager { + + Board getBoard(String id); + + Collection getBoards(); + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/IArduinoRemoteConnection.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/IArduinoRemoteConnection.java new file mode 100644 index 00000000000..f76577a1bcb --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/IArduinoRemoteConnection.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.arduino.core; + +import org.eclipse.remote.core.IRemoteConnection; + +/** + * Arduino specific extensions to IRemoteConnection. + * + * @author dschaefer + * + */ +public interface IArduinoRemoteConnection extends IRemoteConnection.Service { + + final String TYPE_ID = "org.eclipse.cdt.arduino.core.connectionType"; //$NON-NLS-1$ + final String PORT_NAME = "ardiuno.portname"; //$NON-NLS-1$ + final String BOARD_ID = "arduino.board"; //$NON-NLS-1$ + + /** + * Return the serial port name. + * + * @return serial port name + */ + String getPortName(); + + /** + * Get the board type at the end of this connection. + * + * @return Board + */ + Board getBoard(); + + void pause(); + + void resume(); + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/Activator.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/Activator.java new file mode 100644 index 00000000000..1dbe641f7c6 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/Activator.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.arduino.core.internal; + +import org.eclipse.cdt.arduino.core.IArduinoBoardManager; +import org.eclipse.cdt.arduino.core.internal.remote.ArduinoBoardManager; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +public class Activator extends Plugin { + + private static Plugin plugin; + + public static BundleContext getContext() { + return plugin.getBundle().getBundleContext(); + } + + public static Plugin getPlugin() { + return plugin; + } + + public static String getId() { + return plugin.getBundle().getSymbolicName(); + } + + public static void log(Exception e) { + if (e instanceof CoreException) { + plugin.getLog().log(((CoreException) e).getStatus()); + } else { + plugin.getLog().log(new Status(IStatus.ERROR, Activator.getId(), e.getLocalizedMessage(), e)); + } + } + + public void start(BundleContext bundleContext) throws Exception { + plugin = this; + bundleContext.registerService(IArduinoBoardManager.class, new ArduinoBoardManager(), null); + } + + public void stop(BundleContext bundleContext) throws Exception { + plugin = null; + } + + public static T getService(Class service) { + BundleContext context = plugin.getBundle().getBundleContext(); + ServiceReference ref = context.getServiceReference(service); + return ref != null ? context.getService(ref) : null; + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/ArduinoHome.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/ArduinoHome.java new file mode 100644 index 00000000000..5501eed06e6 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/ArduinoHome.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.arduino.core.internal; + +import java.io.File; +import java.net.URISyntaxException; + +import org.eclipse.core.runtime.Platform; + +public class ArduinoHome { + + private static File home; + + public static File get() { + if (home == null) { + String arduinoPathStr = System.getProperty("org.eclipse.cdt.arduino.home"); //$NON-NLS-1$ + if (arduinoPathStr != null) { + home = new File(arduinoPathStr); + } else { + try { + home = new File(new File(Platform.getInstallLocation().getURL().toURI()), "arduino"); //$NON-NLS-1$ + } catch (URISyntaxException e) { + // TODO log + e.printStackTrace(); + home = new File("nohome"); //$NON-NLS-1$ + } + } + } + return home; + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/ArduinoProjectNature.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/ArduinoProjectNature.java new file mode 100644 index 00000000000..5eac539ad69 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/ArduinoProjectNature.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.arduino.core.internal; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IProjectNature; +import org.eclipse.core.runtime.CoreException; + +public class ArduinoProjectNature implements IProjectNature { + + private IProject project; + public static final String ID = Activator.getId() + ".arduinoNature"; //$NON-NLS-1$ + + @Override + public IProject getProject() { + return project; + } + + @Override + public void setProject(IProject project) { + this.project = project; + } + + public static boolean hasNature(IProject project) throws CoreException { + IProjectDescription projDesc = project.getDescription(); + for (String id : projDesc.getNatureIds()) { + if (id.equals(ID)) + return true; + } + return false; + } + + @Override + public void configure() throws CoreException { + } + + @Override + public void deconfigure() throws CoreException { + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/AvrLanguageSettingsProvider.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/AvrLanguageSettingsProvider.java new file mode 100644 index 00000000000..417405a28af --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/AvrLanguageSettingsProvider.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.arduino.core.internal; + +import java.io.File; +import java.util.List; + +import org.eclipse.cdt.arduino.core.ArduinoProjectGenerator; +import org.eclipse.cdt.arduino.core.Board; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Platform; + +public class AvrLanguageSettingsProvider extends GCCBuiltinSpecsDetector { + + @Override + public String getToolchainId() { + return "org.eclipse.cdt.arduino.toolChain.avr"; //$NON-NLS-1$ + } + + @Override + protected String getToolOptions(String languageId) { + String opts = super.getToolOptions(languageId); + + try { + IConfiguration config = ManagedBuildManager.getConfigurationForDescription(currentCfgDescription); + Board board = ArduinoProjectGenerator.getBoard(config); + String mcu = board.getMCU(); + if (mcu != null) { + opts += " -mmcu=" + mcu; //$NON-NLS-1$ + } + } catch (CoreException e) { + Activator.getPlugin().getLog().log(e.getStatus()); + } + + return opts; + } + + @Override + protected List parseOptions(String line) { + if (Platform.getOS().equals(Platform.OS_WIN32)) { + if (line.startsWith(" /arduino/")) { //$NON-NLS-1$ + File full = new File(ArduinoHome.get().getParentFile(), line.trim()); + return parseOptions(" " + full.getAbsolutePath()); //$NON-NLS-1$ + } + } + + return super.parseOptions(line); + } + + @Override + public AvrLanguageSettingsProvider cloneShallow() throws CloneNotSupportedException { + return (AvrLanguageSettingsProvider) super.cloneShallow(); + } + + @Override + public AvrLanguageSettingsProvider clone() throws CloneNotSupportedException { + return (AvrLanguageSettingsProvider) super.clone(); + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/EnvVarSupplier.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/EnvVarSupplier.java new file mode 100644 index 00000000000..a3642b218c8 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/EnvVarSupplier.java @@ -0,0 +1,154 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.arduino.core.internal; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.arduino.core.ArduinoProjectGenerator; +import org.eclipse.cdt.arduino.core.Board; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable; +import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier; +import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Platform; + +public class EnvVarSupplier implements IConfigurationEnvironmentVariableSupplier { + + private EnvVar arduinoHome; + private EnvVar path; + + private static final String OUTPUT_DIR = "OUTPUT_DIR"; //$NON-NLS-1$ + private static final String BOARD = "BOARD"; //$NON-NLS-1$ + private static final String CYGWIN = "CYGWIN"; //$NON-NLS-1$ + + private static final class EnvVar implements IBuildEnvironmentVariable { + String name; + String value; + int operation = IBuildEnvironmentVariable.ENVVAR_REPLACE; + String delimiter = null; + + @Override + public String getName() { + return name; + } + @Override + public String getValue() { + return value; + } + @Override + public int getOperation() { + return operation; + } + @Override + public String getDelimiter() { + return delimiter; + } + } + + public EnvVarSupplier() { + File arduinoPath = ArduinoHome.get(); + + if (arduinoPath.isDirectory()) { + arduinoHome = new EnvVar(); + arduinoHome.name = "ARDUINO_HOME"; //$NON-NLS-1$ + arduinoHome.value = arduinoPath.getAbsolutePath(); + + File avrPath = new File(arduinoPath, "hardware/tools/avr/bin"); //$NON-NLS-1$ + String pathStr = avrPath.getAbsolutePath(); + if (Platform.getOS().equals(Platform.OS_WIN32)) { + // Windows needs the arduino path too to pick up the cygwin dlls + pathStr += File.pathSeparator + arduinoPath.getAbsolutePath(); + } + + path = new EnvVar(); + path.name = "PATH"; //$NON-NLS-1$ + path.value = pathStr; + path.operation = IBuildEnvironmentVariable.ENVVAR_PREPEND; + path.delimiter = File.pathSeparator; + } + } + + private IBuildEnvironmentVariable getOutputDir(IConfiguration configuration) { + EnvVar outputDir = new EnvVar(); + outputDir.name = OUTPUT_DIR; + outputDir.value = "build/" + configuration.getName(); //$NON-NLS-1$ + return outputDir; + } + + private IBuildEnvironmentVariable getBoard(IConfiguration configuration) { + try { + Board board = ArduinoProjectGenerator.getBoard(configuration); + if (board == null) + return null; + + EnvVar boardVar = new EnvVar(); + boardVar.name = BOARD; + boardVar.value = board.getId(); + return boardVar; + } catch (CoreException e) { + Activator.getPlugin().getLog().log(e.getStatus()); + return null; + } + } + + private IBuildEnvironmentVariable getCygwin() { + EnvVar var = new EnvVar(); + var.name = CYGWIN; + var.value = "nodosfilewarning"; //$NON-NLS-1$ + return var; + } + + @Override + public IBuildEnvironmentVariable getVariable(String variableName, + IConfiguration configuration, IEnvironmentVariableProvider provider) { + if (path != null && variableName.equals(path.name)) { + return path; + } else if (arduinoHome != null && variableName.equals(arduinoHome.name)) { + return arduinoHome; + } else if (variableName.equals(OUTPUT_DIR)) { + return getOutputDir(configuration); + } else if (variableName.equals(BOARD)) { + return getBoard(configuration); + } else if (variableName.equals(CYGWIN)) { + return getCygwin(); + } + return null; + } + + @Override + public IBuildEnvironmentVariable[] getVariables( + IConfiguration configuration, IEnvironmentVariableProvider provider) { + List vars = new ArrayList<>(); + + if (path != null) + vars.add(path); + + if (arduinoHome != null) + vars.add(arduinoHome); + + if (configuration != null) { + vars.add(getOutputDir(configuration)); + + IBuildEnvironmentVariable boardVar = getBoard(configuration); + if (boardVar != null) + vars.add(boardVar); + } + + if (Platform.getOS().equals(Platform.OS_WIN32)) + vars.add(getCygwin()); + + return vars.toArray(new IBuildEnvironmentVariable[vars.size()]); + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/Messages.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/Messages.java new file mode 100644 index 00000000000..36fc60f1b2d --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/Messages.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.arduino.core.internal; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.cdt.arduino.core.internal.messages"; //$NON-NLS-1$ + public static String ArduinoLaunchConfigurationDelegate_0; + public static String ArduinoLaunchConfigurationDelegate_1; + public static String ArduinoProjectGenerator_0; + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/launch/ArduinoLaunchConfigurationDelegate.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/launch/ArduinoLaunchConfigurationDelegate.java new file mode 100644 index 00000000000..425c2a3200d --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/launch/ArduinoLaunchConfigurationDelegate.java @@ -0,0 +1,182 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.arduino.core.internal.launch; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.arduino.core.ArduinoLaunchConsoleService; +import org.eclipse.cdt.arduino.core.ArduinoProjectGenerator; +import org.eclipse.cdt.arduino.core.IArduinoRemoteConnection; +import org.eclipse.cdt.arduino.core.internal.Activator; +import org.eclipse.cdt.arduino.core.internal.Messages; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.envvar.IEnvironmentVariable; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.model.LaunchConfigurationDelegate; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.launch.IRemoteLaunchConfigService; + +public class ArduinoLaunchConfigurationDelegate extends LaunchConfigurationDelegate { + + public static ILaunchConfigurationType getLaunchConfigurationType() { + return DebugPlugin.getDefault().getLaunchManager() + .getLaunchConfigurationType("org.eclipse.cdt.arduino.core.launchConfigurationType"); //$NON-NLS-1$ + } + + @Override + public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException { + // 1. make sure proper build config is set active + IProject project = configuration.getMappedResources()[0].getProject(); + ICProjectDescription projDesc = CCorePlugin.getDefault().getProjectDescription(project); + IRemoteConnection remoteConnection = getActiveRemote(configuration); + if (remoteConnection == null) { + // TODO default? + return false; + } + ICConfigurationDescription configDesc = getBuildConfiguration(projDesc, remoteConnection); + boolean newConfig = false; + if (configDesc == null) { + IArduinoRemoteConnection arduinoRemote = remoteConnection.getService(IArduinoRemoteConnection.class); + configDesc = ArduinoProjectGenerator.createBuildConfiguration(projDesc, arduinoRemote.getBoard()); + newConfig = true; + } + if (newConfig || !projDesc.getActiveConfiguration().equals(configDesc)) { + projDesc.setActiveConfiguration(configDesc); + CCorePlugin.getDefault().setProjectDescription(project, projDesc); + } + + // 2. Run the build + return super.buildForLaunch(configuration, mode, monitor); + } + + @Override + protected IProject[] getBuildOrder(ILaunchConfiguration configuration, String mode) throws CoreException { + // 1. Extract project from configuration + IProject project = configuration.getMappedResources()[0].getProject(); + return new IProject[] { project }; + } + + @Override + public void launch(final ILaunchConfiguration configuration, String mode, + final ILaunch launch, IProgressMonitor monitor) throws CoreException { + new Job(Messages.ArduinoLaunchConfigurationDelegate_0) { + protected IStatus run(IProgressMonitor monitor) { + try { + ArduinoLaunchConsoleService consoleService = getConsoleService(); + + IRemoteConnection connection = getActiveRemote(configuration); + if (connection == null) { + return new Status(IStatus.ERROR, Activator.getId(), Messages.ArduinoLaunchConfigurationDelegate_1); + } + + // The project + IProject project = (IProject) configuration.getMappedResources()[0]; + + // The build environment + ICProjectDescription projDesc = CCorePlugin.getDefault().getProjectDescription(project); + ICConfigurationDescription configDesc = getBuildConfiguration(projDesc, connection); + IEnvironmentVariable[] envVars = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariables(configDesc, true); + List envVarList = new ArrayList(envVars.length + 1); + for (IEnvironmentVariable var : envVars) { + envVarList.add(var.getName() + '=' + var.getValue()); + } + // Add in the serial port based on launch config + IArduinoRemoteConnection arduinoRemote = connection.getService(IArduinoRemoteConnection.class); + envVarList.add("SERIAL_PORT=" + arduinoRemote.getPortName()); //$NON-NLS-1$ + String[] envp = envVarList.toArray(new String[envVarList.size()]); + + // The project directory to launch from + File projectDir = new File(project.getLocationURI()); + + // The build command + IConfiguration buildConfig = ManagedBuildManager.getConfigurationForDescription(configDesc); + String command = buildConfig.getBuilder().getCommand(); + + // If opened, temporarily close the connection so we can use it to download the firmware. + boolean wasOpened = connection.isOpen(); + if (wasOpened) { + arduinoRemote.pause(); + } + + // Run the process and capture the results in the console + Process process = Runtime.getRuntime().exec(command + " load", envp, projectDir); //$NON-NLS-1$ + consoleService.monitor(process); + try { + process.waitFor(); + } catch (InterruptedException e) { + } + + // Reopen the connection + if (wasOpened) { + arduinoRemote.resume(); + } + } catch (CoreException e) { + return e.getStatus(); + } catch (IOException e) { + return new Status(IStatus.ERROR, Activator.getId(), e.getLocalizedMessage(), e); + } finally { + DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch); + } + + return Status.OK_STATUS; + }; + }.schedule(); + } + + private ArduinoLaunchConsoleService getConsoleService() throws CoreException { + IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(Activator.getId(), "consoleService"); //$NON-NLS-1$ + IExtension extension = point.getExtensions()[0]; // should only be one + return (ArduinoLaunchConsoleService) extension.getConfigurationElements()[0].createExecutableExtension("class"); //$NON-NLS-1$ + } + + /** + * Returns the build configuration for the active target and the launch configuration. + * + * @param launchConfig + * @return + */ + private ICConfigurationDescription getBuildConfiguration(ICProjectDescription projDesc, IRemoteConnection remoteConnection) throws CoreException { + IArduinoRemoteConnection arduinoRemote = remoteConnection.getService(IArduinoRemoteConnection.class); + String boardId = arduinoRemote.getBoard().getId(); + + for (ICConfigurationDescription configDesc : projDesc.getConfigurations()) { + IConfiguration config = ManagedBuildManager.getConfigurationForDescription(configDesc); + if (ArduinoProjectGenerator.getBoard(config).getId().equals(boardId)) + return configDesc; + } + + return null; + } + + private IRemoteConnection getActiveRemote(ILaunchConfiguration configuration) { + IRemoteLaunchConfigService remoteLaunchService = Activator.getService(IRemoteLaunchConfigService.class); + return remoteLaunchService.getActiveConnection(configuration); + } +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/launch/ArduinoLaunchConfigurationProvider.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/launch/ArduinoLaunchConfigurationProvider.java new file mode 100644 index 00000000000..ac1eba5cd97 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/launch/ArduinoLaunchConfigurationProvider.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.arduino.core.internal.launch; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.launchbar.core.ProjectLaunchConfigurationProvider; + +public class ArduinoLaunchConfigurationProvider extends ProjectLaunchConfigurationProvider { + + @Override + public ILaunchConfigurationType getLaunchConfigurationType() throws CoreException { + return ArduinoLaunchConfigurationDelegate.getLaunchConfigurationType(); + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/launch/ArduinoLaunchDescriptorType.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/launch/ArduinoLaunchDescriptorType.java new file mode 100644 index 00000000000..6b7a8076149 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/launch/ArduinoLaunchDescriptorType.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.arduino.core.internal.launch; + +import org.eclipse.cdt.arduino.core.internal.ArduinoProjectNature; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.launchbar.core.ILaunchDescriptor; +import org.eclipse.launchbar.core.ILaunchDescriptorType; +import org.eclipse.launchbar.core.ProjectLaunchDescriptor; + +public class ArduinoLaunchDescriptorType implements ILaunchDescriptorType { + + @Override + public boolean ownsLaunchObject(Object element) throws CoreException { + if (element instanceof IProject) { + return ArduinoProjectNature.hasNature((IProject) element); + } + + return false; + } + + @Override + public ILaunchDescriptor getDescriptor(Object element) throws CoreException { + if (element instanceof IProject) { + return new ProjectLaunchDescriptor(this, (IProject) element); + } + + return null; + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/messages.properties b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/messages.properties new file mode 100644 index 00000000000..20b2cca975c --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/messages.properties @@ -0,0 +1,13 @@ +ArduinoLaunchConfigurationDelegate_1=No active Arduino remote connection. +################################################################################ +# Copyright (c) 2015 QNX Software Systems and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# QNX Software Systems - Initial API and implementation +################################################################################ +ArduinoLaunchConfigurationDelegate_0=Arduino Launch +ArduinoProjectGenerator_0=Write Arduino project file diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/remote/ArduinoBoardManager.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/remote/ArduinoBoardManager.java new file mode 100644 index 00000000000..e1cd81afaf2 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/remote/ArduinoBoardManager.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.arduino.core.internal.remote; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.eclipse.cdt.arduino.core.Board; +import org.eclipse.cdt.arduino.core.IArduinoBoardManager; +import org.eclipse.cdt.arduino.core.internal.ArduinoHome; + +public class ArduinoBoardManager implements IArduinoBoardManager { + + private Map boards; + + @Override + public Board getBoard(String id) { + init(); + return boards.get(id); + } + + @Override + public Collection getBoards() { + init(); + List sortedBoards = new ArrayList(boards.values()); + Collections.sort(sortedBoards, new Comparator() { + @Override + public int compare(Board arg0, Board arg1) { + return arg0.getName().compareTo(arg1.getName()); + } + }); + return sortedBoards; + } + + private void init() { + if (boards != null) + return; + boards = new HashMap<>(); + File home = ArduinoHome.get(); + if (!home.isDirectory()) + return; + + File archRoot = new File(home, "hardware/arduino"); //$NON-NLS-1$ + for (File archDir : archRoot.listFiles()) { + File boardFile = new File(archDir, "boards.txt"); //$NON-NLS-1$ + loadBoardFile(archDir.getName(), boardFile); + } + } + + private void loadBoardFile(String arch, File boardFile) { + try { + Properties boardProps = new Properties(); + boardProps.load(new FileInputStream(boardFile)); + Enumeration i = boardProps.propertyNames(); + while (i.hasMoreElements()) { + String propertyName = (String) i.nextElement(); + String[] names = propertyName.split("\\."); //$NON-NLS-1$ + if (names.length == 2 && names[1].equals("name")) { //$NON-NLS-1$ + boards.put(names[0], new Board(names[0], boardProps)); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/remote/ArduinoRemoteConnection.java b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/remote/ArduinoRemoteConnection.java new file mode 100644 index 00000000000..96532846643 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/remote/ArduinoRemoteConnection.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.arduino.core.internal.remote; + +import java.io.IOException; + +import org.eclipse.cdt.arduino.core.Board; +import org.eclipse.cdt.arduino.core.IArduinoBoardManager; +import org.eclipse.cdt.arduino.core.IArduinoRemoteConnection; +import org.eclipse.cdt.arduino.core.internal.Activator; +import org.eclipse.cdt.serial.SerialPort; +import org.eclipse.remote.core.IRemoteCommandShellService; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteConnectionPropertyService; +import org.eclipse.remote.core.IRemoteProcess; +import org.eclipse.remote.serial.core.SerialPortCommandShell; + +public class ArduinoRemoteConnection implements IRemoteConnectionPropertyService, IRemoteCommandShellService, IArduinoRemoteConnection { + + private final IArduinoBoardManager boardManager = Activator.getService(IArduinoBoardManager.class); + private final IRemoteConnection remoteConnection; + private SerialPort serialPort; + private SerialPortCommandShell commandShell; + + public ArduinoRemoteConnection(IRemoteConnection remoteConnection) { + this.remoteConnection = remoteConnection; + } + + public static class Factory implements IRemoteConnection.Service.Factory { + @SuppressWarnings("unchecked") + @Override + public T getService(IRemoteConnection remoteConnection, Class service) { + if (IArduinoRemoteConnection.class.equals(service)) { + return (T) new ArduinoRemoteConnection(remoteConnection); + } else if (IRemoteConnectionPropertyService.class.equals(service) + || IRemoteCommandShellService.class.equals(service)) { + return (T) remoteConnection.getService(IArduinoRemoteConnection.class); + } + return null; + } + } + + @Override + public IRemoteConnection getRemoteConnection() { + return remoteConnection; + } + + @Override + public String getProperty(String key) { + if (IRemoteConnection.OS_NAME_PROPERTY.equals(key)) { + return "arduino"; //$NON-NLS-1$ + } else if (IRemoteConnection.OS_ARCH_PROPERTY.equals(key)) { + return "avr"; // TODO handle arm //$NON-NLS-1$ + } else { + return null; + } + } + + @Override + public Board getBoard() { + String boardId = remoteConnection.getAttribute(BOARD_ID); + return boardManager.getBoard(boardId); + } + + @Override + public String getPortName() { + return remoteConnection.getAttribute(PORT_NAME); + } + + + @Override + public IRemoteProcess getCommandShell(int flags) throws IOException { + if (serialPort != null && serialPort.isOpen()) { + // can only have one open at a time + return null; + } + + serialPort = new SerialPort(getPortName()); + commandShell = new SerialPortCommandShell(remoteConnection, serialPort); + return commandShell; + } + + @Override + public void pause() { + if (serialPort != null) { + try { + if (serialPort.isOpen()) + serialPort.pause(); + } catch (IOException e) { + Activator.log(e); + } + } + } + + @Override + public void resume() { + if (serialPort != null) { + try { + if (serialPort.isOpen()) + serialPort.resume(); + } catch (IOException e) { + Activator.log(e); + } + } + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/templates/Makefile b/toolchains/arduino/org.eclipse.cdt.arduino.core/templates/Makefile new file mode 100644 index 00000000000..7383bed636a --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/templates/Makefile @@ -0,0 +1,3 @@ +EXE = ${projectName} + +include $(ARDUINO_HOME)/arduino.mk diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.core/templates/arduino.cpp b/toolchains/arduino/org.eclipse.cdt.arduino.core/templates/arduino.cpp new file mode 100644 index 00000000000..ddfe4da79b6 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.core/templates/arduino.cpp @@ -0,0 +1,9 @@ +#include + +void setup() { + +} + +void loop() { + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/.classpath b/toolchains/arduino/org.eclipse.cdt.arduino.ui/.classpath new file mode 100644 index 00000000000..b9a5b1ec649 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/.gitignore b/toolchains/arduino/org.eclipse.cdt.arduino.ui/.gitignore new file mode 100644 index 00000000000..b83d22266ac --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/.project b/toolchains/arduino/org.eclipse.cdt.arduino.ui/.project new file mode 100644 index 00000000000..25563f6d13c --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/.project @@ -0,0 +1,39 @@ + + + org.eclipse.cdt.arduino.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/.settings/org.eclipse.jdt.core.prefs b/toolchains/arduino/org.eclipse.cdt.arduino.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..f42de363afa --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/.settings/org.eclipse.m2e.core.prefs b/toolchains/arduino/org.eclipse.cdt.arduino.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000000..f897a7f1cb2 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/META-INF/MANIFEST.MF b/toolchains/arduino/org.eclipse.cdt.arduino.ui/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..70675b0bd7c --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/META-INF/MANIFEST.MF @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Arduino UI +Bundle-SymbolicName: org.eclipse.cdt.arduino.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.eclipse.cdt.arduino.ui.internal.Activator +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.core.expressions, + org.eclipse.ui, + org.eclipse.ui.forms, + org.eclipse.ui.console, + org.eclipse.ui.ide, + org.eclipse.debug.ui, + org.eclipse.launchbar.core, + org.eclipse.launchbar.ui, + org.eclipse.cdt.arduino.core, + org.eclipse.remote.core;bundle-version="2.0.0", + org.eclipse.remote.ui;bundle-version="2.0.0", + org.eclipse.cdt.core, + org.eclipse.cdt.native.serial;bundle-version="1.0.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Bundle-ActivationPolicy: lazy diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/about.html b/toolchains/arduino/org.eclipse.cdt.arduino.ui/about.html new file mode 100644 index 00000000000..d7c511887d6 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/about.html @@ -0,0 +1,24 @@ + + +About + + +

About This Content

+ +

June 22, 2007

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + \ No newline at end of file diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/build.properties b/toolchains/arduino/org.eclipse.cdt.arduino.ui/build.properties new file mode 100644 index 00000000000..1eb98901393 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/build.properties @@ -0,0 +1,6 @@ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + icons/,\ + about.html +source.. = src/ diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/icons/arduino.png b/toolchains/arduino/org.eclipse.cdt.arduino.ui/icons/arduino.png new file mode 100644 index 00000000000..2c45ddc2c1a Binary files /dev/null and b/toolchains/arduino/org.eclipse.cdt.arduino.ui/icons/arduino.png differ diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/icons/cprojects.gif b/toolchains/arduino/org.eclipse.cdt.arduino.ui/icons/cprojects.gif new file mode 100644 index 00000000000..fcc08ad89c6 Binary files /dev/null and b/toolchains/arduino/org.eclipse.cdt.arduino.ui/icons/cprojects.gif differ diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/icons/newcc_app.gif b/toolchains/arduino/org.eclipse.cdt.arduino.ui/icons/newcc_app.gif new file mode 100644 index 00000000000..4b39411daf5 Binary files /dev/null and b/toolchains/arduino/org.eclipse.cdt.arduino.ui/icons/newcc_app.gif differ diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/plugin.xml b/toolchains/arduino/org.eclipse.cdt.arduino.ui/plugin.xml new file mode 100644 index 00000000000..3879b043204 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/plugin.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/pom.xml b/toolchains/arduino/org.eclipse.cdt.arduino.ui/pom.xml new file mode 100644 index 00000000000..f5173c9ba76 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + + org.eclipse.cdt + cdt-parent + 8.6.0-SNAPSHOT + ../../../pom.xml + + + org.eclipse.cdt.arduino.ui + 1.0.0-SNAPSHOT + eclipse-plugin + diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/Activator.java b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/Activator.java new file mode 100644 index 00000000000..d9252a18b76 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/Activator.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.arduino.ui.internal; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.cdt.arduino.ui"; //$NON-NLS-1$ + + public static final String IMG_ARDUINO = "arduino"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + + ImageRegistry imageRegistry = getImageRegistry(); + imageRegistry.put(IMG_ARDUINO, imageDescriptorFromPlugin(PLUGIN_ID, "icons/cprojects.gif")); //$NON-NLS-1$ + } + + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + public static BundleContext getContext() { + return plugin.getBundle().getBundleContext(); + } + + public static String getId() { + return plugin.getBundle().getSymbolicName(); + } + + public Image getImage(String id) { + return getImageRegistry().get(id); + } + + public static void log(Exception e) { + if (e instanceof CoreException) { + plugin.getLog().log(((CoreException) e).getStatus()); + } else { + plugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e)); + } + } + + public static T getService(Class service) { + BundleContext context = plugin.getBundle().getBundleContext(); + ServiceReference ref = context.getServiceReference(service); + return ref != null ? context.getService(ref) : null; + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/launch/ArduinoDescriptorLabelProvider.java b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/launch/ArduinoDescriptorLabelProvider.java new file mode 100644 index 00000000000..08f9242861a --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/launch/ArduinoDescriptorLabelProvider.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.arduino.ui.internal.launch; + +import org.eclipse.cdt.arduino.ui.internal.Activator; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.launchbar.core.ILaunchDescriptor; +import org.eclipse.swt.graphics.Image; + +public class ArduinoDescriptorLabelProvider extends LabelProvider { + + @Override + public Image getImage(Object element) { + return Activator.getDefault().getImage(Activator.IMG_ARDUINO); + } + + @Override + public String getText(Object element) { + if (element instanceof ILaunchDescriptor) + return ((ILaunchDescriptor) element).getName(); + return super.getText(element); + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/launch/ArduinoLaunchConsole.java b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/launch/ArduinoLaunchConsole.java new file mode 100644 index 00000000000..9365db0edc4 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/launch/ArduinoLaunchConsole.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.arduino.ui.internal.launch; + +import java.io.IOException; +import java.io.InputStream; + +import org.eclipse.cdt.arduino.core.ArduinoLaunchConsoleService; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IOConsoleOutputStream; +import org.eclipse.ui.console.MessageConsole; +import org.eclipse.ui.progress.UIJob; + +public class ArduinoLaunchConsole implements ArduinoLaunchConsoleService { + + private static MessageConsole console; + + public ArduinoLaunchConsole() { + if (console == null) { + console = new MessageConsole("Arduino Launch", null); + ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console }); + } + } + + @Override + public void monitor(final Process process) { + console.clearConsole(); + console.activate(); + + new UIJob("Start Arduino Console") { + @Override + public IStatus runInUIThread(IProgressMonitor monitor) { + final IOConsoleOutputStream out = console.newOutputStream(); + out.setColor(Display.getDefault().getSystemColor(SWT.COLOR_BLACK)); + new Thread("Arduino Launch Console Output") { + public void run() { + try (InputStream processOut = process.getInputStream()) { + for (int c = processOut.read(); c >= 0; c = processOut.read()) { + out.write(c); + } + } catch (IOException e) { + // Nothing. Just exit + } + } + }.start(); + + final IOConsoleOutputStream err = console.newOutputStream(); + err.setColor(Display.getDefault().getSystemColor(SWT.COLOR_RED)); + new Thread("Arduino Launch Console Output") { + public void run() { + try (InputStream processErr = process.getErrorStream()) { + for (int c = processErr.read(); c >= 0; c = processErr.read()) { + err.write(c); + } + } catch (IOException e) { + // Nothing. Just exit + } + } + }.start(); + + return Status.OK_STATUS; + } + }.schedule(); + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/project/NewArduinoProjectWizard.java b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/project/NewArduinoProjectWizard.java new file mode 100644 index 00000000000..58fc1d2d8ca --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/project/NewArduinoProjectWizard.java @@ -0,0 +1,53 @@ +package org.eclipse.cdt.arduino.ui.internal.project; + +import org.eclipse.cdt.arduino.core.ArduinoProjectGenerator; +import org.eclipse.cdt.arduino.ui.internal.Activator; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard; + +public class NewArduinoProjectWizard extends BasicNewProjectResourceWizard { + + @Override + public void addPages() { + super.addPages(); + } + + @Override + public boolean performFinish() { + if (!super.performFinish()) + return false; + + new Job("Creating Aurdino Project") { + protected IStatus run(IProgressMonitor monitor) { + try { + final ArduinoProjectGenerator generator = new ArduinoProjectGenerator(getNewProject()); + generator.setupArduinoProject(monitor); + getWorkbench().getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + try { + IWorkbenchPage activePage = getWorkbench().getActiveWorkbenchWindow().getActivePage(); + IDE.openEditor(activePage, generator.getSourceFile()); + } catch (PartInitException e) { + Activator.getDefault().getLog().log(e.getStatus()); + } + } + }); + return Status.OK_STATUS; + } catch (CoreException e) { + return e.getStatus(); + } + } + }.schedule(); + + return true; + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/ArduinoRemoteServicesUI.java b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/ArduinoRemoteServicesUI.java new file mode 100644 index 00000000000..39caf9f327d --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/ArduinoRemoteServicesUI.java @@ -0,0 +1,67 @@ +package org.eclipse.cdt.arduino.ui.internal.remote; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.cdt.arduino.ui.internal.Activator; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.PlatformObject; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.operation.IRunnableContext; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.IRemoteConnectionType.Service; +import org.eclipse.remote.core.exception.RemoteConnectionException; +import org.eclipse.remote.ui.IRemoteUIConnectionService; +import org.eclipse.remote.ui.IRemoteUIConnectionWizard; +import org.eclipse.swt.widgets.Shell; + +public class ArduinoRemoteServicesUI extends PlatformObject implements IRemoteUIConnectionService { + + private final IRemoteConnectionType connectionType; + + public ArduinoRemoteServicesUI(IRemoteConnectionType connectionType) { + this.connectionType = connectionType; + } + + @Override + public void openConnectionWithProgress(Shell shell, IRunnableContext context, final IRemoteConnection connection) { + try { + context.run(false, true, new IRunnableWithProgress() { + @Override + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + try { + connection.open(monitor); + } catch (RemoteConnectionException e) { + Activator.getDefault().getLog().log(e.getStatus()); + } + } + }); + } catch (InvocationTargetException | InterruptedException e) { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getLocalizedMessage(), e)); + } + } + + @Override + public IRemoteConnectionType getConnectionType() { + return connectionType; + } + + @Override + public IRemoteUIConnectionWizard getConnectionWizard(Shell shell) { + return new NewArduinoTargetWizard(); + } + + public static class Factory implements IRemoteConnectionType.Service.Factory { + @SuppressWarnings("unchecked") + @Override + public T getService(IRemoteConnectionType connectionType, Class service) { + if (IRemoteUIConnectionService.class.equals(service)) { + return (T) new ArduinoRemoteServicesUI(connectionType); + } + return null; + } + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/ArduinoTargetPropertyPage.java b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/ArduinoTargetPropertyPage.java new file mode 100644 index 00000000000..3d03a76c259 --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/ArduinoTargetPropertyPage.java @@ -0,0 +1,111 @@ +package org.eclipse.cdt.arduino.ui.internal.remote; + +import java.io.IOException; +import java.util.Collection; + +import org.eclipse.cdt.arduino.core.Board; +import org.eclipse.cdt.arduino.core.IArduinoBoardManager; +import org.eclipse.cdt.arduino.core.IArduinoRemoteConnection; +import org.eclipse.cdt.arduino.ui.internal.Activator; +import org.eclipse.cdt.serial.SerialPort; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; +import org.eclipse.remote.core.exception.RemoteConnectionException; +import org.eclipse.swt.SWT; +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.Label; +import org.eclipse.ui.IWorkbenchPropertyPage; +import org.eclipse.ui.dialogs.PropertyPage; + +public class ArduinoTargetPropertyPage extends PropertyPage implements IWorkbenchPropertyPage { + + private Combo portSelector; + private Combo boardSelector; + + private Board[] boards; + + @Override + protected Control createContents(Composite parent) { + Composite comp = new Composite(parent, SWT.NONE); + comp.setLayout(new GridLayout(2, false)); + + IRemoteConnection remoteConnection = (IRemoteConnection) getElement().getAdapter(IRemoteConnection.class); + IArduinoRemoteConnection arduinoRemote = remoteConnection.getService(IArduinoRemoteConnection.class); + + Label portLabel = new Label(comp, SWT.NONE); + portLabel.setText("Serial Port:"); + + portSelector = new Combo(comp, SWT.READ_ONLY); + portSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + String currentPort = arduinoRemote.getPortName(); + int i = 0, portSel = -1; + try { + for (String port : SerialPort.list()) { + portSelector.add(port); + if (port.equals(currentPort)) { + portSel = i; + } else { + portSel = portSel < 0 ? 0 : portSel; + } + i++; + } + } catch (IOException e) { + Activator.log(e); + } + if (portSel >= 0) { + portSelector.select(portSel); + } else { + setMessage("No serial ports", ERROR); + setValid(false); + } + + Label boardLabel = new Label(comp, SWT.NONE); + boardLabel.setText("Board type:"); + + boardSelector = new Combo(comp, SWT.READ_ONLY); + boardSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Board currentBoard = arduinoRemote.getBoard(); + IArduinoBoardManager boardManager = Activator.getService(IArduinoBoardManager.class); + Collection boardList = boardManager.getBoards(); + boards = new Board[boardList.size()]; + i = 0; + int boardSel = 0; + for (Board board : boardList) { + boards[i] = board; + boardSelector.add(board.getName()); + if (board.equals(currentBoard)) { + boardSel = i; + } + i++; + } + boardSelector.select(boardSel); + + return comp; + } + + @Override + public boolean performOk() { + IRemoteConnection remoteConnection = (IRemoteConnection) getElement().getAdapter(IRemoteConnection.class); + IRemoteConnectionWorkingCopy workingCopy = remoteConnection.getWorkingCopy(); + + String portName = portSelector.getItem(portSelector.getSelectionIndex()); + workingCopy.setAttribute(IArduinoRemoteConnection.PORT_NAME, portName); + + Board board = boards[boardSelector.getSelectionIndex()]; + workingCopy.setAttribute(IArduinoRemoteConnection.BOARD_ID, board.getId()); + + try { + workingCopy.save(); + } catch (RemoteConnectionException e) { + Activator.getDefault().getLog().log(e.getStatus()); + } + return true; + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/NewArduinoTargetWizard.java b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/NewArduinoTargetWizard.java new file mode 100644 index 00000000000..a3d905a508e --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/NewArduinoTargetWizard.java @@ -0,0 +1,72 @@ +package org.eclipse.cdt.arduino.ui.internal.remote; + +import java.util.Set; + +import org.eclipse.cdt.arduino.core.IArduinoRemoteConnection; +import org.eclipse.cdt.arduino.ui.internal.Activator; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; +import org.eclipse.remote.core.IRemoteServicesManager; +import org.eclipse.remote.core.exception.RemoteConnectionException; +import org.eclipse.remote.ui.IRemoteUIConnectionWizard; + +public class NewArduinoTargetWizard extends Wizard implements IRemoteUIConnectionWizard { + + private NewArduinoTargetWizardPage page; + private IRemoteConnectionWorkingCopy workingCopy; + + @Override + public void addPages() { + page = new NewArduinoTargetWizardPage(); + addPage(page); + } + + @Override + public boolean performFinish() { + if (getConnection() == null) { + return false; + } + + workingCopy.setAttribute(IArduinoRemoteConnection.PORT_NAME, page.portName); + workingCopy.setAttribute(IArduinoRemoteConnection.BOARD_ID, page.board.getId()); + return true; + } + + @Override + public IRemoteConnectionWorkingCopy open() { + return getConnection(); + } + + @Override + public IRemoteConnectionWorkingCopy getConnection() { + if (workingCopy == null) { + IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class); + IRemoteConnectionType connectionType = remoteManager.getConnectionType(IArduinoRemoteConnection.TYPE_ID); + try { + workingCopy = connectionType.newConnection(page.name); + } catch (RemoteConnectionException e) { + Activator.getDefault().getLog().log(e.getStatus()); + return null; + } + } + + return workingCopy; + } + + @Override + public void setConnection(IRemoteConnectionWorkingCopy connection) { + workingCopy = connection; + } + + @Override + public void setConnectionName(String name) { + // TODO Auto-generated method stub + } + + @Override + public void setInvalidConnectionNames(Set names) { + // TODO Auto-generated method stub + } + +} diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/NewArduinoTargetWizardPage.java b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/NewArduinoTargetWizardPage.java new file mode 100644 index 00000000000..522f4142fef --- /dev/null +++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/NewArduinoTargetWizardPage.java @@ -0,0 +1,120 @@ +package org.eclipse.cdt.arduino.ui.internal.remote; + +import java.io.IOException; + +import org.eclipse.cdt.arduino.core.Board; +import org.eclipse.cdt.arduino.core.IArduinoBoardManager; +import org.eclipse.cdt.arduino.ui.internal.Activator; +import org.eclipse.cdt.serial.SerialPort; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +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; + +public class NewArduinoTargetWizardPage extends WizardPage { + + String name; + private Text nameText; + + String portName; + private String[] portNames; + private Combo portCombo; + + Board board; + private Board[] boards; + private Combo boardCombo; + + public NewArduinoTargetWizardPage() { + super("NewArduinoTargetPage"); + setDescription("New Arduino Target settings"); + setTitle("New Arduino Target"); + } + + @Override + public void createControl(Composite parent) { + Composite comp = new Composite(parent, SWT.NONE); + comp.setLayout(new GridLayout(2, false)); + + Label nameLabel = new Label(comp, SWT.NONE); + nameLabel.setText("Target name:"); + + nameText = new Text(comp, SWT.BORDER | SWT.SINGLE); + nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + nameText.setText(""); + nameText.addKeyListener(new KeyListener() { + @Override + public void keyReleased(KeyEvent e) { + updateStatus(); + } + + @Override + public void keyPressed(KeyEvent e) { + } + }); + + Label portLabel = new Label(comp, SWT.NONE); + portLabel.setText("Serial port:"); + + 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(); + } + }); + + IArduinoBoardManager boardManager = Activator.getService(IArduinoBoardManager.class); + + Label boardLabel = new Label(comp, SWT.NONE); + boardLabel.setText("Board type:"); + + boardCombo = new Combo(comp, SWT.READ_ONLY); + boardCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + boards = boardManager.getBoards().toArray(new Board[0]); + for (Board board : boards) { + boardCombo.add(board.getName()); + } + boardCombo.select(0); + boardCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + updateStatus(); + } + }); + + setControl(comp); + setPageComplete(false); + } + + private void updateStatus() { + name = nameText.getText(); + + 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); + } + +} -- cgit v1.2.3