git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@510 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d

This commit is contained in:
Tgui 2007-02-09 18:12:22 +00:00
parent 90884b13f6
commit 6a81b6ec15
22 changed files with 1848 additions and 21 deletions

View File

@ -1,19 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="lib" path="lib/logger/rxtx/RXTXcomm.jar"/>
<classpathentry exported="true" kind="lib" path="lib/logger/jcommon-1.0.7.jar"/>
<classpathentry exported="true" kind="lib" path="lib/logger/jfreechart-1.0.3.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jep.jar"/>
<classpathentry exported="true" kind="lib" path="lib/JFontChooser.jar"/>
<classpathentry exported="true" kind="lib" path="lib/swing-layout-1.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/Graph3d/linux/lib/j3dcore.jar"/>
<classpathentry exported="true" kind="lib" path="lib/Graph3d/linux/lib/j3dutils.jar"/>
<classpathentry exported="true" kind="lib" path="lib/Graph3d/linux/lib/vecmath.jar"/>
<classpathentry exported="true" kind="lib" path="lib/Graph3d/linux/Graph3d.jar"/>
<classpathentry exported="true" kind="lib" path="lib/Graph3d/jama-1.0.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/BareBonesBrowserLaunch.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jdic/jdic.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="lib" path="lib/logger/rxtx/RXTXcomm.jar"/>
<classpathentry exported="true" kind="lib" path="lib/logger/jcommon-1.0.7.jar"/>
<classpathentry exported="true" kind="lib" path="lib/logger/jfreechart-1.0.3.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jep.jar"/>
<classpathentry exported="true" kind="lib" path="lib/JFontChooser.jar"/>
<classpathentry exported="true" kind="lib" path="lib/swing-layout-1.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/Graph3d/linux/lib/j3dcore.jar"/>
<classpathentry exported="true" kind="lib" path="lib/Graph3d/linux/lib/j3dutils.jar"/>
<classpathentry exported="true" kind="lib" path="lib/Graph3d/linux/lib/vecmath.jar"/>
<classpathentry exported="true" kind="lib" path="lib/Graph3d/linux/Graph3d.jar"/>
<classpathentry exported="true" kind="lib" path="lib/Graph3d/jama-1.0.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/BareBonesBrowserLaunch.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jdic/jdic.jar"/>
<classpathentry kind="lib" path="lib/tts/freetts.jar"/>
<classpathentry kind="lib" path="lib/tts/en_us.jar"/>
<classpathentry kind="lib" path="lib/tts/cmulex.jar"/>
<classpathentry kind="lib" path="lib/tts/cmudict04.jar"/>
<classpathentry kind="lib" path="lib/tts/cmu_us_kal.jar"/>
<classpathentry kind="lib" path="lib/tts/cmu_time_awb.jar"/>
<classpathentry kind="lib" path="lib/tts/cmutimelex.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

BIN
lib/tts/cmu_time_awb.jar Normal file

Binary file not shown.

BIN
lib/tts/cmu_us_kal.jar Normal file

Binary file not shown.

BIN
lib/tts/cmudict04.jar Executable file

Binary file not shown.

BIN
lib/tts/cmulex.jar Normal file

Binary file not shown.

BIN
lib/tts/cmutimelex.jar Executable file

Binary file not shown.

BIN
lib/tts/en_us.jar Normal file

Binary file not shown.

BIN
lib/tts/freetts.jar Normal file

Binary file not shown.

View File

@ -0,0 +1,74 @@
package enginuity.logger.utec.comm;
import java.awt.*;
import java.awt.event.*;
import enginuity.logger.utec.gui.*;
/**
Informs the user that an other application has requested the port they
are using, and then asks if they are willing to give it up. If the user
answers "Yes" the port is closed and the dialog is closed, if the user
answers "No" the dialog closes and no other action is taken.
*/
public class PortRequestedDialog extends Dialog implements ActionListener {
private JutecGUI parent;
/**
Creates the a dialog with two buttons and a message asking the user if
they are willing to give up the port they are using.
@param parent The main SerialDemo object.
*/
public PortRequestedDialog(JutecGUI parent) {
super(parent, "Port Requested!", true);
this.parent = parent;
String lineOne = "Your port has been requested";
String lineTwo = "by an other application.";
String lineThree = "Do you want to give up your port?";
Panel labelPanel = new Panel();
labelPanel.setLayout(new GridLayout(3, 1));
labelPanel.add(new Label(lineOne, Label.CENTER));
labelPanel.add(new Label(lineTwo, Label.CENTER));
labelPanel.add(new Label(lineThree, Label.CENTER));
add(labelPanel, "Center");
Panel buttonPanel = new Panel();
Button yesButton = new Button("Yes");
yesButton.addActionListener(this);
buttonPanel.add(yesButton);
Button noButton = new Button("No");
noButton.addActionListener(this);
buttonPanel.add(noButton);
add(buttonPanel, "South");
FontMetrics fm = getFontMetrics(getFont());
int width = Math.max(fm.stringWidth(lineOne),
Math.max(fm.stringWidth(lineTwo), fm.stringWidth(lineThree)));
setSize(width + 40, 150);
setLocation(parent.getLocationOnScreen().x + 30,
parent.getLocationOnScreen().y + 30);
setVisible(true);
}
/**
Handles events generated by the buttons. If the yes button in pushed the
port closing routine is called and the dialog is disposed of. If the "No"
button is pushed the dialog is disposed of.
*/
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if (cmd.equals("Yes")) {
///parent.portClosed();
System.out.println("Port has been closed");
System.out.println("Eventually handle this notification through the GUI");
}
setVisible(false);
dispose();
}
}

View File

