working on #223: Auto-detection of serial ports. Linux version ready

This commit is contained in:
Federico Fissore 2013-01-28 16:33:18 +01:00
parent 5b8ac97a42
commit 776952762f
9 changed files with 107 additions and 15 deletions

View File

@ -76,13 +76,13 @@
<os family="unix"/>
</condition>
<!--
<dirname property="blah" file="${java.home}" />
<echo message="here! ${java.home}/lib/tools.jar or there: ${blah}" />
<echo message="override ${env.JAVA_HOME}/lib/tools.jar" />
<fail />
-->
<javac source="1.5" target="1.5"
<!--
<dirname property="blah" file="${java.home}" />
<echo message="here! ${java.home}/lib/tools.jar or there: ${blah}" />
<echo message="override ${env.JAVA_HOME}/lib/tools.jar" />
<fail />
-->
<javac source="1.6" target="1.6"
srcdir="src"
destdir="bin"
encoding="UTF-8"
@ -97,7 +97,7 @@
<target name="test" depends="compile" description="Runs the test">
<mkdir dir="test-bin"/>
<javac source="1.5" target="1.5"
<javac source="1.6" target="1.6"
srcdir="test"
destdir="test-bin"
encoding="UTF-8"

Binary file not shown.

View File

@ -1002,7 +1002,13 @@ public class Editor extends JFrame implements RunnerListener {
{
//System.out.println("Adding port to serial port menu: " + commportidentifier);
String curr_port = commportidentifier.getName();
rbMenuItem = new JCheckBoxMenuItem(curr_port, curr_port.equals(Preferences.get("serial.port")));
String description = curr_port;
String additionalDescription = Base.getPlatform().resolveDeviceAttachedTo(curr_port, Base.packages);
if (additionalDescription != null) {
description += " (" + additionalDescription + ")";
}
rbMenuItem = new JCheckBoxMenuItem(description, curr_port.equals(Preferences.get("serial.port")));
rbMenuItem.addActionListener(serialMenuListener);
//serialGroup.add(rbMenuItem);
serialMenu.add(rbMenuItem);

View File

@ -24,11 +24,15 @@ package processing.app;
import static processing.app.I18n._;
import java.io.File;
import java.util.Map;
import javax.swing.UIManager;
import com.sun.jna.Library;
import com.sun.jna.Native;
import processing.app.debug.TargetPackage;
import processing.app.debug.TargetPlatform;
import processing.app.helpers.PreferencesMap;
import processing.core.PConstants;
@ -129,10 +133,31 @@ public class Platform {
showLauncherWarning();
}
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
public String resolveDeviceAttachedTo(String device, Map<String, TargetPackage> packages) {
return null;
}
public String resolveDeviceByVendorIdProductId(Map<String, TargetPackage> packages, String vendorId, String productId) {
for (TargetPackage targetPackage : packages.values()) {
for (TargetPlatform targetPlatform : targetPackage.getPlatforms().values()) {
for (PreferencesMap board : targetPlatform.getBoards().values()) {
if (board.containsKey("vid_pid")) {
String[] vidPids = board.get("vid_pid").split(",");
for (String vidPid : vidPids) {
if (vidPid.toUpperCase().equals(vendorId + "_" + productId)) {
return board.get("name");
}
}
}
}
}
}
return null;
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)Native.loadLibrary("c", CLibrary.class);

View File

@ -22,11 +22,18 @@
package processing.app.linux;
import java.io.File;
import java.io.*;
import java.util.Map;
import java.util.Properties;
import javax.swing.UIManager;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteStreamHandler;
import org.apache.commons.exec.Executor;
import processing.app.Preferences;
import processing.app.debug.TargetPackage;
import processing.core.PConstants;
@ -124,4 +131,51 @@ public class Platform extends processing.app.Platform {
public String getName() {
return PConstants.platformNames[PConstants.LINUX];
}
@Override
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages) {
Executor executor = new DefaultExecutor();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
executor.setStreamHandler(new ExecuteStreamHandler() {
@Override
public void setProcessInputStream(OutputStream outputStream) throws IOException {
}
@Override
public void setProcessErrorStream(InputStream inputStream) throws IOException {
}
@Override
public void setProcessOutputStream(InputStream inputStream) throws IOException {
byte[] buf = new byte[4096];
int bytes = -1;
while ((bytes = inputStream.read(buf)) != -1) {
baos.write(buf, 0, bytes);
}
}
@Override
public void start() throws IOException {
}
@Override
public void stop() {
}
});
try {
CommandLine toDevicePath = CommandLine.parse("udevadm info -q path -n " + serial);
executor.execute(toDevicePath);
String devicePath = new String(baos.toByteArray());
baos.reset();
CommandLine commandLine = CommandLine.parse("udevadm info --query=property -p " + devicePath);
executor.execute(commandLine);
Properties properties = new Properties();
properties.load(new ByteArrayInputStream(baos.toByteArray()));
return super.resolveDeviceByVendorIdProductId(packages, properties.get("ID_VENDOR_ID").toString().toUpperCase(), properties.get("ID_MODEL_ID").toString().toUpperCase());
} catch (IOException e) {
return null;
}
}
}

View File

@ -25,6 +25,7 @@
<include name="core/core.jar" />
<include name="app/pde.jar" />
<include name="app/lib/ecj.jar" />
<include name="app/lib/commons-exec-1.1.jar" />
<include name="app/lib/jna.jar" />
<include name="app/lib/RXTXcomm.jar" />
<include name="app/lib/ant.jar" />

View File

@ -13,7 +13,7 @@
<methods dir="${basedir}/src/processing/core" />
<mkdir dir="bin" />
<javac source="1.5" target="1.5"
<javac source="1.6" target="1.6"
encoding="UTF-8"
includeAntRuntime="false"
srcdir="src" destdir="bin"/>

View File

@ -5,6 +5,7 @@ menu.cpu=Processor
##############################################################
uno.name=Arduino Uno
uno.vid_pid=2341_0043
uno.upload.tool=avrdude
uno.upload.protocol=arduino
uno.upload.maximum_size=32256
@ -119,6 +120,7 @@ nano.menu.cpu.atmega168.build.mcu=atmega168
##############################################################
mega2560.name=Arduino Mega 2560 or Mega ADK
mega2560.vid_pid=2341_0044,2341_003f
mega2560.cpu=2560 or ADK
mega2560.upload.tool=avrdude
@ -167,6 +169,7 @@ mega.build.variant=mega
##############################################################
leonardo.name=Arduino Leonardo
leonardo.vid_pid=2341_0036,2341_8036
leonardo.upload.tool=avrdude
leonardo.upload.protocol=avr109
leonardo.upload.maximum_size=28672
@ -225,6 +228,7 @@ micro.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid}
##############################################################
esplora.name=Arduino Esplora
esplora.vid_pid=2341_003c,2341_8036
esplora.upload.tool=avrdude
esplora.upload.protocol=avr109
esplora.upload.maximum_size=28672

View File

@ -1,5 +1,6 @@
arduino_due_x_dbg.name=Arduino Due (Programming Port)
arduino_due_x_dbg.vid_pid=2341_003d
arduino_due_x_dbg.upload.tool=bossac
arduino_due_x_dbg.upload.protocol=sam-ba
arduino_due_x_dbg.upload.maximum_size=524288
@ -18,6 +19,7 @@ arduino_due_x_dbg.build.vid=0x2341
arduino_due_x_dbg.build.pid=0x003e
arduino_due_x.name=Arduino Due (Native USB Port)
arduino_due_x.vid_pid=2341_003e
arduino_due_x.upload.tool=bossac
arduino_due_x.upload.protocol=sam-ba
arduino_due_x.upload.maximum_size=524288