diff --git a/src/enginuity/logger/utec/comm/UtecSerialConnection.java b/src/enginuity/logger/utec/comm/UtecSerialConnection.java index 17fad5e1..e95723f9 100755 --- a/src/enginuity/logger/utec/comm/UtecSerialConnection.java +++ b/src/enginuity/logger/utec/comm/UtecSerialConnection.java @@ -25,9 +25,9 @@ import enginuity.logger.utec.properties.UtecProperties; // CommPortOwnershipListener { import gnu.io.*; -public class UtecSerialConnection { +public class UtecSerialConnection{ - private static GetMapFromUtecListener getMapFromUtecListener = null; + // Parameters used to define serial connection public static SerialParameters parameters = new SerialParameters(); @@ -50,14 +50,7 @@ public class UtecSerialConnection { // Listeners private static Vector portListeners = new Vector(); - // Define whether or not we are recieving a map from the UTEC - private static boolean isMapFromUtecPrep = false; - private static boolean isMapFromUtec = false; - - private static UtecMapData currentMap = null; - private static String totalDat = ""; - private static UtecSerialListener serialListener = null; public static void init(UtecSerialListener se){ @@ -100,6 +93,7 @@ public class UtecSerialConnection { * @throws SerialConnectionException */ public static void openConnection() throws SerialConnectionException { + System.out.println("Opening connection now."); // if(sPort == null){ System.err.println("No port selected or available to open."); return; } @@ -158,7 +152,7 @@ public class UtecSerialConnection { // Add this object as an event listener for the serial port. try { - sPort.addEventListener(serialListener); + sPort.addEventListener(new UtecSerialListener()); } catch (TooManyListenersException e) { System.err.println("Too Many listeners"); sPort.close(); @@ -282,4 +276,17 @@ public class UtecSerialConnection { public static boolean isOpen(){ return open; } + + public static InputStream getInputFromUtecStream() { + return inputFromUtecStream; + } + + public static OutputStream getOutputToUtecStream() { + return outputToUtecStream; + } + + public void serialEvent(SerialPortEvent arg0) { + // TODO Auto-generated method stub + + } } diff --git a/src/enginuity/logger/utec/commEvent/LoggerEvent.java b/src/enginuity/logger/utec/commEvent/LoggerEvent.java index 5b6ad413..ddd5f1c5 100755 --- a/src/enginuity/logger/utec/commEvent/LoggerEvent.java +++ b/src/enginuity/logger/utec/commEvent/LoggerEvent.java @@ -48,27 +48,17 @@ public class LoggerEvent { if(theData.startsWith("--")){ theData = "0.0"; } + if(theData.startsWith("ECU")){ + theData = "0.0"; + } try{ doubleData[i] = Double.parseDouble(theData); }catch (NumberFormatException e) { - System.out.println("Number error in commevent."); + //System.out.println("Number error in commevent."); this.isValidData = false; return; } - - - // Valid data found - String[] afrIndex = UtecProperties.getProperties("utec.afrIndex"); - if(afrIndex == null || afrIndex[0] == null || afrIndex[0].length() < 1){ - // No afr data available - }else{ - System.out.println("AFR Data available."); - UtecAFRListener utecAFRListener = DataManager.getUtecAFRListener(); - if(utecAFRListener != null){ - utecAFRListener.receivedUtecAFRData(Double.parseDouble(afrIndex[0])); - } - } } } diff --git a/src/enginuity/logger/utec/commEvent/UtecTimerTask.java b/src/enginuity/logger/utec/commEvent/UtecTimerTask.java index 16c67956..6aef9c2c 100644 --- a/src/enginuity/logger/utec/commEvent/UtecTimerTask.java +++ b/src/enginuity/logger/utec/commEvent/UtecTimerTask.java @@ -3,6 +3,7 @@ package enginuity.logger.utec.commEvent; import java.util.TimerTask; import enginuity.logger.utec.comm.UtecSerialConnection; +import enginuity.logger.utec.gui.JutecGUI; public class UtecTimerTask extends TimerTask{ private UtecTimerTaskListener listener = null; @@ -14,16 +15,19 @@ public class UtecTimerTask extends TimerTask{ this.listener = listener; this.data = data; this.stringBuffer = new StringBuffer(data); + JutecGUI.getInstance().getJProgressBar().setMinimum(0); + JutecGUI.getInstance().getJProgressBar().setMaximum(data.length()); } public void run(){ char theChar = stringBuffer.charAt(counter); - System.out.println("->"+theChar+"<- :"+(int)theChar+""); + // System.out.println("->"+theChar+"<- :"+(int)theChar+""); //Send the data to the Utec UtecSerialConnection.sendCommandToUtec((int)theChar); counter++; + JutecGUI.getInstance().getJProgressBar().setValue(counter); // Kill the timer after a at the end of the string if(counter == data.length()){ diff --git a/src/enginuity/logger/utec/commInterface/UtecInterface.java b/src/enginuity/logger/utec/commInterface/UtecInterface.java index 47b68ec3..c88b6c5e 100755 --- a/src/enginuity/logger/utec/commInterface/UtecInterface.java +++ b/src/enginuity/logger/utec/commInterface/UtecInterface.java @@ -36,7 +36,7 @@ import enginuity.logger.utec.commEvent.UtecTimerTaskManager; public class UtecInterface{ //Store string vector of known system comm ports private static Vector portChoices = listPortChoices(); - private static UtecSerialListener se = new UtecSerialListener(); + private static UtecSerialListener serialEventListener = new UtecSerialListener(); private static Vector loggerListeners = new Vector(); /** @@ -44,7 +44,7 @@ public class UtecInterface{ * */ public static void init(){ - UtecSerialConnection.init(se); + UtecSerialConnection.init(serialEventListener); } /** @@ -166,8 +166,7 @@ public class UtecInterface{ * @param mapNumber */ - public static void pullMapData(int mapNumber, GetMapFromUtecListener listener) { - /* + public static void pullMapData(int mapNumber) { // Sanity check if (mapNumber < 1 || mapNumber > 5) { System.err.println("Map selection out of range."); @@ -184,14 +183,11 @@ public class UtecInterface{ System.out.println("UtecControl, getting map:" + mapNumber); // Null out any previously loaded map - this.currentMap = null; - - // Who will get this map in the end? - this.getMapFromUtecListener = listener; + serialEventListener.currentMap = null; // Setup map transfer prep state - this.isMapFromUtecPrep = true; - this.isMapFromUtec = false; + serialEventListener.isMapFromUtecPrep = true; + serialEventListener.isMapFromUtec = false; // Iterate through command string int starCounter = 0; @@ -201,32 +197,32 @@ public class UtecInterface{ // Select map if (mapNumber == 1) { - this.sendCommandToUtec(33); + UtecTimerTaskManager.execute(33); System.out.println("Requested Map 1"); } if (mapNumber == 2) { - this.sendCommandToUtec(64); + UtecTimerTaskManager.execute(64); System.out.println("Requested Map 2"); } if (mapNumber == 3) { - this.sendCommandToUtec(35); + UtecTimerTaskManager.execute(35); System.out.println("Requested Map 3"); } if (mapNumber == 4) { - this.sendCommandToUtec(36); + UtecTimerTaskManager.execute(36); System.out.println("Requested Map 4"); } if (mapNumber == 5) { - this.sendCommandToUtec(37); + UtecTimerTaskManager.execute(37); System.out.println("Requested Map 5"); } }else if(starCounter == 1){ // Make this class receptive to map transfer - this.isMapFromUtec = true; + serialEventListener.isMapFromUtec = true; // No longer map prep - this.isMapFromUtecPrep = false; + serialEventListener.isMapFromUtecPrep = false; }else{ System.err.println("No operation supported for properties value '*'"); @@ -235,10 +231,9 @@ public class UtecInterface{ starCounter++; }else{ // Send parsed command to the utec - this.sendCommandToUtec(Integer.parseInt(commandList[i])); + UtecTimerTaskManager.execute(Integer.parseInt(commandList[i])); } } - */ } @@ -343,4 +338,8 @@ public class UtecInterface{ public static void addLoggerListener(LoggerListener ll){ loggerListeners.add(ll); } + + public static Vector getLoggerListeners() { + return loggerListeners; + } } \ No newline at end of file diff --git a/src/enginuity/logger/utec/commInterface/UtecSerialListener.java b/src/enginuity/logger/utec/commInterface/UtecSerialListener.java index 96cb5e38..5e22fc1d 100644 --- a/src/enginuity/logger/utec/commInterface/UtecSerialListener.java +++ b/src/enginuity/logger/utec/commInterface/UtecSerialListener.java @@ -3,26 +3,29 @@ package enginuity.logger.utec.commInterface; import java.io.IOException; import java.util.Iterator; +import enginuity.logger.utec.comm.UtecSerialConnection; import enginuity.logger.utec.commEvent.LoggerEvent; import enginuity.logger.utec.commEvent.LoggerListener; +import enginuity.logger.utec.gui.mapTabs.DataManager; import enginuity.logger.utec.mapData.UtecMapData; import gnu.io.SerialPortEvent; import gnu.io.SerialPortEventListener; public class UtecSerialListener implements SerialPortEventListener{ - + // Define whether or not we are recieving a map from the UTEC + public boolean isMapFromUtecPrep = false; + public boolean isMapFromUtec = false; + public UtecMapData currentMap = null; + public String totalDat = ""; + + public UtecSerialListener(){ + System.out.println("Serial listener was instantiated."); + } - - /** - * 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) { - /* + System.out.println("Got serial event."); + + // Create a StringBuffer and int to receive input data. StringBuffer inputBuffer = new StringBuffer(); int newData = 0; @@ -37,20 +40,12 @@ public class UtecSerialListener implements SerialPortEventListener{ // Append new output to buffer while (newData != -1) { try { - newData = inputFromUtecStream.read(); + newData = UtecSerialConnection.getInputFromUtecStream().read(); if (newData == -1) { break; } - - //if ('\r' == (char) newData) { - // inputBuffer.append('\n'); - //} else { - // inputBuffer.append((char) newData); - //} - - inputBuffer.append((char) newData); System.out.print((char)newData); this.totalDat += (char)newData; @@ -60,7 +55,7 @@ public class UtecSerialListener implements SerialPortEventListener{ return; } } -// Ouput to console + //System.out.println(inputBuffer); if (this.isMapFromUtecPrep == true) { @@ -93,14 +88,17 @@ public class UtecSerialListener implements SerialPortEventListener{ this.currentMap.populateMapDataStructures(); System.out.println("hi 3"); + // Inform data manager of new map + DataManager.setCurrentMap(this.currentMap); + // Notify listner if available - System.out.println("Calling listeners."); - if (this.getMapFromUtecListener != null) { - System.out.println("Listener called."); - this.getMapFromUtecListener.mapRetrieved(this.currentMap); - }else{ - System.out.println("Calling listeners, but none found."); - } + //System.out.println("Calling listeners."); + //if (this.getMapFromUtecListener != null) { + // System.out.println("Listener called."); + // this.getMapFromUtecListener.mapRetrieved(this.currentMap); + //}else{ + // System.out.println("Calling listeners, but none found."); + //} // Empty out map storage this.currentMap = null; @@ -114,11 +112,14 @@ public class UtecSerialListener implements SerialPortEventListener{ loggerEvent.setLoggerData(new String(inputBuffer)); loggerEvent.setLoggerData(true); - Iterator portIterator = portListeners.iterator(); + Iterator portIterator = UtecInterface.getLoggerListeners().iterator(); while (portIterator.hasNext()) { LoggerListener theListener = (LoggerListener) portIterator.next(); if(loggerEvent.isValidData() == true){ + //System.out.println("Valid data"); theListener.getCommEvent(loggerEvent); + }else{ + //System.out.println("Invalid data"); } } @@ -130,7 +131,5 @@ public class UtecSerialListener implements SerialPortEventListener{ //System.out.println("BREAK RECEIVED."); } - */ } - } diff --git a/src/enginuity/logger/utec/gui/JutecGUI.java b/src/enginuity/logger/utec/gui/JutecGUI.java index 1d478b26..b75deff6 100755 --- a/src/enginuity/logger/utec/gui/JutecGUI.java +++ b/src/enginuity/logger/utec/gui/JutecGUI.java @@ -27,7 +27,7 @@ import enginuity.logger.utec.commInterface.UtecInterface; /** * @author botman */ -public class JutecGUI extends JFrame implements ActionListener,GetMapFromUtecListener, KeyListener { +public class JutecGUI extends JFrame implements ActionListener, KeyListener { // Top level desktop pane public JLayeredPane desktop = null; @@ -78,17 +78,17 @@ public class JutecGUI extends JFrame implements ActionListener,GetMapFromUtecLis private static JutecGUI instance = null; - public static UtecMapData currentMap = null; // Text input field for sending commands directly to the UTEC private JTextField textInput = new JTextField(); private JLabel utecInputLabel = new JLabel(" Send Single Char Commands to UTEC: "); - // Map tabs - private MapJPanel timingMapPanel = new MapJPanel(MapJPanel.TIMINGMAP); - private MapJPanel fuelMapPanel = new MapJPanel(MapJPanel.FUELMAP); - private MapJPanel boostMapPanel = new MapJPanel(MapJPanel.BOOSTMAP); + private JProgressBar jProgressBar = new JProgressBar(); + + public JProgressBar getJProgressBar() { + return jProgressBar; + } public static JutecGUI getInstance() { return instance; @@ -103,12 +103,15 @@ public class JutecGUI extends JFrame implements ActionListener,GetMapFromUtecLis this.setResizable(false); this.setDefaultCloseOperation(setDefaultCloseOperation); + this.jProgressBar.setSize(790,20); + // ************************* // Voice the welcome message // ************************* SpeakString vc = new SpeakString("Welcome to you teck logger! Use at your own risk."); - + System.out.println("UTEC Gui is loading now."); + // Actions to take when window is closing addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { @@ -221,7 +224,8 @@ public class JutecGUI extends JFrame implements ActionListener,GetMapFromUtecLis JPanel totalPanel = new JPanel(new BorderLayout()); JPanel commandPanel = new JPanel(new BorderLayout()); this.textInput.addKeyListener(this); - + + commandPanel.add(this.jProgressBar, BorderLayout.NORTH); commandPanel.add(this.utecInputLabel, BorderLayout.WEST); commandPanel.add(this.textInput, BorderLayout.CENTER); @@ -312,14 +316,14 @@ public class JutecGUI extends JFrame implements ActionListener,GetMapFromUtecLis else if (cmd.equals("Save Map To File")) { System.out.println("Saving map to file."); - if (this.currentMap != null) { + if (DataManager.getCurrentMapData() != null) { String saveFileName = null; System.out.println("Save map now."); fileChosen = fileChooser.showSaveDialog(this); if (fileChosen == JFileChooser.APPROVE_OPTION) { saveFileName = fileChooser.getSelectedFile().getPath(); - this.currentMap.writeMapToFile(saveFileName); + DataManager.getCurrentMapData().writeMapToFile(saveFileName); } } else { @@ -329,27 +333,27 @@ public class JutecGUI extends JFrame implements ActionListener,GetMapFromUtecLis else if (cmd.equals("Load Map #1")) { System.out.println("Starting to get map 1"); - UtecInterface.pullMapData(1, this); + UtecInterface.pullMapData(1); } else if (cmd.equals("Load Map #2")) { System.out.println("Starting to get map 2"); - UtecInterface.pullMapData(2, this); + UtecInterface.pullMapData(2); } else if (cmd.equals("Load Map #3")) { System.out.println("Starting to get map 3"); - UtecInterface.pullMapData(3, this); + UtecInterface.pullMapData(3); } else if (cmd.equals("Load Map #4")) { System.out.println("Starting to get map 4"); - UtecInterface.pullMapData(4, this); + UtecInterface.pullMapData(4); } else if (cmd.equals("Load Map #5")) { System.out.println("Starting to get map 5"); - UtecInterface.pullMapData(5, this); + UtecInterface.pullMapData(5); } else if (cmd.equals("Load Map File")) { @@ -453,12 +457,6 @@ public class JutecGUI extends JFrame implements ActionListener,GetMapFromUtecLis } - public void mapRetrieved(UtecMapData theMap) { - System.out.println("@@@@@@@@@@@@@@@@@@ Got a map from the utec:" + theMap.getMapName()); - this.currentMap = theMap; - DataManager.setCurrentMap(theMap); - } - public void keyPressed(KeyEvent arg0) { //System.out.println("Key Pressed"); // System.out.println("Key Pressed:"+arg0.getKeyCode()+" :"+arg0.getKeyChar()+" :"+arg0.getModifiers()+" :"+(int)arg0.getKeyChar()); diff --git a/src/enginuity/logger/utec/gui/mapTabs/MapJPanel.java b/src/enginuity/logger/utec/gui/mapTabs/MapJPanel.java index 53c9b56f..8d832789 100644 --- a/src/enginuity/logger/utec/gui/mapTabs/MapJPanel.java +++ b/src/enginuity/logger/utec/gui/mapTabs/MapJPanel.java @@ -36,12 +36,23 @@ public class MapJPanel extends JPanel{ } this.tableModel = new UtecTableModel(this.mapType, initialData); - init(); + if(this.mapType == MapJPanel.FUELMAP){ + init(-8.0, 8.0); + } + + if(this.mapType == MapJPanel.TIMINGMAP){ + init(-1.0, 5.0); + } + + if(this.mapType == MapJPanel.BOOSTMAP){ + init(0.0, 500.0); + } + } - public void init(){ - table = new UtecJTable(tableModel, mapType); + public void init(double min, double max){ + table = new UtecJTable(tableModel, mapType, min, max); //table.setPreferredScrollableViewportSize(new Dimension(500, 70)); //Create the scroll pane and add the table to it. diff --git a/src/enginuity/logger/utec/gui/mapTabs/UtecJTable.java b/src/enginuity/logger/utec/gui/mapTabs/UtecJTable.java index fce69562..60c6172e 100644 --- a/src/enginuity/logger/utec/gui/mapTabs/UtecJTable.java +++ b/src/enginuity/logger/utec/gui/mapTabs/UtecJTable.java @@ -1,13 +1,26 @@ package enginuity.logger.utec.gui.mapTabs; import javax.swing.JTable; +import javax.swing.ListSelectionModel; public class UtecJTable extends JTable{ - public UtecJTable(UtecTableModel theModel, int modelType){ + public UtecJTable(UtecTableModel theModel, int modelType, double minValue, double maxValue){ super(theModel); + //this.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + //this.getColumnModel().getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + //this.setRowSelectionAllowed(false); + this.setCellSelectionEnabled(true); + //this.setColumnSelectionAllowed(false); + this.getSelectionModel().addListSelectionListener(new UtecSelectionListener(this)); + + this.setDefaultRenderer(Object.class, new UtecTableCellRenderer(minValue, maxValue)); + + + // ************************ + // Utec Specific code below + // ************************ if(modelType == MapJPanel.FUELMAP){ - System.out.println("Setting the fuel listener"); DataManager.setFuelListener(theModel); } else if(modelType == MapJPanel.BOOSTMAP){ @@ -19,7 +32,6 @@ public class UtecJTable extends JTable{ } public void updateData(double[][] newData){ - System.out.println("Hi ya spanky"); ((UtecTableModel)this.dataModel).replaceData(newData); } } diff --git a/src/enginuity/logger/utec/gui/mapTabs/UtecSelectionListener.java b/src/enginuity/logger/utec/gui/mapTabs/UtecSelectionListener.java new file mode 100644 index 00000000..c86ea0eb --- /dev/null +++ b/src/enginuity/logger/utec/gui/mapTabs/UtecSelectionListener.java @@ -0,0 +1,34 @@ +package enginuity.logger.utec.gui.mapTabs; + +import javax.swing.JTable; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +public class UtecSelectionListener implements ListSelectionListener{ + private JTable parentTable = null; + + public UtecSelectionListener(JTable parentTable){ + this.parentTable = parentTable; + } + public void valueChanged(ListSelectionEvent event) { + //System.out.println("1: "+ event.getFirstIndex()+" 2: "+event.getLastIndex()); + + int selRow[] = parentTable.getSelectedRows(); + int selCol[] = parentTable.getSelectedColumns(); + + + for(int i = 0; i < selRow.length; i++){ + //System.out.println("Row Value: "+selRow[i]); + } + + for(int i = 0; i < selCol.length; i++){ + //System.out.println("Col Value: "+selCol[i]); + } + + //System.out.println("---------------------------"); + Object[] selectedCells = new Object[selRow.length * selCol.length]; + + + } + +} diff --git a/src/enginuity/logger/utec/gui/mapTabs/UtecTableCellRenderer.java b/src/enginuity/logger/utec/gui/mapTabs/UtecTableCellRenderer.java new file mode 100644 index 00000000..6161eb28 --- /dev/null +++ b/src/enginuity/logger/utec/gui/mapTabs/UtecTableCellRenderer.java @@ -0,0 +1,40 @@ +package enginuity.logger.utec.gui.mapTabs; + +import java.awt.Color; +import java.awt.Component; + +import javax.swing.JTable; +import javax.swing.table.DefaultTableCellRenderer; +import javax.vecmath.Color3f; + +import com.ecm.graphics.tools.ColorTable; + +public class UtecTableCellRenderer extends DefaultTableCellRenderer{ + private double min; + private double max; + + public UtecTableCellRenderer(double min, double max){ + this.min = min; + this.max = max; + } + + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col){ + Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col); + + if(isSelected){ + cell.setBackground(Color.BLUE); + }else{ + if(value instanceof Double){ + //System.out.println("Amount:"+(Double)value); + } + ColorTable.initColorTable(min, max); + Color3f theColor = ColorTable.getColor((Double)value); + + cell.setBackground(new Color(theColor.x, theColor.y, theColor.z)); + } + + + + return cell; + } +} diff --git a/src/enginuity/logger/utec/gui/mapTabs/UtecTableModel.java b/src/enginuity/logger/utec/gui/mapTabs/UtecTableModel.java index be3d39ac..879aa65e 100644 --- a/src/enginuity/logger/utec/gui/mapTabs/UtecTableModel.java +++ b/src/enginuity/logger/utec/gui/mapTabs/UtecTableModel.java @@ -20,6 +20,7 @@ public class UtecTableModel extends AbstractTableModel { for (int i = 0; i < columnNames.length; i++) { columnNames[i] = i + ""; } + } public int getColumnCount() { diff --git a/src/enginuity/logger/utec/gui/mapTabs/UtecTableSelectionListener.java b/src/enginuity/logger/utec/gui/mapTabs/UtecTableSelectionListener.java new file mode 100644 index 00000000..54df17e4 --- /dev/null +++ b/src/enginuity/logger/utec/gui/mapTabs/UtecTableSelectionListener.java @@ -0,0 +1,13 @@ +package enginuity.logger.utec.gui.mapTabs; + +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; + +public class UtecTableSelectionListener implements TableModelListener{ + + public void tableChanged(TableModelEvent arg0) { + // TODO Auto-generated method stub + + } + +}