@ -0,0 +1,398 @@
package enginuity.logger.utec.comm;
//import javax.comm.*;
import java.io.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import enginuity.logger.utec.commEvent.*;
/**
* Class negotiates data to and from UTEC via the serial port
*
* Please note that at this time ownership issues are not handled.
* See commented out code pertaining to the parent entity
*
* @author botman
*
*/
//public class SerialConnection implements SerialPortEventListener,
// CommPortOwnershipListener {
import gnu.io.*;
public class SerialConnection implements SerialPortEventListener{
// Parent object organizing connections to and from UTEC
//private JPanel parent;
//Data to UTEC
//private JTextArea messageAreaOut;
//Data from UTEC
//private JTextArea messageAreaIn;
// Parameters used to define serial connection
public SerialParameters parameters = new SerialParameters();
//Data from UTEC
private OutputStream outputToUtecStream;
//Data to UTEC
private InputStream inputFromUtecStream;
// Handler for keyboard input
private KeyHandler keyHandler;
// Defines named comport
private CommPortIdentifier portId;
// Serial port being accessed
private SerialPort sPort;
// Defin state of defined comport, open or closed.
private boolean open;
//Listeners
private Vector portListeners = new Vector();
/**
* Public constructor
*
* @param parent
* @param parameters
* @param messageAreaOut
* @param messageAreaIn
*/
//public SerialConnection(JPanel parent, SerialParameters parameters,
// TextArea messageAreaOut, TextArea messageAreaIn) {
public SerialConnection(SerialParameters parameters) {
//this.parent = parent;
//this.messageAreaOut = messageAreaOut;
//this.messageAreaIn = messageAreaIn;
open = false;
}
/**
* Get UTEC to send data
*
*/
public void startDataFlow(){
System.out.println("Starting data flow from UTEC");
//OutPut a '1' to start basic data flow from UTEC
try{
outputToUtecStream.write((int) '!');
}
catch(IOException e){
System.err.println("Can't start flow of data from UTEC");
e.getMessage();
}
}
/**
* Reset UTEC to main screen
*
*/
public void resetUtec(){
//OutPut and 'escape' to UTEC
try{
outputToUtecStream.write((int) '\u001B');
}
catch(IOException e){
System.err.println("Can't start flow of data from UTEC");
e.getMessage();
}
}
/**
* Opens a connection to the defined serial port If attempt fails,
* SerialConnectionException is thrown
*
* @throws SerialConnectionException
*/
public void openConnection() throws SerialConnectionException {
// Obtain a CommPortIdentifier object for the port you want to open.
try {
//System.out.println("PORT: "+parameters.getPortName());
portId = CommPortIdentifier.getPortIdentifier(parameters
.getPortName());
} catch (NoSuchPortException e) {
System.err.println("Can't get commport identifier");
throw new SerialConnectionException(e.getMessage());
}
// Open the port represented by the CommPortIdentifier object. Give
// the open call a relatively long timeout of 30 seconds to allow
// a different application to reliquish the port if the user
// wants to.
try {
sPort = (SerialPort) portId.open("SerialDemo", 30000);
} catch (PortInUseException e) {
System.err.println("Can't open serial port");
throw new SerialConnectionException(e.getMessage());
}
// Set the parameters of the connection. If they won't set, close the
// port before throwing an exception.
try {
setConnectionParameters();
} catch (SerialConnectionException e) {
System.err.println("Can't set connection parameters");
sPort.close();
throw e;
}
// Open the input and output streams for the connection. If they won't
// open, close the port before throwing an exception.
try {
outputToUtecStream = sPort.getOutputStream();
inputFromUtecStream = sPort.getInputStream();
} catch (IOException e) {
System.err.println("Error opening IO streams");
sPort.close();
throw new SerialConnectionException("Error opening i/o streams");
}
// Create a new KeyHandler to respond to key strokes in the
// messageAreaOut. Add the KeyHandler as a keyListener to the
// messageAreaOut.
//keyHandler = new KeyHandler(outputToUtecStream);
//messageAreaOut.addKeyListener(keyHandler);
// Add this object as an event listener for the serial port.
try {
sPort.addEventListener(this);
} catch (TooManyListenersException e) {
System.err.println("Too Many listeners");
sPort.close();
throw new SerialConnectionException("too many listeners added");
}
// Set notifyOnDataAvailable to true to allow event driven input.
sPort.notifyOnDataAvailable(true);
// Set notifyOnBreakInterrup to allow event driven break handling.
sPort.notifyOnBreakInterrupt(true);
// Set receive timeout to allow breaking out of polling loop during
// input handling.
try {
sPort.enableReceiveTimeout(30);
} catch (UnsupportedCommOperationException e) {
System.err.println("Time Out");
}
// Add ownership listener to allow ownership event handling.
//portId.addPortOwnershipListener(this);
open = true;
}
/**
* Sets the connection parameters to the setting in the parameters object.
* If set fails return the parameters object to origional settings and throw
* exception.
*/
public void setConnectionParameters() throws SerialConnectionException {
// Save state of parameters before trying a set.
int oldBaudRate = sPort.getBaudRate();
int oldDatabits = sPort.getDataBits();
int oldStopbits = sPort.getStopBits();
int oldParity = sPort.getParity();
int oldFlowControl = sPort.getFlowControlMode();
// Set connection parameters, if set fails return parameters object
// to original state.
try {
sPort.setSerialPortParams(parameters.getBaudRate(), parameters
.getDatabits(), parameters.getStopbits(), parameters
.getParity());
} catch (UnsupportedCommOperationException e) {
parameters.setBaudRate(oldBaudRate);
parameters.setDatabits(oldDatabits);
parameters.setStopbits(oldStopbits);
parameters.setParity(oldParity);
throw new SerialConnectionException("Unsupported parameter");
}
// Set flow control.
try {
sPort.setFlowControlMode(parameters.getFlowControlIn()
| parameters.getFlowControlOut());
} catch (UnsupportedCommOperationException e) {
throw new SerialConnectionException("Unsupported flow control");
}
}
/**
* Close the port and clean up associated elements.
*/
public void closeConnection() {
// If port is alread closed just return.
if (!open) {
return;
}
System.out.println("Closing connection to the currently targeted port");
//Reset the UTEC first
resetUtec();
// Remove the key listener.
//messageAreaOut.removeKeyListener(keyHandler);
// Check to make sure sPort has reference to avoid a NPE.
if (sPort != null) {
try {
// close the i/o streams.
outputToUtecStream.close();
inputFromUtecStream.close();
} catch (IOException e) {
System.err.println(e);
}
// Close the port.
sPort.close();
// Remove the ownership listener.
//portId.removePortOwnershipListener(this);
}
open = false;
}
/**
* Send a one second break signal.
*/
public void sendBreak() {
sPort.sendBreak(1000);
}
/**
* Reports the open status of the port.
*
* @return true if port is open, false if port is closed.
*/
public boolean isOpen() {
return open;
}
/**
* Method adds a class as a listener
* @param o
*/
public void addListener(Object o){
portListeners.add(o);
}
/**
* Handles SerialPortEvents. The two types of SerialPortEvents that this
* program is registered to listen for are DATA_AVAILABLE and BI. During
* DATA_AVAILABLE the port buffer is read until it is drained, when no more
* data is availble and 30ms has passed the method returns. When a BI event
* occurs the words BREAK RECEIVED are written to the messageAreaIn.
*/
public void serialEvent(SerialPortEvent e) {
// Create a StringBuffer and int to receive input data.
StringBuffer inputBuffer = new StringBuffer();
int newData = 0;
// Determine type of event.
switch (e.getEventType()) {
// Read data until -1 is returned. If \r is received substitute
// \n for correct newline handling.
case SerialPortEvent.DATA_AVAILABLE:
while (newData != -1) {
try {
newData = inputFromUtecStream.read();
if (newData == -1) {
break;
}
if ('\r' == (char) newData) {
inputBuffer.append('\n');
} else {
inputBuffer.append((char) newData);
}
} catch (IOException ex) {
System.err.println(ex);
return;
}
}
//Build new event with buffer data
CommEvent commEvent = new CommEvent(new String(inputBuffer));
//Send received data to listeners
Iterator portIterator = portListeners.iterator();
while(portIterator.hasNext()){
CommListener theListener = (CommListener)portIterator.next();
theListener.getCommEvent(commEvent);
}
break;
// If break event append BREAK RECEIVED message.
/*
case SerialPortEvent.BI:
messageAreaIn.append("\n--- BREAK RECEIVED ---\n");
*/
}
}
/**
* Handles ownership events. If a PORT_OWNERSHIP_REQUESTED event is received
* a dialog box is created asking the user if they are willing to give up
* the port. No action is taken on other types of ownership events.
*/
/*
public void ownershipChange(int type) {
if (type == CommPortOwnershipListener.PORT_OWNERSHIP_REQUESTED) {
PortRequestedDialog prd = new PortRequestedDialog(parent);
}
}
*/
/**
* A class to handle <code>KeyEvent</code> s generated by the
* messageAreaOut. When a <code>KeyEvent</code> occurs the
* <code>char</code> that is generated by the event is read, converted to
* an <code>int</code> and writen to the <code>OutputStream</code> for
* the port.
*/
class KeyHandler extends KeyAdapter {
OutputStream toUtec;
/**
* Creates the KeyHandler.
*
* @param toUtec
* The OutputStream for the port.
*/
public KeyHandler(OutputStream toUtec) {
super();
this.toUtec = toUtec;
}
/**
* Handles the KeyEvent. Gets the
* <code>char</char> generated by the <code>KeyEvent</code>,
converts it to an <code>int</code>, writes it to the <code>
OutputStream</code> for the port.
*/
public void keyTyped(KeyEvent evt) {
char newCharacter = evt.getKeyChar();
try {
toUtec.write((int) newCharacter);
} catch (IOException e) {
System.err.println("OutputStream write error: " + e);
}
}
}
}

