mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
add tool to fix the serial port on OS X
This commit is contained in:
@@ -1019,6 +1019,9 @@ public abstract class Editor extends JFrame implements RunnerListener {
|
||||
addToolMenuItem(menu, "processing.app.tools.Archiver");
|
||||
|
||||
if (Base.isMacOS()) {
|
||||
if (SerialFixer.isNeeded()) {
|
||||
addToolMenuItem(menu, "processing.app.tools.SerialFixer");
|
||||
}
|
||||
addToolMenuItem(menu, "processing.app.tools.InstallCommander");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2012 The Processing Foundation
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 2.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package processing.app.tools;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.Editor;
|
||||
import processing.core.PApplet;
|
||||
|
||||
|
||||
public class SerialFixer implements Tool {
|
||||
Editor editor;
|
||||
|
||||
|
||||
public String getMenuTitle() {
|
||||
return "Fix the Serial Library";
|
||||
}
|
||||
|
||||
|
||||
public void init(Editor editor) {
|
||||
this.editor = editor;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
final String primary =
|
||||
"Attempt to fix common serial port problems?";
|
||||
final String secondary =
|
||||
"Click “OK” to perform additional installation steps to enable " +
|
||||
"the Serial library. An administrator password will be required.";
|
||||
|
||||
int result =
|
||||
JOptionPane.showConfirmDialog(editor,
|
||||
"<html> " +
|
||||
"<head> <style type=\"text/css\">"+
|
||||
"b { font: 13pt \"Lucida Grande\" }"+
|
||||
"p { font: 11pt \"Lucida Grande\"; margin-top: 8px }"+
|
||||
"</style> </head>" +
|
||||
"<b>" + primary + "</b>" +
|
||||
"<p>" + secondary + "</p>",
|
||||
"Commander",
|
||||
JOptionPane.OK_CANCEL_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE);
|
||||
|
||||
if (result == JOptionPane.OK_OPTION) {
|
||||
String shellScript = "mkdir -p /var/lock && chmod 777 /var/lock";
|
||||
String appleScript =
|
||||
"do shell script \"" + shellScript + "\" with administrator privileges";
|
||||
PApplet.exec(new String[] { "osascript", "-e", appleScript });
|
||||
}
|
||||
editor.statusNotice("Finished.");
|
||||
}
|
||||
|
||||
|
||||
static public boolean isNeeded() {
|
||||
if (Base.isMacOS()) {
|
||||
File lockFolder = new File("/var/lock");
|
||||
if (!lockFolder.exists() ||
|
||||
!lockFolder.canRead() ||
|
||||
!lockFolder.canWrite() ||
|
||||
!lockFolder.canExecute()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,7 @@ public class Serial implements SerialPortEventListener {
|
||||
this(parent, dname, drate, dparity, ddatabits, dstopbits);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param irate 9600 is the default
|
||||
*/
|
||||
@@ -107,6 +108,7 @@ public class Serial implements SerialPortEventListener {
|
||||
this(parent, dname, irate, dparity, ddatabits, dstopbits);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param iname name of the port (COM1 is the default)
|
||||
*/
|
||||
@@ -118,6 +120,7 @@ public class Serial implements SerialPortEventListener {
|
||||
this(parent, iname, drate, dparity, ddatabits, dstopbits);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param iparity 'N' for none, 'E' for even, 'O' for odd ('N' is the default)
|
||||
* @param idatabits 8 is the default
|
||||
@@ -143,8 +146,11 @@ public class Serial implements SerialPortEventListener {
|
||||
"sudo mkdir -p /var/lock\n" +
|
||||
"sudo chmod 777 /var/lock";
|
||||
System.err.println(MESSAGE);
|
||||
throw new RuntimeException("Additional installation required to " +
|
||||
"use serial, read the console below.");
|
||||
//throw new RuntimeException("Additional installation required to " +
|
||||
// "use serial, read the console below.");
|
||||
final String msg =
|
||||
"Please use Tools \u2192 Fix the Serial Library.";
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +195,7 @@ public class Serial implements SerialPortEventListener {
|
||||
output = null;
|
||||
}
|
||||
|
||||
parent.registerDispose(this);
|
||||
parent.registerMethod("dispose", this);
|
||||
|
||||
// reflection to check whether host applet has a call for
|
||||
// public void serialEvent(processing.serial.Serial)
|
||||
@@ -240,18 +246,19 @@ public class Serial implements SerialPortEventListener {
|
||||
|
||||
|
||||
/**
|
||||
* Set the DTR line. Addition from Tom Hulbert.
|
||||
*/
|
||||
* Set the DTR line. Addition from Tom Hulbert.
|
||||
*/
|
||||
public void setDTR(boolean state) {
|
||||
port.setDTR(state);
|
||||
port.setDTR(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* @generate serialEvent.xml
|
||||
* @webref serial:events
|
||||
* @usage web_application
|
||||
* @param serialEvent the port where new data is available
|
||||
*/
|
||||
|
||||
/**
|
||||
* @generate serialEvent.xml
|
||||
* @webref serial:events
|
||||
* @usage web_application
|
||||
* @param serialEvent the port where new data is available
|
||||
*/
|
||||
synchronized public void serialEvent(SerialPortEvent serialEvent) {
|
||||
if (serialEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user