1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Bug 466209 - Initial commit of Arduino plugins.

Includes freemarker jar which we have CQ approval for.

Change-Id: I8f36cd7f4539497bab5f106f84216f75a25da3a0
This commit is contained in:
Doug Schaefer 2015-05-02 22:58:18 -04:00
parent cb16665cc7
commit 076e141b69
65 changed files with 2754 additions and 6 deletions

View file

@ -3,3 +3,4 @@ bin
javaCompiler...args javaCompiler...args
build.xml build.xml
target target
/workspace/

View file

@ -28,6 +28,8 @@ public class SerialPort {
private final String portName; private final String portName;
private boolean isOpen; private boolean isOpen;
private boolean isPaused;
private Object pauseMutex = new Object();
private BaudRate baudRate = BaudRate.B115200; private BaudRate baudRate = BaudRate.B115200;
private ByteSize byteSize = ByteSize.B8; private ByteSize byteSize = ByteSize.B8;
private Parity parity = Parity.None; private Parity parity = Parity.None;
@ -56,7 +58,19 @@ public class SerialPort {
while (true) { while (true) {
rlen = read1(handle, rbuff, 0, rbuff.length); rlen = read1(handle, rbuff, 0, rbuff.length);
if (rlen < 0) { 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) { } else if (rlen > 0) {
break; break;
} }
@ -79,8 +93,22 @@ public class SerialPort {
System.arraycopy(rbuff, rpos, b, off, n); System.arraycopy(rbuff, rpos, b, off, n);
rpos += n; rpos += n;
return n; return n;
} else { } else {
return read1(handle, b, off, len); 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 { } else {
return -1; return -1;
@ -97,14 +125,44 @@ public class SerialPort {
@Override @Override
public void write(int b) throws IOException { public void write(int b) throws IOException {
if (isOpen()) { 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 @Override
public void write(byte[] buff, int off, int len) throws IOException { public void write(byte[] buff, int off, int len) throws IOException {
if (isOpen()) { 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; 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 { public void setBaudRate(BaudRate rate) throws IOException {
if (isOpen) { if (isOpen) {
throw new IOException(PORT_OPEN); throw new IOException(PORT_OPEN);

View file

@ -216,6 +216,10 @@
<module>remote/org.eclipse.cdt.remote.core</module> <module>remote/org.eclipse.cdt.remote.core</module>
<module>remote/org.eclipse.cdt.remote-feature</module> <module>remote/org.eclipse.cdt.remote-feature</module>
<module>toolchains/arduino/org.eclipse.cdt.arduino.core</module>
<module>toolchains/arduino/org.eclipse.cdt.arduino.ui</module>
<module>toolchains/arduino/org.eclipse.cdt.arduino-feature</module>
<!-- <!--
<module>lrparser/org.eclipse.cdt.core.lrparser.tests</module> <module>lrparser/org.eclipse.cdt.core.lrparser.tests</module>
<module>upc/org.eclipse.cdt.core.parser.upc.tests</module> <module>upc/org.eclipse.cdt.core.parser.upc.tests</module>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?><target name="cdt_e4.5" sequenceNumber="24"> <?pde version="3.8"?><target name="cdt_e4.5" sequenceNumber="25">
<locations> <locations>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit"> <location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.apache.commons.compress" version="0.0.0"/> <unit id="org.apache.commons.compress" version="0.0.0"/>
@ -24,6 +24,7 @@
</location> </location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit"> <location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.remote.feature.group" version="0.0.0"/> <unit id="org.eclipse.remote.feature.group" version="0.0.0"/>
<unit id="org.eclipse.remote.serial.feature.group" version="0.0.0"/>
<repository location="http://download.eclipse.org/tools/ptp/builds/remote/2.0.0/"/> <repository location="http://download.eclipse.org/tools/ptp/builds/remote/2.0.0/"/>
</location> </location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit"> <location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
@ -35,6 +36,14 @@
<unit id="org.eclipse.sdk.ide" version="0.0.0"/> <unit id="org.eclipse.sdk.ide" version="0.0.0"/>
<repository location="http://download.eclipse.org/eclipse/updates/4.5milestones/"/> <repository location="http://download.eclipse.org/eclipse/updates/4.5milestones/"/>
</location> </location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.launchbar.feature.group" version="0.0.0"/>
<repository location="https://hudson.eclipse.org/cdt/job/launchbar-master/lastSuccessfulBuild/artifact/repo/target/repository/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.cdt.native.feature.group" version="0.0.0"/>
<repository location="https://hudson.eclipse.org/cdt/job/cdt-master/lastSuccessfulBuild/artifact/releng/org.eclipse.cdt.repo/target/repository/"/>
</location>
</locations> </locations>
<targetJRE path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> <targetJRE path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<launcherArgs> <launcherArgs>

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.cdt.arduino</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
<filteredResources>
<filter>
<id>1430580875530</id>
<name></name>
<type>10</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-org.eclipse.cdt.*</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>

View file

@ -0,0 +1 @@
/target/

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.cdt.arduino-feature</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.pde.FeatureBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.FeatureNature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View file

@ -0,0 +1,113 @@
VERSION = 156
BOARD ?= uno
OUTPUT_DIR ?= build/Default
rwildcard = $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
ifeq ($(OS),Windows_NT)
RMDIR = rmdir /s /q
fixpath = $(subst /,\,$1)
mymkdir = if not exist "$(call fixpath,$1)" mkdir $(call fixpath,$1)
else
RMDIR = rm -fr
fixpath = $1
mymkdir = mkdir -p $1
endif
ifeq ($(BOARD),uno)
ARCH = avr
BUILD_CORE = arduino
BUILD_VARIANT = standard
BUILD_MCU = atmega328p
BUILD_F_CPU = 16000000L
BUILD_BOARD = AVR_UNO
LOADER = avrdude
LOADER_PROTOCOL = arduino
LOADER_SPEED = 115200
LOADER_MAX_SIZE = 32256
LOADER_MAX_DATA = 2048
endif
ifeq ($(ARCH),avr)
CXXFLAGS = -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD \
-mmcu=$(BUILD_MCU) -DF_CPU=$(BUILD_F_CPU) -DARDUINO=$(VERSION) -DARDUINO_$(BUILD_BOARD) -DARDUINO_ARCH_AVR $(INCLUDES)
CFLAGS = -g -Os -w -ffunction-sections -fdata-sections -MMD \
-mmcu=$(BUILD_MCU) -DF_CPU=$(BUILD_F_CPU) -DARDUINO=156 -DARDUINO_$(BUILD_BOARD) -DARDUINO_ARCH_AVR $(INCLUDES)
CXX = avr-g++
CC = avr-gcc
AR = avr-ar
OBJCOPY = avr-objcopy
define do_link
$(CC) -Os -Wl,--gc-sections -mmcu=$(BUILD_MCU) -o $(OUTPUT_DIR)/$(EXE).elf $^
avr-objcopy -O ihex -R .eeprom $(OUTPUT_DIR)/$(EXE).elf $(OUTPUT_DIR)/$(EXE).hex
$(do_link_extra)
avr-size $(OUTPUT_DIR)/$(EXE).elf
@echo Max text: $(LOADER_MAX_SIZE)
@echo Max data + bss: $(LOADER_MAX_DATA)
endef
define do_eeprom
avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load \
--no-change-warnings --change-section-lma .eeprom=0 \
$(OUTPUT_DIR)/$(EXE).elf $(OUTPUT_DIR)/$(EXE).eep
endef
define do_load_avrdude
avrdude -C"$(ARDUINO_HOME)/hardware/tools/avr/etc/avrdude.conf" -p$(BUILD_MCU) -c$(LOADER_PROTOCOL) \
-P$(SERIAL_PORT) -b$(LOADER_SPEED) -D "-Uflash:w:$(OUTPUT_DIR)/$(EXE).hex:i"
endef
endif # ARCH = avr
LIB_ROOT = $(ARDUINO_HOME)/hardware/arduino/$(ARCH)/cores/$(BUILD_CORE)
LIB_SRCS = $(call rwildcard, $(LIB_ROOT)/, *.c *.cpp)
LIB_OBJS = $(patsubst $(LIB_ROOT)/%.c, $(OUTPUT_DIR)/arduino/%.o, $(filter %.c, $(LIB_SRCS))) \
$(patsubst $(LIB_ROOT)/%.cpp, $(OUTPUT_DIR)/arduino/%.o, $(filter %.cpp, $(LIB_SRCS)))
LIBS_ROOTS = $(HOME)/Documents/Arduino/libraries $(ARDUINO_HOME)/hardware/arduino/$(ARCH)/libraries $(ARDUINO_HOME)/libraries
LIBS_DIRS = $(foreach lib, $(LIBS), $(firstword $(realpath $(foreach lib_root, $(LIBS_ROOTS), $(lib_root)/$(lib)))))
INCLUDES = -I$(ARDUINO_HOME)/hardware/arduino/$(ARCH)/cores/$(BUILD_CORE) \
-I$(ARDUINO_HOME)/hardware/arduino/$(ARCH)/variants/$(BUILD_VARIANT) \
$(foreach lib, $(LIBS_DIRS), -I$(lib))
SRCS = $(call rwildcard, ./, *.c *.cpp) $(foreach lib, $(LIBS_DIRS), $(wildcard $(lib)/*.c $(lib)/*.cpp $(lib)/utility/*.c $(lib)/utility/*.cpp))
OBJS = $(patsubst %.cpp, $(OUTPUT_DIR)/%.o, $(filter %.cpp, $(SRCS))) \
$(patsubst %.c, $(OUTPUT_DIR)/%.o, $(filter %.c, $(SRCS)))
all: $(OUTPUT_DIR)/$(EXE).hex
clean:
$(RMDIR) $(call fixpath,$(OUTPUT_DIR))
load: #$(OUTPUT_DIR)/$(EXE).hex
$(do_load_$(LOADER))
$(OUTPUT_DIR)/$(EXE).hex: $(OBJS) $(OUTPUT_DIR)/core.a
$(do_link)
$(OUTPUT_DIR)/core.a: $(LIB_OBJS)
$(AR) r $@ $?
$(OUTPUT_DIR)/arduino/%.o: $(LIB_ROOT)/%.c
@-$(call mymkdir,$(dir $@))
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
$(OUTPUT_DIR)/arduino/%.o: $(LIB_ROOT)/%.cpp
@-$(call mymkdir,$(dir $@))
$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -o $@ $<
$(OUTPUT_DIR)/%.o: %.c
@-$(call mymkdir,$(dir $@))
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
$(OUTPUT_DIR)/%.o: %.cpp
@-$(call mymkdir,$(dir $@))
$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -o $@ $<

View file

@ -0,0 +1 @@
bin.includes = feature.xml

View file

@ -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
###############################################################################
# features.properties
# contains externalized strings for feature.xml
# "%foo" in feature.xml corresponds to the key "foo" in this file
# java.io.Properties file (ISO 8859-1 with "\" escapes)
# This file should be translated.
# "featureName" property - name of the feature
featureName=Arduino C++ Tools
# "providerName" property - name of the company that provides the feature
providerName=Eclipse CDT
# "description" property - description of the feature
description=Extensions to support Arduino C++ projects in Eclipse
# copyright
copyright=\
Copyright (c) 2015 QNX Software Systems and others.\n\
All rights reserved. This program and the accompanying materials\n\
are made available under the terms of the Eclipse Public License v1.0\n\
which accompanies this distribution, and is available at\n\
http://www.eclipse.org/legal/epl-v10.html

View file

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="org.eclipse.cdt.arduino"
label="%featureName"
version="1.0.0.qualifier"
provider-name="%providerName"
plugin="org.eclipse.cdt.arduino.ui"
license-feature="org.eclipse.license"
license-feature-version="0.0.0">
<description>
%description
</description>
<copyright>
%copyright
</copyright>
<license url="%licenseURL">
%license
</license>
<requires>
<import feature="org.eclipse.launchbar" version="1.0.0.qualifier"/>
<import feature="org.eclipse.remote.serial" version="1.0.0.qualifier"/>
<import feature="org.eclipse.remote" version="2.0.0.qualifier"/>
</requires>
<plugin
id="org.eclipse.cdt.arduino.core"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
<plugin
id="org.eclipse.cdt.arduino.ui"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
</feature>

View file

@ -0,0 +1,16 @@
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.cdt</groupId>
<artifactId>cdt-parent</artifactId>
<version>8.6.0-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<artifactId>org.eclipse.cdt.arduino</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-feature</packaging>
</project>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry exported="true" kind="lib" path="libs/freemarker-2.3.22.jar"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View file

@ -0,0 +1,2 @@
/bin/
/target/

View file

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.cdt.arduino.core</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

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

View file

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View file

@ -0,0 +1,22 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Arduino C++ Core
Bundle-SymbolicName: org.eclipse.cdt.arduino.core;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.eclipse.cdt.arduino.core.internal.Activator
Bundle-Vendor: Doug Schaefer
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.debug.core,
org.eclipse.cdt.core,
org.eclipse.cdt.managedbuilder.core,
org.eclipse.cdt.managedbuilder.gnu.ui,
org.eclipse.launchbar.core,
org.eclipse.remote.core;bundle-version="2.0.0",
org.eclipse.cdt.native.serial;bundle-version="1.0.0",
org.eclipse.remote.serial.core;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: libs/freemarker-2.3.22.jar,
.
Export-Package: org.eclipse.cdt.arduino.core

View file

@ -0,0 +1,24 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head>
<body lang="EN-US">
<h2>About This Content</h2>
<p>June 22, 2007</p>
<h3>License</h3>
<p>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 <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
For purposes of the EPL, "Program" will mean the Content.</p>
<p>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 <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
</body></html>

View file

@ -0,0 +1,8 @@
source.. = src/
bin.includes = META-INF/,\
.,\
plugin.xml,\
templates/,\
libs/freemarker-2.3.22.jar,\
about.html,\
schema/

View file

@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension-point id="consoleService" name="Arduino Launch Console Service" schema="schema/consoleService.exsd"/>
<extension
point="org.eclipse.cdt.managedbuilder.core.buildDefinitions">
<managedBuildRevision
fileVersion="4.0.0">
</managedBuildRevision>
<toolChain
archList="all"
configurationEnvironmentSupplier="org.eclipse.cdt.arduino.core.internal.EnvVarSupplier"
id="org.eclipse.cdt.arduino.toolChain.avr"
isAbstract="false"
languageSettingsProviders="org.eclipse.cdt.arduino.avr.builtins;org.eclipse.cdt.arduino.avr.outputParser"
name="Arduino AVR C++"
osList="all"
supportsManagedBuild="false">
<targetPlatform
id="org.eclipse.cdt.arduino.targetPlatform"
isAbstract="false"
name="Arduino">
</targetPlatform>
<builder
autoBuildTarget="all"
buildRunner="org.eclipse.cdt.managedbuilder.core.ExternalBuildRunner"
cleanBuildTarget="clean"
command="make"
commandLauncher="org.eclipse.cdt.core.CommandLauncher"
id="org.eclipse.cdt.arduino.builder.make"
incrementalBuildTarget="all"
isAbstract="false"
isVariableCaseSensitive="false"
name="Arduino Make">
</builder>
<tool
command="avr-g++"
id="org.eclipse.cdt.arduino.tool.avr.compiler"
isAbstract="false"
name="Arduino AVR C++ Compiler"
natureFilter="ccnature"
superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base">
</tool>
<option
category="org.eclipse.cdt.arduino.optionCategory.board"
id="org.eclipse.cdt.arduino.option.board"
isAbstract="false"
name="Board Type"
resourceFilter="all"
valueType="string">
</option>
<optionCategory
id="org.eclipse.cdt.arduino.optionCategory.board"
name="Board Type">
</optionCategory>
</toolChain>
</extension>
<extension
point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider
class="org.eclipse.cdt.arduino.core.internal.AvrLanguageSettingsProvider"
id="org.eclipse.cdt.arduino.avr.builtins"
name="Arduino AVR Compiler Built-ins"
parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;"
prefer-non-shared="true">
<language-scope
id="org.eclipse.cdt.core.g++">
</language-scope>
</provider>
<provider
class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser"
id="org.eclipse.cdt.arduino.avr.outputParser"
name="Arduino AVR Built Output Parser"
parameter="(avr-gcc)|(avr-g\+\+)"
prefer-non-shared="true">
</provider>
</extension>
<extension
point="org.eclipse.debug.core.launchConfigurationTypes">
<launchConfigurationType
delegate="org.eclipse.cdt.arduino.core.internal.launch.ArduinoLaunchConfigurationDelegate"
id="org.eclipse.cdt.arduino.core.launchConfigurationType"
modes="run"
name="Arduino">
</launchConfigurationType>
</extension>
<extension
point="org.eclipse.remote.core.remoteServices">
<connectionType
capabilities="7"
id="org.eclipse.cdt.arduino.core.connectionType"
name="Arduino">
</connectionType>
<connectionService
connectionTypeId="org.eclipse.cdt.arduino.core.connectionType"
factory="org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection$Factory"
service="org.eclipse.cdt.arduino.core.IArduinoRemoteConnection">
</connectionService>
<connectionService
connectionTypeId="org.eclipse.cdt.arduino.core.connectionType"
factory="org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection$Factory"
service="org.eclipse.remote.core.IRemoteCommandShellService">
</connectionService>
<connectionService
connectionTypeId="org.eclipse.cdt.arduino.core.connectionType"
factory="org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection$Factory"
service="org.eclipse.remote.core.IRemoteConnectionPropertyService">
</connectionService>
</extension>
<extension
point="org.eclipse.launchbar.core.launchBarContributions">
<descriptorType
class="org.eclipse.cdt.arduino.core.internal.launch.ArduinoLaunchDescriptorType"
id="org.eclipse.cdt.arduino.core.descriptorType"
priority="5">
</descriptorType>
<configProvider
class="org.eclipse.cdt.arduino.core.internal.launch.ArduinoLaunchConfigurationProvider"
launchConfigurationType="org.eclipse.cdt.arduino.core.launchConfigurationType">
</configProvider>
<configType
descriptorType="org.eclipse.cdt.arduino.core.descriptorType"
isDefault="true"
launchConfigurationType="org.eclipse.cdt.arduino.core.launchConfigurationType"
targetType="org.eclipse.cdt.arduino.core.targetType">
</configType>
<targetType
connectionTypeId="org.eclipse.cdt.arduino.core.connectionType"
id="org.eclipse.cdt.arduino.core.targetType">
</targetType>
</extension>
<extension
point="org.eclipse.core.contenttype.contentTypes">
<content-type
base-type="org.eclipse.cdt.core.binaryFile"
file-extensions="hex"
id="org.eclipse.cdt.arduino.core.contentType.hex"
name="Arduino Hex download file"
priority="normal">
</content-type>
</extension>
<extension
id="arduinoNature"
point="org.eclipse.core.resources.natures">
<runtime>
<run
class="org.eclipse.cdt.arduino.core.internal.ArduinoProjectNature">
</run>
</runtime>
</extension>
</plugin>

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.cdt</groupId>
<artifactId>cdt-parent</artifactId>
<version>8.6.0-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<artifactId>org.eclipse.cdt.arduino.core</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>

View file

@ -0,0 +1,102 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.cdt.arduino.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="org.eclipse.cdt.arduino.core" id="consoleService" name="Arduino Launch Console Service"/>
</appinfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<sequence>
<element ref="provider"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute translatable="true"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="provider">
<complexType>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.cdt.arduino.core.internal.launch.ArduinoLaunchConsoleService"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>

View file

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

View file

@ -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<IRemoteConnection> 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<String, Object> 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;
}
}

View file

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

View file

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

View file

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

View file

@ -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> T getService(Class<T> service) {
BundleContext context = plugin.getBundle().getBundleContext();
ServiceReference<T> ref = context.getServiceReference(service);
return ref != null ? context.getService(ref) : null;
}
}

View file

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

View file

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

View file

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

View file

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

View file

@ -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() {
}
}

View file

@ -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<String> envVarList = new ArrayList<String>(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);
}
}

View file

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

View file

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

View file

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

View file

@ -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<String, Board> boards;
@Override
public Board getBoard(String id) {
init();
return boards.get(id);
}
@Override
public Collection<Board> getBoards() {
init();
List<Board> sortedBoards = new ArrayList<Board>(boards.values());
Collections.sort(sortedBoards, new Comparator<Board>() {
@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();
}
}
}

View file

@ -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 extends IRemoteConnection.Service> T getService(IRemoteConnection remoteConnection, Class<T> 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);
}
}
}
}

View file

@ -0,0 +1,3 @@
EXE = ${projectName}
include $(ARDUINO_HOME)/arduino.mk

View file

@ -0,0 +1,9 @@
#include <Arduino.h>
void setup() {
}
void loop() {
}

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View file

@ -0,0 +1 @@
/target/

View file

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.cdt.arduino.ui</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

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

View file

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View file

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

View file

@ -0,0 +1,24 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head>
<body lang="EN-US">
<h2>About This Content</h2>
<p>June 22, 2007</p>
<h3>License</h3>
<p>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 <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
For purposes of the EPL, "Program" will mean the Content.</p>
<p>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 <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
</body></html>

View file

@ -0,0 +1,6 @@
bin.includes = META-INF/,\
.,\
plugin.xml,\
icons/,\
about.html
source.. = src/

Binary file not shown.

After

Width:  |  Height:  |  Size: 913 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

View file

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.debug.ui.launchConfigurationTypeImages">
<launchConfigurationTypeImage
configTypeID="org.eclipse.cdt.arduino.core.launchConfigurationType"
icon="icons/logo.png"
id="org.eclipse.cdt.arduino.ui.launchConfigurationTypeImage1">
</launchConfigurationTypeImage>
</extension>
<extension
point="org.eclipse.ui.newWizards">
<wizard
canFinishEarly="false"
category="org.eclipse.cdt.arduino.ui.newCategory"
class="org.eclipse.cdt.arduino.ui.internal.remote.NewArduinoTargetWizard"
hasPages="true"
icon="icons/arduino.png"
id="org.eclipse.cdt.arduino.ui.newTargetWizard"
name="Android Target"
project="false">
</wizard>
<wizard
category="org.eclipse.cdt.ui.newCWizards"
class="org.eclipse.cdt.arduino.ui.internal.project.NewArduinoProjectWizard"
icon="icons/newcc_app.gif"
id="org.eclipse.cdt.arduino.ui.newProjectWizard"
name="Arduino Project"
project="true">
</wizard>
</extension>
<extension
point="org.eclipse.cdt.arduino.core.consoleService">
<provider
class="org.eclipse.cdt.arduino.ui.internal.launch.ArduinoLaunchConsole">
</provider>
</extension>
<extension
point="org.eclipse.ui.propertyPages">
<page
class="org.eclipse.cdt.arduino.ui.internal.remote.ArduinoTargetPropertyPage"
id="org.eclipse.cdt.arduino.ui.targetPropertyPage"
name="Arduino"
selectionFilter="single">
<enabledWhen>
<adapt
type="org.eclipse.cdt.arduino.core.remote.IArduinoRemoteConnection">
</adapt>
</enabledWhen>
</page>
</extension>
<extension
point="org.eclipse.launchbar.ui.launchBarUIContributions">
<descriptorUI
descriptorTypeId="org.eclipse.cdt.arduino.core.descriptorType"
labelProvider="org.eclipse.cdt.arduino.ui.internal.launch.ArduinoDescriptorLabelProvider">
</descriptorUI>
</extension>
<extension
point="org.eclipse.remote.core.remoteServices">
<connectionTypeService
connectionTypeId="org.eclipse.cdt.arduino.core.connectionType"
factory="org.eclipse.cdt.arduino.ui.internal.remote.ArduinoRemoteServicesUI$Factory"
service="org.eclipse.remote.ui.IRemoteUIConnectionService">
</connectionTypeService>
</extension>
</plugin>

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.cdt</groupId>
<artifactId>cdt-parent</artifactId>
<version>8.6.0-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<artifactId>org.eclipse.cdt.arduino.ui</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>

View file

@ -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> T getService(Class<T> service) {
BundleContext context = plugin.getBundle().getBundleContext();
ServiceReference<T> ref = context.getServiceReference(service);
return ref != null ? context.getService(ref) : null;
}
}

View file

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

View file

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

View file

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

View file

@ -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 extends Service> T getService(IRemoteConnectionType connectionType, Class<T> service) {
if (IRemoteUIConnectionService.class.equals(service)) {
return (T) new ArduinoRemoteServicesUI(connectionType);
}
return null;
}
}
}

View file

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

View file

@ -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<String> names) {
// TODO Auto-generated method stub
}
}

View file

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