View File

@ -0,0 +1,27 @@
/*
* Class defines an exception to be thrown in the event
* of serial connection troubles
*/
package enginuity.logger.utec.comm;
public class SerialConnectionException extends Exception {
/**
* Constructs a <code>SerialConnectionException</code>
* with the specified detail message.
*
* @param s the detail message.
*/
public SerialConnectionException(String str) {
super(str);
}
/**
* Constructs a <code>SerialConnectionException</code>
* with no detail message.
*/
public SerialConnectionException() {
super();
}
}

View File

@ -0,0 +1,349 @@
/*
* Class holds serial port specific data
*/
package enginuity.logger.utec.comm;
//import javax.comm.*;
import gnu.io.*;
/**
* A class that stores parameters for serial ports.
*/
public class SerialParameters {
private String portName;
private int baudRate;
private int flowControlIn;
private int flowControlOut;
private int databits;
private int stopbits;
private int parity;
/**
* Constructor. Settings tuned to connect to the UTEC
*
*/
public SerialParameters() {
this.portName = "";
this.baudRate = 19200;
this.flowControlIn = SerialPort.FLOWCONTROL_NONE;
this.flowControlOut = SerialPort.FLOWCONTROL_NONE;
this.databits = SerialPort.DATABITS_8;
this.stopbits = SerialPort.STOPBITS_1;
this.parity = SerialPort.PARITY_NONE;
}
/**
Sets port name.
@param portName New port name.
*/
public void setPortName(String portName) {
//System.out.println("Set portName requested");
this.portName = portName;
}
/**
Gets port name.
@return Current port name.
*/
public String getPortName() {
return portName;
}
/**
Sets baud rate.
@param baudRate New baud rate.
*/
public void setBaudRate(int baudRate) {
this.baudRate = baudRate;
}
/**
Sets baud rate.
@param baudRate New baud rate.
*/
public void setBaudRate(String baudRate) {
this.baudRate = Integer.parseInt(baudRate);
}
/**
Gets baud rate as an <code>int</code>.
@return Current baud rate.
*/
public int getBaudRate() {
return baudRate;
}
/**
Gets baud rate as a <code>String</code>.
@return Current baud rate.
*/
public String getBaudRateString() {
return Integer.toString(baudRate);
}
/**
Sets flow control for reading.
@param flowControlIn New flow control for reading type.
*/
public void setFlowControlIn(int flowControlIn) {
this.flowControlIn = flowControlIn;
}
/**
Sets flow control for reading.
@param flowControlIn New flow control for reading type.
*/
public void setFlowControlIn(String flowControlIn) {
this.flowControlIn = stringToFlow(flowControlIn);
}
/**
Gets flow control for reading as an <code>int</code>.
@return Current flow control type.
*/
public int getFlowControlIn() {
return flowControlIn;
}
/**
Gets flow control for reading as a <code>String</code>.
@return Current flow control type.
*/
public String getFlowControlInString() {
return flowToString(flowControlIn);
}
/**
Sets flow control for writing.
@param flowControlIn New flow control for writing type.
*/
public void setFlowControlOut(int flowControlOut) {
this.flowControlOut = flowControlOut;
}
/**
Sets flow control for writing.
@param flowControlIn New flow control for writing type.
*/
public void setFlowControlOut(String flowControlOut) {
this.flowControlOut = stringToFlow(flowControlOut);
}
/**
Gets flow control for writing as an <code>int</code>.
@return Current flow control type.
*/
public int getFlowControlOut() {
return flowControlOut;
}
/**
Gets flow control for writing as a <code>String</code>.
@return Current flow control type.
*/
public String getFlowControlOutString() {
return flowToString(flowControlOut);
}
/**
Sets data bits.
@param databits New data bits setting.
*/
public void setDatabits(int databits) {
this.databits = databits;
}
/**
Sets data bits.
@param databits New data bits setting.
*/
public void setDatabits(String databits) {
if (databits.equals("5")) {
this.databits = SerialPort.DATABITS_5;
}
if (databits.equals("6")) {
this.databits = SerialPort.DATABITS_6;
}
if (databits.equals("7")) {
this.databits = SerialPort.DATABITS_7;
}
if (databits.equals("8")) {
this.databits = SerialPort.DATABITS_8;
}
}
/**
Gets data bits as an <code>int</code>.
@return Current data bits setting.
*/
public int getDatabits() {
return databits;
}
/**
Gets data bits as a <code>String</code>.
@return Current data bits setting.
*/
public String getDatabitsString() {
switch(databits) {
case SerialPort.DATABITS_5:
return "5";
case SerialPort.DATABITS_6:
return "6";
case SerialPort.DATABITS_7:
return "7";
case SerialPort.DATABITS_8:
return "8";
default:
return "8";
}
}
/**
Sets stop bits.
@param stopbits New stop bits setting.
*/
public void setStopbits(int stopbits) {
this.stopbits = stopbits;
}
/**
Sets stop bits.
@param stopbits New stop bits setting.
*/
public void setStopbits(String stopbits) {
if (stopbits.equals("1")) {
this.stopbits = SerialPort.STOPBITS_1;
}
if (stopbits.equals("1.5")) {
this.stopbits = SerialPort.STOPBITS_1_5;
}
if (stopbits.equals("2")) {
this.stopbits = SerialPort.STOPBITS_2;
}
}
/**
Gets stop bits setting as an <code>int</code>.
@return Current stop bits setting.
*/
public int getStopbits() {
return stopbits;
}
/**
Gets stop bits setting as a <code>String</code>.
@return Current stop bits setting.
*/
public String getStopbitsString() {
switch(stopbits) {
case SerialPort.STOPBITS_1:
return "1";
case SerialPort.STOPBITS_1_5:
return "1.5";
case SerialPort.STOPBITS_2:
return "2";
default:
return "1";
}
}
/**
Sets parity setting.
@param parity New parity setting.
*/
public void setParity(int parity) {
this.parity = parity;
}
/**
Sets parity setting.
@param parity New parity setting.
*/
public void setParity(String parity) {
if (parity.equals("None")) {
this.parity = SerialPort.PARITY_NONE;
}
if (parity.equals("Even")) {
this.parity = SerialPort.PARITY_EVEN;
}
if (parity.equals("Odd")) {
this.parity = SerialPort.PARITY_ODD;
}
}
/**
Gets parity setting as an <code>int</code>.
@return Current parity setting.
*/
public int getParity() {
return parity;
}
/**
Gets parity setting as a <code>String</code>.
@return Current parity setting.
*/
public String getParityString() {
switch(parity) {
case SerialPort.PARITY_NONE:
return "None";
case SerialPort.PARITY_EVEN:
return "Even";
case SerialPort.PARITY_ODD:
return "Odd";
default:
return "None";
}
}
/**
Converts a <code>String</code> describing a flow control type to an
<code>int</code> type defined in <code>SerialPort</code>.
@param flowControl A <code>string</code> describing a flow control type.
@return An <code>int</code> describing a flow control type.
*/
private int stringToFlow(String flowControl) {
if (flowControl.equals("None")) {
return SerialPort.FLOWCONTROL_NONE;
}
if (flowControl.equals("Xon/Xoff Out")) {
return SerialPort.FLOWCONTROL_XONXOFF_OUT;
}
if (flowControl.equals("Xon/Xoff In")) {
return SerialPort.FLOWCONTROL_XONXOFF_IN;
}
if (flowControl.equals("RTS/CTS In")) {
return SerialPort.FLOWCONTROL_RTSCTS_IN;
}
if (flowControl.equals("RTS/CTS Out")) {
return SerialPort.FLOWCONTROL_RTSCTS_OUT;
}
return SerialPort.FLOWCONTROL_NONE;
}
/**
Converts an <code>int</code> describing a flow control type to a
<code>String</code> describing a flow control type.
@param flowControl An <code>int</code> describing a flow control type.
@return A <code>String</code> describing a flow control type.
*/
String flowToString(int flowControl) {
switch(flowControl) {
case SerialPort.FLOWCONTROL_NONE:
return "None";
case SerialPort.FLOWCONTROL_XONXOFF_OUT:
return "Xon/Xoff Out";
case SerialPort.FLOWCONTROL_XONXOFF_IN:
return "Xon/Xoff In";
case SerialPort.FLOWCONTROL_RTSCTS_IN:
return "RTS/CTS In";
case SerialPort.FLOWCONTROL_RTSCTS_OUT:
return "RTS/CTS Out";
default:
return "None";
}
}
}

