Skip to content

Commit

Permalink
Replace old RXTXcomm with jSSC
Browse files Browse the repository at this point in the history
Remove old RXTXcomm and add support for jSSC library
  • Loading branch information
dbarragan committed Aug 7, 2014
1 parent d0976f6 commit 00b0dcf
Show file tree
Hide file tree
Showing 23 changed files with 656 additions and 555 deletions.
73 changes: 70 additions & 3 deletions IDE/processing/app/Base.java
Expand Up @@ -27,6 +27,7 @@
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.net.*;

import javax.swing.*;

Expand All @@ -42,8 +43,8 @@
* files and images, etc) that comes from that.
*/
public class Base {
public static final int REVISION = 100;
static String VERSION_NAME = "0100";
public static final int REVISION = 101;
static String VERSION_NAME = "0101";
/** Set true if this a proper release rather than a numbered revision. */
static public boolean RELEASE = false;
/** True if heavy debugging error/log messages are enabled */
Expand Down Expand Up @@ -2259,8 +2260,62 @@ static public int showYesNoQuestion(Frame editor, String title,
}
}

static public String urlDecode(String str) {
try {
return URLDecoder.decode(str, "UTF-8");
} catch (UnsupportedEncodingException e) { // safe per the JDK source
return null;
}
}

/**
* Adjacent the executable on Windows and Linux,
* or inside Contents/Resources/Java on Mac OS X.
*/
static protected File wiringRoot;


static public File getContentFile(String name) {
if (wiringRoot == null) {
// Get the path to the .jar file that contains Base.class
String path = Base.class.getProtectionDomain().getCodeSource().getLocation().getPath();
// Path may have URL encoding, so remove it
String decodedPath = urlDecode(path);

if (decodedPath.contains("/app/bin")) {
if (Base.isMacOS()) {
wiringRoot =
new File(path, "../../build/macosx/work/Processing.app/Contents/Java");
} else if (Base.isWindows()) {
wiringRoot = new File(path, "../../build/windows/work");
} else if (Base.isLinux()) {
wiringRoot = new File(path, "../../build/linux/work");
}
} else {
// The .jar file will be in the lib folder
File jarFolder = new File(decodedPath).getParentFile();
if (jarFolder.getName().equals("lib")) {
// The main Processing installation directory.
// This works for Windows, Linux, and Apple's Java 6 on OS X.
wiringRoot = jarFolder.getParentFile();
} else if (Base.isMacOS()) {
// This works for Java 7 on OS X. The 'lib' folder is not part of the
// classpath on OS X, and adding it creates more problems than it's
// worth.
wiringRoot = jarFolder;

}
if (wiringRoot == null || !wiringRoot.exists()) {
// Try working directory instead (user.dir, different from user.home)
System.err.println("Could not find lib folder via " +
jarFolder.getAbsolutePath() +
", switching to user.dir");
wiringRoot = new File(System.getProperty("user.dir"));
}
}
}

/*
String path = System.getProperty("user.dir");
// Get a path to somewhere inside the .app folder
Expand All @@ -2271,7 +2326,8 @@ static public File getContentFile(String name) {
}
}
File working = new File(path);
return new File(working, name);
*/
return new File(wiringRoot, name);
}


Expand Down Expand Up @@ -2305,6 +2361,17 @@ static public Image getLibImage(String name, Component who) {
* Return an InputStream for a file inside the Processing lib folder.
*/
static public InputStream getLibStream(String filename) throws IOException {
/*
Properties p = System.getProperties();
Enumeration keys = p.keys();
String res = new String();
while (keys.hasMoreElements()) {
String key = (String)keys.nextElement();
String value = (String)p.get(key);
res += key + ": " + value+ "\n";
}
showMessage("HERE ", getContentFile("lib").getAbsolutePath() +"XXX"+ System.getProperty("os.name")+"XXX"+res);
*/
return new FileInputStream(new File(getContentFile("lib"), filename));
}

Expand Down
31 changes: 22 additions & 9 deletions IDE/processing/app/Editor.java
Expand Up @@ -43,7 +43,7 @@
import javax.swing.undo.*;

import java.util.regex.*;
import gnu.io.*;
import jssc.*;

/**
* Main editor panel for the Processing Development Environment.
Expand Down Expand Up @@ -868,7 +868,20 @@ protected void populateSerialMenu() {

try
{
for (Enumeration enumeration = CommPortIdentifier.getPortIdentifiers(); enumeration.hasMoreElements();)
Vector<String> ports = new Vector<String>(Arrays.asList(SerialPortList.getPortNames()));
Enumeration<?> portList = ports.elements();

while (portList.hasMoreElements()) {
String portId =
(String) portList.nextElement();
rbMenuItem = new JCheckBoxMenuItem(portId, portId.equals(Preferences.get("serial.port")));
rbMenuItem.addActionListener(serialMenuListener);
//serialGroup.add(rbMenuItem);
serialMenu.add(rbMenuItem);
empty = false;
}

/*for (Enumeration enumeration = CommPortIdentifier.getPortIdentifiers(); enumeration.hasMoreElements();)
{
CommPortIdentifier commportidentifier = (CommPortIdentifier)enumeration.nextElement();
//System.out.println("Found communication port: " + commportidentifier);
Expand All @@ -882,7 +895,7 @@ protected void populateSerialMenu() {
serialMenu.add(rbMenuItem);
empty = false;
}
}
}*/
if (!empty) {
//System.out.println("enabling the serialMenu");
serialMenu.setEnabled(true);
Expand Down Expand Up @@ -924,21 +937,21 @@ protected JMenu buildSerialMenu() {
// environment variable will hose things.
try {
//System.out.println("building port list");
for( Enumeration portList = CommPortIdentifier.getPortIdentifiers(); portList.hasMoreElements();)
Vector<String> ports = new Vector<String>(Arrays.asList(SerialPortList.getPortNames()));
Enumeration<?> portList = ports.elements();

while( portList.hasMoreElements())
{
CommPortIdentifier portId =
(CommPortIdentifier) portList.nextElement();
String portId = (String) portList.nextElement();
//System.out.println(portId);

if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
//if (portId.getName().equals(port)) {
String name = portId.getName();
String name = portId;
JCheckBoxMenuItem mi =
new JCheckBoxMenuItem(name, name.equals(defaultName));
mi.addActionListener(listener);
//mi.addItemListener(listener);
serialMenu.add(mi);
}
}
} catch (UnsatisfiedLinkError e) {
e.printStackTrace();
Expand Down

0 comments on commit 00b0dcf

Please sign in to comment.