View File

@ -0,0 +1,76 @@
/*
* Created on May 28, 2005
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package enginuity.logger.utec.commEvent;
import java.util.*;
/**
* @author emorgan
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class CommEvent {
public String UtecBuffer = null;
public String[] data = new String[6];
public double[] doubleData = new double[6];
public CommEvent(String buffer){
UtecBuffer = buffer;
StringTokenizer st = new StringTokenizer(UtecBuffer, ",");
int counter = 0;
while(st.hasMoreTokens()){
String theData = st.nextToken();
//RPM
if(counter == 0){
data[0] = theData;
}
//PSI
if(counter == 1){
data[1] = theData;
}
//KNOCK
if(counter == 5){
data[2] = theData;
}
//IGN
if(counter == 6){
data[3] = theData;
}
//DUTY
if(counter == 7){
data[4] = theData;
}
//AFR
if(counter == 13){
data[5] = theData;
}
counter++;
}
for(int i = 0; i < 6; i++){
String theData = data[i];
theData = theData.trim();
if(theData.startsWith(">")){
theData = "25.5";
}
if(theData.startsWith("--")){
theData = "0.0";
}
doubleData[i] = Double.parseDouble(theData);
}
}
}

View File

@ -0,0 +1,17 @@
/*
* Created on May 28, 2005
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package enginuity.logger.utec.commEvent;
/**
* @author emorgan
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public interface CommListener {
public void getCommEvent(CommEvent e);
}

View File

@ -0,0 +1,145 @@
/*
* Created on May 30, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package enginuity.logger.utec.commInterface;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Enumeration;
import java.util.*;
//import javax.comm.CommPortIdentifier
import gnu.io.*;
import javax.swing.*;
import enginuity.logger.utec.gui.realtimeData.*;
import enginuity.logger.utec.comm.*;
/**
* @author emorgan
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class CommInterface{
//Store string vector of known system comm ports
private static Vector portChoices = listPortChoices();
//Basic connection settings, already tuned for a UTEC connection, baud, parity, etc
private static SerialParameters parameters = new SerialParameters();
//Actual connection entity
private static SerialConnection connection = new SerialConnection(parameters);
public static boolean ISOPEN = connection.isOpen();
public static Vector getPortsVector(){
return portChoices;
}
public static String getPortChoiceUsed(){
return connection.parameters.getPortName();
}
/**
* Open a port as per names defined in get port names method
*
* @param portName
*/
public static void openConnection(){
//No port yet chosen
if(connection.parameters.getPortName().equalsIgnoreCase("")){
System.err.println("No Port Yet Chosen, nothing to open");
return;
}
//Port is already opened, any port is open
/*
if(ISOPEN){
System.err.println("Port already opened");
return;
}
*/
//Attempt to make connection
try{
connection.openConnection();
}catch(SerialConnectionException e){
System.err.println("Error opening serial port connection");
e.printStackTrace();
return;
}
//Successful opening of port
//ISOPEN=true;
}
public static void closeConnection(){
connection.closeConnection();
}
public static void setPortChoice(String port){
connection.parameters.setPortName(port);
}
/**
* Resets UTEC to main screen
*
*/
public static void resetUtec(){
connection.resetUtec();
}
/**
* Starts the #1 logger (SHIFT-1), ie !, ie CSV logger.
*
*/
public static void startDataLogFromUtec(){
connection.startDataFlow();
}
/**
* Adds a listener for comm port events
* @param o
*/
public static void addListener(Object o){
if(connection == null){
System.err.println("No Serial Connection defined yet.. DIZZoGG!");
return;
}
connection.addListener(o);
}
/**
* Method returns a vector of all available serial ports found
*
* @return
*/
private static Vector listPortChoices() {
Vector theChoices = new Vector();
CommPortIdentifier portId;
Enumeration en = CommPortIdentifier.getPortIdentifiers();
if (!en.hasMoreElements()) {
System.err.println("No Valid ports found, check Java installation");
}
//Iterate through the ports
while (en.hasMoreElements()) {
portId = (CommPortIdentifier) en.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
System.out.println("Port found on system: "+portId.getName());
theChoices.addElement(portId.getName());
}
}
return theChoices;
}
}

View File

@ -0,0 +1,247 @@
/*
* Created on Jan 8, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package enginuity.logger.utec.gui;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import enginuity.Settings;
import enginuity.logger.utec.gui.realtimeData.*;
import enginuity.logger.utec.gui.bottomControl.*;
import enginuity.tts.VoiceThread;
import enginuity.logger.utec.commInterface.CommInterface;
/**
* @author botman
*/
public class JutecGUI extends JFrame implements ActionListener{
//Top level desktop pane
public JLayeredPane desktop = null;
//Top menu bar
private JMenuBar menuBar;
//A known existing port
private String defaultPort = null;
//Currently selected port
private String currentPort = null;
private BottomUtecControl bottomPanel = null;
private JFileChooser fileChooser = null;
private int fileChosen;
private File selectedFile = null;
//FileMenu Items
public JMenuItem saveItem = new JMenuItem("Save");
public JMenuItem exitItem = new JMenuItem("Exit");
private static JutecGUI instance = null;
public static JutecGUI getInstance(){
return instance;
}
private JutecGUI(int setDefaultCloseOperation) {
// Main frame
// Grid layout with a top and bottom, ie two rows
super("-=<JUTEC Tuning Tool>=- USE AT OWN RISK,NO WARRANTY");
this.setSize(800, 600);
this.setResizable(false);
this.setDefaultCloseOperation(setDefaultCloseOperation);
//*************************
//Voice the welcome message
//*************************
VoiceThread vc = new VoiceThread("Welcome to you teck logger! Use at your own risk.");
vc.start();
//Actions to take when window is closing
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.out.println("JUTEC Exiting");
//Use interface to close the connecetion to the Utec
CommInterface.closeConnection();
}
});
//-----------------------
//Start Menu bar addtions
//-----------------------
menuBar = new JMenuBar();
//*********************************************
//Add a menu item for basic application actions
//*********************************************
// Define the menu system
JMenu fileMenu = new JMenu("File");
saveItem.addActionListener(this);
exitItem.addActionListener(this);
fileMenu.add(saveItem);
fileMenu.add(exitItem);
menuBar.add(fileMenu);
//----------------------------------
//Add a menu item for comm port selection
//----------------------------------
JMenu portsMenu =new JMenu("Ports");
//Gather list of ports from interface
Vector portsVector =CommInterface.getPortsVector();
Iterator portsIterator = portsVector.iterator();
int counter = 0;
while(portsIterator.hasNext()){
counter++;
Object o = portsIterator.next();
String theName = (String)o;
JMenuItem item = new JMenuItem(theName);
item.setName(theName);
item.addActionListener(this);
portsMenu.add(item);
if(counter == 1){
defaultPort = theName;
CommInterface.setPortChoice(defaultPort);
}
}
menuBar.add(portsMenu);
// Add menu item to the JFrame
this.setJMenuBar(menuBar);
//*********************************************
//Start Adding GUI Elements to the Window
//*********************************************
bottomPanel = new BottomUtecControl();
JTabbedPane topTabbedPane = new JTabbedPane();
topTabbedPane.add("Graph Data",new RealTimeData());
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPane.setDividerLocation(435);
splitPane.setTopComponent(topTabbedPane);
splitPane.setBottomComponent(bottomPanel);
splitPane.setPreferredSize(new Dimension(800,600));
this.getContentPane().add(splitPane);
//***********************
//Define the file chooser
//***********************
fileChooser = new JFileChooser();
//Save singleton
instance = this;
}
/**
* Implements actionPerformed
*
* Action listeners for buttons/menus that throw them
*
*/
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
//Open Port
if (cmd.equals("New")) {
System.out.println("New action occuring");
}
//Close Port
else if (cmd.equals("Open")) {
System.out.println("Open action occuring");
}
//Start Capture
else if (cmd.equals("Save")) {
String saveFileName = null;
System.out.println("Save action occuring");
fileChosen = fileChooser.showSaveDialog(this);
if(fileChosen == JFileChooser.APPROVE_OPTION)
{
saveFileName = fileChooser.getSelectedFile().getPath();
//selectedFile = fileChooser.getSelectedFile();
try {
File file = new File(saveFileName);
FileWriter out = new FileWriter(file);
out.write(bottomPanel.totalLog);
out.close();
bottomPanel.totalLog = "";
}
catch (IOException e2) {
System.out.println("Couldn't save file " + saveFileName);
e2.printStackTrace();
}
}
}
//Stop Capture
else if (cmd.equals("Exit")) {
//Use interface to finally close the connection to the Utec
CommInterface.closeConnection();
System.out.println("Exit action occuring");
//Close out the application
System.exit(0);
}
//Only non explicitly defined actions are those generated by ports.
//Since an arbitrary machine could have any number of serial ports
//its impossible to hard code choices based on menu items generated on the fly.
//Must pull the calling object and interrogate
else{
JMenuItem theItem = (JMenuItem)e.getSource();
String portChoice = theItem.getName();
System.out.println("Port chosen: "+portChoice);
currentPort = portChoice;
CommInterface.setPortChoice(currentPort);
bottomPanel.setEnabled(true);
//Notify the infoPane of the current port choice
//infoPane.setPort(currentPort);
}
}
public static void startLogger(final int defaultCloseOperation, final Settings settings) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JutecGUI application = new JutecGUI(defaultCloseOperation);
application.setVisible(true);
}
});
}
/**
* Main method
* @param args
*/
public static void main(String[] args) {
JutecGUI application = new JutecGUI(0);
application.setVisible(true);
}
}

View File

@ -0,0 +1,47 @@
/*
* Created on May 26, 2005
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package enginuity.logger.utec.gui.barGraph;
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
/**
* @author emorgan
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class BarGraph extends JComponent{
public BarGraph(){
}
private void Init(){
}
public void paint(Graphics g) {
//Dimensions of bounding entity
Dimension theSize = this.getSize();
int width = theSize.width;
int height = theSize.height;
Graphics2D g2 = (Graphics2D) g;
GradientPaint gp = new GradientPaint((float)0, (float)0, Color.RED, (float)0, (float)height-10, Color.GREEN);
RoundRectangle2D rect1 = new RoundRectangle2D.Double(30, 5, 90, 390, 10, 10);
g2.setPaint(gp);
g2.fill(rect1);
g2.setPaint(Color.BLACK);
g2.draw(rect1);
}
}

View File

@ -0,0 +1,195 @@
/*
* Created on May 29, 2005
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package enginuity.logger.utec.gui.bottomControl;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import enginuity.logger.utec.commInterface.CommInterface;
import enginuity.logger.utec.gui.JutecGUI;
import enginuity.logger.utec.commEvent.*;
/**
* @author emorgan
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class BottomUtecControl extends JPanel implements ActionListener, CommListener{
//Buttons to be used
private JButton openButton;
private JButton closeButton;
private JButton startButton;
private JButton stopButton;
//Text areas to be used
private JTextArea textFromUtec;
public String totalLog = "";
public void setOpenPortEnabled(boolean choice){
openButton.setEnabled(choice);
}
public BottomUtecControl() {
//Define UTEC output text Area
textFromUtec = new JTextArea();
textFromUtec.setCaretPosition(textFromUtec.getDocument().getLength());
textFromUtec.setText(
"--==< Live data feed from UTEC will start here. >==--\n");
JScrollPane utecOutTextScroll = new JScrollPane(textFromUtec);
//-------------------------
//Define buttons to be used
//-------------------------
//JButton button;
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
this.setLayout(gridbag);
c.fill = GridBagConstraints.BOTH;
c.gridwidth = 1;
//Button to open defined COM Port
openButton = new JButton("OPEN PORT");
openButton.addActionListener(this);
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 0;
gridbag.setConstraints(openButton, c);
//openButton.setEnabled(false);
this.add(openButton);
//Button to close defined COM port
closeButton = new JButton("CLOSE PORT");
closeButton.addActionListener(this);
closeButton.setEnabled(false);
c.gridx = 0;
c.gridy = 1;
gridbag.setConstraints(closeButton, c);
this.add(closeButton);
//Button to start data capture from UTEC
startButton = new JButton("START CAPTURE");
startButton.addActionListener(this);
startButton.setEnabled(false);
c.gridx = 0;
c.gridy = 2;
gridbag.setConstraints(startButton, c);
this.add(startButton);
//Button to stop data capture from UTEC
stopButton = new JButton("STOP CAPTURE");
stopButton.addActionListener(this);
stopButton.setEnabled(false);
c.gridx = 0;
c.gridy = 3;
gridbag.setConstraints(stopButton, c);
this.add(stopButton);
//Text box that returns live text data from the UTEC
c.ipadx = 600;
c.gridheight = 5;
c.gridx = 1;
c.gridy = 0;
gridbag.setConstraints(utecOutTextScroll, c);
this.add(utecOutTextScroll);
//Make this panel listen for comm events
CommInterface.addListener(this);
}
/**
* Implements actionPerformed
*
*/
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
//Open Port
if (cmd.equals("OPEN PORT")) {
System.out.println("Opening connection to defined port: "+CommInterface.getPortChoiceUsed());
//Don't allow use after first press, and until after close port has been pressed
openButton.setEnabled(false);
closeButton.setEnabled(true);
startButton.setEnabled(true);
stopButton.setEnabled(false);
//Use interface to open connection
CommInterface.openConnection();
//VoiceThread vc = new VoiceThread("open port");
//vc.start();
}
//Close Port
if (cmd.equals("CLOSE PORT")) {
System.out.println("Closing connection to defined port");
//Use interface to close the connection to the Utec
CommInterface.closeConnection();
//Set button states
openButton.setEnabled(true);
closeButton.setEnabled(false);
startButton.setEnabled(false);
stopButton.setEnabled(false);
//VoiceThread vc = new VoiceThread("close port.");
//vc.start();
}
//Start Capture
if (cmd.equals("START CAPTURE")) {
System.out.println("Starting data capture from the UTEC");
//Use interface to pull logging data from the Utec
CommInterface.startDataLogFromUtec();
//Set button states
startButton.setEnabled(false);
stopButton.setEnabled(true);
openButton.setEnabled(false);
closeButton.setEnabled(false);
//Disable log save option
JutecGUI.getInstance().saveItem.setEnabled(false);
//VoiceThread vc = new VoiceThread("start capture");
//vc.start();
}
//Stop Capture
if (cmd.equals("STOP CAPTURE")) {
System.out.println("Stopping data capture from the UTEC");
//Use interface to reset the state of the Utec
CommInterface.resetUtec();
//Set button states
startButton.setEnabled(true);
stopButton.setEnabled(false);
closeButton.setEnabled(true);
openButton.setEnabled(false);
//Enable log save option
JutecGUI.getInstance().saveItem.setEnabled(true);
//VoiceThread vc = new VoiceThread("stop capture");
//vc.start();
}
}
public void getCommEvent(CommEvent e){
String utecData = e.UtecBuffer;
totalLog+=utecData;
textFromUtec.append(utecData);
textFromUtec.setCaretPosition(textFromUtec.getDocument().getLength());
//System.out.println("Adding data to the text AREA");
}
}

View File

@ -0,0 +1,168 @@
package enginuity.logger.utec.gui.realtimeData;
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import enginuity.logger.utec.gui.bottomControl.*;
import enginuity.tts.VoiceThread;
import enginuity.logger.utec.commEvent.*;
import enginuity.logger.utec.commInterface.CommInterface;
/**
* @author botman
*
* Class displays live data from the UTEC
*/
public class RealTimeData extends JComponent implements CommListener{
//Buttons to be used
private JButton openButton;
private JButton closeButton;
private JButton startButton;
private JButton stopButton;
//Text areas to be used
private JTextArea textFromUtec;
//Recieved utec data, start values are zero
public String[] stringData = {"0","0","0","0","0","0"};
public double[] doubleData = {0,0,0,0,0,0};
//Graph Constants
private double maxHeight = 370;
//Window Constants
private int windowHeight = 400;
//Constructor
public RealTimeData() {
CommInterface.addListener(this);
}
/**
* Sets the used ports
* @param portChoice
*/
public void setPort(String portChoice) {
CommInterface.setPortChoice(portChoice);
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
GradientPaint gp = new GradientPaint((float)30, (float)-10, Color.RED, (float)30, (float)maxHeight, Color.GREEN);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Font font = new Font("Serif", Font.PLAIN, 20);
g2.setFont(font);
//RPM
double max1 = 7500;
double min1 = 0;
double value1 = doubleData[0];
double height1 = ((value1 - min1)/(max1 - min1))*maxHeight;
double yValue1 = 5 + (maxHeight - height1);
double xValueLeft1 = 30;
double width1 = 90;
RoundRectangle2D rect1 = new RoundRectangle2D.Double(xValueLeft1, yValue1, width1, height1, 10, 10);
g2.setPaint(gp);
g2.fill(rect1);
g2.setPaint(Color.BLACK);
g2.draw(rect1);
g2.drawString("RPM:"+(int)value1, (int)xValueLeft1, windowHeight);
//PSI
double max2 = 20;
double min2 = -14.7;
double value2 = doubleData[1];
if(value2 > 18.5){
VoiceThread vc = new VoiceThread("Max P S I,"+value2);
vc.start();
}
double height2 = ((value2 - min2)/(max2 - min2))*maxHeight;
double yValue2 = 5 + (maxHeight - height2);
double xValueLeft2 = 150;
double width2 = 90;
RoundRectangle2D rect2 = new RoundRectangle2D.Double(xValueLeft2, yValue2, width2, height2, 10, 10);
g2.setPaint(gp);
g2.fill(rect2);
g2.setPaint(Color.BLACK);
g2.draw(rect2);
g2.drawString("PSI:"+value2, (int)xValueLeft2, windowHeight);
//KNOCK
double max3 = 20;
double min3 = 0;
double value3 = doubleData[2];
if(value3 > 0){
VoiceThread vc = new VoiceThread("knock, count "+(int)value3);
vc.start();
}
double height3 = ((value3 - min3)/(max3 - min3))*maxHeight;
double yValue3 = 5 + (maxHeight - height3);
double xValueLeft3 = 280;
double width3 = 90;
RoundRectangle2D rect3 = new RoundRectangle2D.Double(xValueLeft3, yValue3, width3, height3, 10, 10);
g2.setPaint(gp);
g2.fill(rect3);
g2.setPaint(Color.BLACK);
g2.draw(rect3);
g2.drawString("KNOCK:"+(int)value3, (int)xValueLeft3, windowHeight);
//IGN
double max4 = 80;
double min4 = 0;
double value4 = doubleData[3];
double height4 = ((value4 - min4)/(max4 - min4))*maxHeight;
double yValue4 = 5 + (maxHeight - height4);
double xValueLeft4 = 400;
double width4 = 90;
RoundRectangle2D rect4 = new RoundRectangle2D.Double(xValueLeft4, yValue4, width4, height4, 10, 10);
g2.setPaint(gp);
g2.fill(rect4);
g2.setPaint(Color.BLACK);
g2.draw(rect4);
g2.drawString("IGN:"+value4, (int)xValueLeft4, windowHeight);
//DUTY
double max5 = 105;
double min5 = 0;
double value5 = doubleData[4];
if(value5 > 98){
VoiceThread vc = new VoiceThread("Max duty "+value5);
vc.start();
}
double height5 = ((value5 - min5)/(max5 - min5))*maxHeight;
double yValue5 = 5 + (maxHeight - height5);
double xValueLeft5 = 530;
double width5 = 90;
RoundRectangle2D rect5 = new RoundRectangle2D.Double(xValueLeft5, yValue5, width5, height5, 10, 10);
g2.setPaint(gp);
g2.fill(rect5);
g2.setPaint(Color.BLACK);
g2.draw(rect5);
g2.drawString("DUTY:"+value5, (int)xValueLeft5, windowHeight);
//AFR
double max6 = 26;
double min6 = 0;
double value6 = doubleData[5];
double height6 = ((value6 - min6)/(max6 - min6))*maxHeight;
double yValue6 = 5 + (maxHeight - height6);
double xValueLeft6 = 660;
double width6 = 90;
RoundRectangle2D rect6 = new RoundRectangle2D.Double(xValueLeft6, yValue6, width6, height6, 10, 10);
g2.setPaint(gp);
g2.fill(rect6);
g2.setPaint(Color.BLACK);
g2.draw(rect6);
g2.drawString("AFR:"+value6, (int)xValueLeft6, windowHeight);
}
public void getCommEvent(CommEvent e){
stringData = e.data;
doubleData = e.doubleData;
this.repaint();
}
}

View File

@ -32,6 +32,7 @@ import com.centerkey.utils.BareBonesBrowserLaunch;
import enginuity.ECUEditor;
import enginuity.logger.EcuLogger;
import enginuity.maps.Rom;
import enginuity.logger.utec.gui.JutecGUI;
public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
@ -63,7 +64,9 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
private JMenu loggerMenu = new JMenu("Logger");
private JMenuItem openLogger = new JMenuItem("Launch ECU Logger...");
private JMenuItem utecLogger = new JMenuItem("Launch UTEC Logger...");
private JMenu helpMenu = new JMenu("Help");
private JMenuItem about = new JMenuItem("About Enginuity");
@ -162,8 +165,10 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
loggerMenu.setMnemonic('L');
openLogger.setMnemonic('O');
loggerMenu.add(openLogger);
loggerMenu.add(utecLogger);
openLogger.addActionListener(this);
utecLogger.addActionListener(this);
// help menu stuff
add(helpMenu);
helpMenu.setMnemonic('H');
@ -265,6 +270,9 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
} else if (e.getSource() == openLogger) {
EcuLogger.startLogger(DISPOSE_ON_CLOSE, parent.getSettings());
} else if (e.getSource() == utecLogger) {
JutecGUI.startLogger(DISPOSE_ON_CLOSE, parent.getSettings());
} else if (e.getSource() == updateDefinition) {
BareBonesBrowserLaunch.openURL(parent.getSettings().getEcuDefsURL());

View File

@ -0,0 +1,42 @@
/*
* Created on May 31, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package enginuity.tts;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
/**
* @author botman
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class SpeakKnock {
private static VoiceManager voiceManager = VoiceManager.getInstance();
private static Voice theVoice = null;
public static void speakKnock(int count){
if(theVoice == null){
theVoice = voiceManager.getVoice("kevin16");
theVoice.allocate();
}
theVoice.speak("Knock! count "+count+"!");
}
public static void speakString(String message){
if(theVoice == null){
theVoice = voiceManager.getVoice("kevin16");
theVoice.allocate();
}
theVoice.speak(message);
}
public static void end(){
theVoice.deallocate();
}
}

View File

@ -0,0 +1,27 @@
/*
* Created on May 31, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package enginuity.tts;
/**
* @author botman
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class VoiceThread extends Thread{
private String message = null;
public VoiceThread(String message){
this.message = message;
}
public void run(){
SpeakKnock.speakString(message);
}
}