From a32691e8a8ff89d5ddc9d3f85516012a66c5c998 Mon Sep 17 00:00:00 2001 From: Tgui Date: Mon, 26 Feb 2007 23:30:35 +0000 Subject: [PATCH] working on saving maps back to the utec git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@541 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d --- .../utec/comm/UtecSerialConnection.java | 256 +++++++++++++----- .../logger/utec/commEvent/CommEvent.java | 44 +-- .../utec/commInterface/UtecInterface.java | 10 +- src/enginuity/logger/utec/gui/JutecGUI.java | 64 ++++- .../logger/utec/gui/mapTabs/DataManager.java | 17 +- .../utec/gui/realtimeData/RealTimeData.java | 97 +++---- .../utec/properties/UtecProperties.java | 39 +++ .../{VoiceThread.java => SpeakString.java} | 17 +- utec/utec.properties | 10 + 9 files changed, 379 insertions(+), 175 deletions(-) create mode 100644 src/enginuity/logger/utec/properties/UtecProperties.java rename src/enginuity/tts/{VoiceThread.java => SpeakString.java} (57%) create mode 100644 utec/utec.properties diff --git a/src/enginuity/logger/utec/comm/UtecSerialConnection.java b/src/enginuity/logger/utec/comm/UtecSerialConnection.java index 891afa63..aa2d6d8c 100755 --- a/src/enginuity/logger/utec/comm/UtecSerialConnection.java +++ b/src/enginuity/logger/utec/comm/UtecSerialConnection.java @@ -8,6 +8,7 @@ import javax.swing.*; import enginuity.logger.utec.commEvent.*; import enginuity.logger.utec.mapData.GetMapFromUtecListener; import enginuity.logger.utec.mapData.UtecMapData; +import enginuity.logger.utec.properties.UtecProperties; /** * Class negotiates data to and from UTEC via the serial port @@ -89,9 +90,18 @@ public class UtecSerialConnection implements SerialPortEventListener { */ public void startLoggerDataFlow() { System.out.println("Starting data flow from UTEC"); - - // OutPut a '!' to start basic data flow from UTEC - this.sendDataToUtec(33); + + String[] commandList = UtecProperties.getProperties("utec.startLogging"); + if(commandList == null){ + System.err.println("Command string in properties file for utec.startLogging not found."); + return; + } + + this.resetUtec(); + for(int i = 0; i < commandList.length ; i++){ + // Send parsed command to the utec + this.sendCommandToUtec(Integer.parseInt(commandList[i])); + } } /** @@ -99,16 +109,18 @@ public class UtecSerialConnection implements SerialPortEventListener { * */ public void resetUtec() { - // OutPut 2 ctrl-x to UTEC - // this.sendDataToUtec('\u0018'); - // this.sendDataToUtec('\u0018'); System.out.println("Utec reset called."); - this.sendDataToUtec(24); - this.waitForIt(); - this.sendDataToUtec(24); - this.waitForIt(); - this.sendDataToUtec(24); - this.waitForIt(); + + String[] commandList = UtecProperties.getProperties("utec.resetUtec"); + if(commandList == null){ + System.err.println("Command string in properties file for utec.resetUtec not found."); + return; + } + + for(int i = 0; i < commandList.length ; i++){ + // Send parsed command to the utec + this.sendCommandToUtec(Integer.parseInt(commandList[i])); + } } /** @@ -117,14 +129,21 @@ public class UtecSerialConnection implements SerialPortEventListener { * @param mapNumber */ public void pullMapData(int mapNumber, GetMapFromUtecListener listener) { - this.resetUtec(); - System.out.println("UtecControl, getting map:" + mapNumber); - // Check bounds of map requested + // Sanity check if (mapNumber < 1 || mapNumber > 5) { System.err.println("Map selection out of range."); return; } + + String[] commandList = UtecProperties.getProperties("utec.startMapDownload"); + if(commandList == null){ + System.err.println("Command string in properties file for utec.startMapDownload not found."); + return; + } + + this.resetUtec(); + System.out.println("UtecControl, getting map:" + mapNumber); // Null out any previously loaded map this.currentMap = null; @@ -135,87 +154,178 @@ public class UtecSerialConnection implements SerialPortEventListener { // Setup map transfer prep state this.isMapFromUtecPrep = true; this.isMapFromUtec = false; - - // Reset the UTEC - this.resetUtec(); - - // Send an 'e' to enter map menu - // this.sendDataToUtec('\u0065'); - this.sendDataToUtec(101); - System.out.println("Sent an e"); - this.waitForIt(); - // Point UTEC menu to the appropriate map - if (mapNumber == 1) { - // this.sendDataToUtec('\u0021'); - this.sendDataToUtec(33); - System.out.println("Requested Map 1"); - this.waitForIt(); - } - if (mapNumber == 2) { - // this.sendDataToUtec('\u0040'); - this.sendDataToUtec(64); - System.out.println("Requested Map 2"); - } - if (mapNumber == 3) { - // this.sendDataToUtec('\u0023'); - this.sendDataToUtec(35); - System.out.println("Requested Map 3"); - } - if (mapNumber == 4) { - // this.sendDataToUtec('\u0024'); - this.sendDataToUtec(36); - System.out.println("Requested Map 4"); - } - if (mapNumber == 5) { - // this.sendDataToUtec('\u0025'); - this.sendDataToUtec(37); - System.out.println("Requested Map 5"); - } + // Iterate through command string + int starCounter = 0; + for(int i = 0; i < commandList.length ; i++){ + if(commandList[i].equalsIgnoreCase("*")){ + if(starCounter == 0){ + // Select map + + if (mapNumber == 1) { + this.sendCommandToUtec(33); + System.out.println("Requested Map 1"); + } + if (mapNumber == 2) { + this.sendCommandToUtec(64); + System.out.println("Requested Map 2"); + } + if (mapNumber == 3) { + this.sendCommandToUtec(35); + System.out.println("Requested Map 3"); + } + if (mapNumber == 4) { + this.sendCommandToUtec(36); + System.out.println("Requested Map 4"); + } + if (mapNumber == 5) { + this.sendCommandToUtec(37); + System.out.println("Requested Map 5"); + } + }else if(starCounter == 1){ - // Write first ctrl-s to init save state - // this.sendDataToUtec('\u0013'); - this.sendDataToUtec(19); - System.out.println("Sent crtl-s"); - this.waitForIt(); + // Make this class receptive to map transfer + this.isMapFromUtec = true; - // Make this class receptive to map transfer - this.isMapFromUtec = true; - - // No longer map prep - this.isMapFromUtecPrep = false; - - // Write second ctrl-s to start map data flow - // this.sendDataToUtec('\u0013'); - this.sendDataToUtec(19); - System.out.println("Sent crtl-s"); + // No longer map prep + this.isMapFromUtecPrep = false; + + }else{ + System.err.println("No operation supported for properties value '*'"); + } + + starCounter++; + }else{ + // Send parsed command to the utec + this.sendCommandToUtec(Integer.parseInt(commandList[i])); + } + } + } /** - * Helper method to write chars to the UTEC + * Transmit a map to the utec + * + * @param mapNumber + * @param listener + */ + public void sendMapData(int mapNumber, StringBuffer mapData) { + + // Sanity check + if (mapNumber < 1 || mapNumber > 5) { + System.err.println("Map selection out of range."); + return; + } + + String[] commandList = UtecProperties.getProperties("utec.startMapDownload"); + if(commandList == null){ + System.err.println("Command string in properties file for utec.startMapUpload not found."); + return; + } + + this.resetUtec(); + System.out.println("UtecControl, sending map:" + mapNumber); + + // Iterate through command string + int starCounter = 0; + for(int i = 0; i < commandList.length ; i++){ + if(commandList[i].equalsIgnoreCase("*")){ + if(starCounter == 0){ + // Select map + + if (mapNumber == 1) { + this.sendCommandToUtec(33); + System.out.println("Requested Map 1"); + } + if (mapNumber == 2) { + this.sendCommandToUtec(64); + System.out.println("Requested Map 2"); + } + if (mapNumber == 3) { + this.sendCommandToUtec(35); + System.out.println("Requested Map 3"); + } + if (mapNumber == 4) { + this.sendCommandToUtec(36); + System.out.println("Requested Map 4"); + } + if (mapNumber == 5) { + this.sendCommandToUtec(37); + System.out.println("Requested Map 5"); + } + }else if(starCounter == 1){ + this.sendDataToUtec(mapData); + + }else{ + System.err.println("No operation supported for properties value '*'"); + } + + starCounter++; + }else{ + // Send parsed command to the utec + this.sendCommandToUtec(Integer.parseInt(commandList[i])); + } + } + } + + + /** + * Helper method to write chcommands to the UTEC. There is a pause after each command sent to ensure utec has time to respond. * * @param charValue */ - public void sendDataToUtec(int charValue) { + public void sendCommandToUtec(int charValue) { if(this.sPort == null){ System.err.println("No Port Selected, therefore no interraction with Utec happening."); - return; } + return; + } try { outputToUtecStream.write(charValue); + + System.out.println("Sending command to the ute:"+charValue); } catch (IOException e) { - System.err.println("Can't send char data to UTEC: " + charValue); + System.err.println("Can't send char command to UTEC: " + charValue); e.getMessage(); } - + this.waitForIt(); } + /** + * Method sends string data to the utec + * @param mapData + */ + public void sendDataToUtec(StringBuffer mapData){ + if(this.sPort == null){ System.err.println("No Port Selected, therefore no interraction with Utec happening."); + return; + } + + for(int i = 0; i < mapData.length(); i++){ + try { + outputToUtecStream.write(mapData.charAt(i)); + } catch (IOException e) { + System.err.println("Can't send char data to UTEC: " + mapData.charAt(i)); + e.getMessage(); + } + + //Wait + this.waitForIt(); + } + } + + /** + * Helper method to pause application. Used to spread data transmission + * + */ private void waitForIt(){ + String[] pauseString = UtecProperties.getProperties("utec.dataTransmissionPauseMS"); + + int pauseCount = Integer.parseInt(pauseString[0]); try { - Thread.currentThread().sleep(1000); - System.out.println("waiting 1 second."); + Thread.currentThread().sleep(pauseCount); + System.out.println("waiting for this many ms:"+pauseCount); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/src/enginuity/logger/utec/commEvent/CommEvent.java b/src/enginuity/logger/utec/commEvent/CommEvent.java index 0246711d..f116d8c2 100755 --- a/src/enginuity/logger/utec/commEvent/CommEvent.java +++ b/src/enginuity/logger/utec/commEvent/CommEvent.java @@ -21,7 +21,7 @@ import enginuity.logger.utec.mapData.UtecMapData; public class CommEvent { private String UtecBuffer = null; private String[] data = new String[6]; - private double[] doubleData = new double[6]; + private double[] doubleData = null; //new double[6]; private boolean isLoggerData = false; private boolean isMapData = false; @@ -32,45 +32,11 @@ public class CommEvent { public void setLoggerData(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++){ + data = UtecBuffer.split(","); + doubleData = new double[data.length]; + + for(int i = 0; i < data.length; i++){ String theData = data[i]; theData = theData.trim(); if(theData.startsWith(">")){ diff --git a/src/enginuity/logger/utec/commInterface/UtecInterface.java b/src/enginuity/logger/utec/commInterface/UtecInterface.java index 3e7b556f..335899e1 100755 --- a/src/enginuity/logger/utec/commInterface/UtecInterface.java +++ b/src/enginuity/logger/utec/commInterface/UtecInterface.java @@ -19,6 +19,7 @@ import javax.swing.*; import enginuity.logger.utec.gui.realtimeData.*; import enginuity.logger.utec.mapData.GetMapFromUtecListener; +import enginuity.logger.utec.mapData.UtecMapData; import enginuity.logger.utec.comm.*; /** * @author emorgan @@ -52,13 +53,18 @@ public class UtecInterface{ utecControl.pullMapData(mapNumber, listener); } + public static void uploadMap(int mapNumber, UtecMapData mapData){ + openConnection(); + utecControl.sendMapData(mapNumber, mapData.getUpdatedMap()); + } + /** * Pass a command to the UTEC * @param charValue */ - public static void sendDataToUtec(int charValue){ + public static void sendCommandToUtec(int charValue){ openConnection(); - utecControl.sendDataToUtec(charValue); + utecControl.sendCommandToUtec(charValue); } /** diff --git a/src/enginuity/logger/utec/gui/JutecGUI.java b/src/enginuity/logger/utec/gui/JutecGUI.java index e741c351..b854ea63 100755 --- a/src/enginuity/logger/utec/gui/JutecGUI.java +++ b/src/enginuity/logger/utec/gui/JutecGUI.java @@ -20,7 +20,8 @@ import enginuity.logger.utec.gui.realtimeData.*; import enginuity.logger.utec.gui.bottomControl.*; import enginuity.logger.utec.mapData.GetMapFromUtecListener; import enginuity.logger.utec.mapData.UtecMapData; -import enginuity.tts.VoiceThread; +import enginuity.logger.utec.properties.UtecProperties; +import enginuity.tts.SpeakString; import enginuity.logger.utec.commInterface.UtecInterface; /** @@ -67,6 +68,11 @@ public class JutecGUI extends JFrame implements ActionListener,GetMapFromUtecLis public JMenuItem loadMapFour = new JMenuItem("Load Map #4"); public JMenuItem loadMapFive = new JMenuItem("Load Map #5"); + public JMenuItem saveMapOne = new JMenuItem("Save To Map #1"); + public JMenuItem saveMapTwo = new JMenuItem("Save To Map #2"); + public JMenuItem saveMapThree = new JMenuItem("Save To Map #3"); + public JMenuItem saveMapFour = new JMenuItem("Save To Map #4"); + public JMenuItem saveMapFive = new JMenuItem("Save To Map #5"); private static JutecGUI instance = null; @@ -88,20 +94,19 @@ public class JutecGUI extends JFrame implements ActionListener,GetMapFromUtecLis } private JutecGUI(int setDefaultCloseOperation) { - + // Main frame // Grid layout with a top and bottom, ie two rows - super("UTEC Loggers"); + super("UTEC Logger"); this.setSize(800, 640); 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(); + SpeakString vc = new SpeakString("Welcome to you teck logger! Use at your own risk."); // Actions to take when window is closing addWindowListener(new WindowAdapter() { @@ -158,6 +163,23 @@ public class JutecGUI extends JFrame implements ActionListener,GetMapFromUtecLis getMapsMenu.add(loadMapFour); getMapsMenu.add(loadMapFive); menuBar.add(getMapsMenu); + + + // **************************************** + // Add menu item to save maps to the utec + // **************************************** + JMenu setMapsMenu = new JMenu("Save Map"); + saveMapOne.addActionListener(this); + saveMapTwo.addActionListener(this); + saveMapThree.addActionListener(this); + saveMapFour.addActionListener(this); + saveMapFive.addActionListener(this); + setMapsMenu.add(saveMapOne); + setMapsMenu.add(saveMapTwo); + setMapsMenu.add(saveMapThree); + setMapsMenu.add(saveMapFour); + setMapsMenu.add(saveMapFive); + menuBar.add(setMapsMenu); // *************************************** // Add a menu item for comm port selection @@ -203,7 +225,7 @@ public class JutecGUI extends JFrame implements ActionListener,GetMapFromUtecLis bottomPanel = new BottomUtecControl(); - this.topTabbedPane.add("Graph Data", new RealTimeData()); + this.topTabbedPane.add("Dashboard", new RealTimeData()); this.topTabbedPane.add("Timing Data", new MapJPanel(MapJPanel.TIMINGMAP)); this.topTabbedPane.add("Fuel Data", new MapJPanel(MapJPanel.FUELMAP)); this.topTabbedPane.add("Boost Data", new MapJPanel(MapJPanel.BOOSTMAP)); @@ -326,7 +348,31 @@ public class JutecGUI extends JFrame implements ActionListener,GetMapFromUtecLis System.out.println("Starting to get map 5"); UtecInterface.getMap(5, this); } - + + else if (cmd.equals("Save To Map #1")) { + System.out.println("Starting to save map #1"); + UtecInterface.uploadMap(1, DataManager.getCurrentMapData()); + } + + else if (cmd.equals("Save To Map #2")) { + System.out.println("Starting to save map #2"); + UtecInterface.uploadMap(2, DataManager.getCurrentMapData()); + } + + else if (cmd.equals("Save To Map #3")) { + System.out.println("Starting to save map #3"); + UtecInterface.uploadMap(3, DataManager.getCurrentMapData()); + } + + else if (cmd.equals("Save To Map #4")) { + System.out.println("Starting to save map #4"); + UtecInterface.uploadMap(4, DataManager.getCurrentMapData()); + } + + else if (cmd.equals("Save To Map #5")) { + System.out.println("Starting to save map #5"); + UtecInterface.uploadMap(5, DataManager.getCurrentMapData()); + } else if (cmd.equals("Exit")) { // Use interface to finally close the connection to the Utec UtecInterface.closeConnection(); @@ -407,7 +453,7 @@ public class JutecGUI extends JFrame implements ActionListener,GetMapFromUtecLis System.out.println("Key Code entered:"+charCodeInt); //Pass along command to the UTEC - UtecInterface.sendDataToUtec(charCodeInt); + UtecInterface.sendCommandToUtec(charCodeInt); } // Empty out the text field diff --git a/src/enginuity/logger/utec/gui/mapTabs/DataManager.java b/src/enginuity/logger/utec/gui/mapTabs/DataManager.java index 0b68c668..22db62b2 100644 --- a/src/enginuity/logger/utec/gui/mapTabs/DataManager.java +++ b/src/enginuity/logger/utec/gui/mapTabs/DataManager.java @@ -36,14 +36,25 @@ public class DataManager { } public static void setFuelMapValue(int row, int col, double value){ - currentMapData.setFuelMapValue(row, col, value); + if(currentMapData != null){ + currentMapData.setFuelMapValue(row, col, value); + } } public static void setBoostMapValue(int row, int col, double value){ - currentMapData.setBoostMapValue(row, col, value); + if(currentMapData != null){ + currentMapData.setBoostMapValue(row, col, value); + } } public static void setTimingMapValue(int row, int col, double value){ - currentMapData.setTimingMapValue(row, col, value); + if(currentMapData != null){ + currentMapData.setTimingMapValue(row, col, value); + } + } + + + public static UtecMapData getCurrentMapData() { + return currentMapData; } } diff --git a/src/enginuity/logger/utec/gui/realtimeData/RealTimeData.java b/src/enginuity/logger/utec/gui/realtimeData/RealTimeData.java index 295766f2..8acbac62 100755 --- a/src/enginuity/logger/utec/gui/realtimeData/RealTimeData.java +++ b/src/enginuity/logger/utec/gui/realtimeData/RealTimeData.java @@ -5,7 +5,8 @@ import java.awt.geom.*; import javax.swing.*; import enginuity.logger.utec.gui.bottomControl.*; -import enginuity.tts.VoiceThread; +import enginuity.logger.utec.properties.UtecProperties; +import enginuity.tts.SpeakString; import enginuity.logger.utec.commEvent.*; import enginuity.logger.utec.commInterface.UtecInterface; @@ -16,18 +17,8 @@ import enginuity.logger.utec.commInterface.UtecInterface; */ 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}; + public double[] doubleData = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //Graph Constants private double maxHeight = 370; @@ -35,6 +26,11 @@ public class RealTimeData extends JComponent implements CommListener{ //Window Constants private int windowHeight = 400; + // Needed data + String[] indexes = UtecProperties.getProperties("utec.loggerIndexes"); + String[] titles = UtecProperties.getProperties("utec.loggerTitles"); + String[] dataRanges = UtecProperties.getProperties("utec.loggerDataRanges"); + //Constructor public RealTimeData() { UtecInterface.addListener(this); @@ -56,10 +52,10 @@ public class RealTimeData extends JComponent implements CommListener{ Font font = new Font("Serif", Font.PLAIN, 20); g2.setFont(font); - //RPM - double max1 = 7500; - double min1 = 0; - double value1 = doubleData[0]; + // 0 + double max1 = (minAndMax(dataRanges[0]))[1]; + double min1 = (minAndMax(dataRanges[0]))[0]; + double value1 = doubleData[Integer.parseInt(indexes[0])]; double height1 = ((value1 - min1)/(max1 - min1))*maxHeight; double yValue1 = 5 + (maxHeight - height1); double xValueLeft1 = 30; @@ -69,14 +65,14 @@ public class RealTimeData extends JComponent implements CommListener{ g2.fill(rect1); g2.setPaint(Color.BLACK); g2.draw(rect1); - g2.drawString("RPM:"+(int)value1, (int)xValueLeft1, windowHeight); + g2.drawString(titles[0]+":"+(int)value1, (int)xValueLeft1, windowHeight); - //PSI - double max2 = 20; - double min2 = -14.7; - double value2 = doubleData[1]; + // 1 + double max2 = (minAndMax(dataRanges[1]))[1]; + double min2 = (minAndMax(dataRanges[1]))[0]; + double value2 = doubleData[Integer.parseInt(indexes[1])]; if(value2 > 18.5){ - VoiceThread vc = new VoiceThread("Max P S I,"+value2); + SpeakString vc = new SpeakString("Max P S I,"+value2); vc.start(); } double height2 = ((value2 - min2)/(max2 - min2))*maxHeight; @@ -88,14 +84,14 @@ public class RealTimeData extends JComponent implements CommListener{ g2.fill(rect2); g2.setPaint(Color.BLACK); g2.draw(rect2); - g2.drawString("PSI:"+value2, (int)xValueLeft2, windowHeight); + g2.drawString(titles[1]+":"+value2, (int)xValueLeft2, windowHeight); - //KNOCK - double max3 = 20; - double min3 = 0; - double value3 = doubleData[2]; + // 2 + double max3 = (minAndMax(dataRanges[2]))[1]; + double min3 = (minAndMax(dataRanges[2]))[0]; + double value3 = doubleData[Integer.parseInt(indexes[2])]; if(value3 > 0){ - VoiceThread vc = new VoiceThread("knock, count "+(int)value3); + SpeakString vc = new SpeakString("knock, count "+(int)value3); vc.start(); } double height3 = ((value3 - min3)/(max3 - min3))*maxHeight; @@ -107,12 +103,12 @@ public class RealTimeData extends JComponent implements CommListener{ g2.fill(rect3); g2.setPaint(Color.BLACK); g2.draw(rect3); - g2.drawString("KNOCK:"+(int)value3, (int)xValueLeft3, windowHeight); + g2.drawString(titles[2]+":"+(int)value3, (int)xValueLeft3, windowHeight); - //IGN - double max4 = 80; - double min4 = 0; - double value4 = doubleData[3]; + // 3 + double max4 = (minAndMax(dataRanges[3]))[1]; + double min4 = (minAndMax(dataRanges[3]))[0]; + double value4 = doubleData[Integer.parseInt(indexes[3])]; double height4 = ((value4 - min4)/(max4 - min4))*maxHeight; double yValue4 = 5 + (maxHeight - height4); double xValueLeft4 = 400; @@ -122,14 +118,14 @@ public class RealTimeData extends JComponent implements CommListener{ g2.fill(rect4); g2.setPaint(Color.BLACK); g2.draw(rect4); - g2.drawString("IGN:"+value4, (int)xValueLeft4, windowHeight); + g2.drawString(titles[3]+":"+value4, (int)xValueLeft4, windowHeight); - //DUTY - double max5 = 105; - double min5 = 0; - double value5 = doubleData[4]; + // 4 + double max5 = (minAndMax(dataRanges[4]))[1]; + double min5 = (minAndMax(dataRanges[4]))[0]; + double value5 = doubleData[Integer.parseInt(indexes[4])]; if(value5 > 98){ - VoiceThread vc = new VoiceThread("Max duty "+value5); + SpeakString vc = new SpeakString("Max duty "+value5); vc.start(); } double height5 = ((value5 - min5)/(max5 - min5))*maxHeight; @@ -141,12 +137,12 @@ public class RealTimeData extends JComponent implements CommListener{ g2.fill(rect5); g2.setPaint(Color.BLACK); g2.draw(rect5); - g2.drawString("DUTY:"+value5, (int)xValueLeft5, windowHeight); + g2.drawString(titles[4]+":"+value5, (int)xValueLeft5, windowHeight); - //AFR - double max6 = 26; - double min6 = 0; - double value6 = doubleData[5]; + // 5 + double max6 = (minAndMax(dataRanges[5]))[1]; + double min6 = (minAndMax(dataRanges[5]))[0]; + double value6 = doubleData[Integer.parseInt(indexes[5])]; double height6 = ((value6 - min6)/(max6 - min6))*maxHeight; double yValue6 = 5 + (maxHeight - height6); double xValueLeft6 = 660; @@ -156,15 +152,24 @@ public class RealTimeData extends JComponent implements CommListener{ g2.fill(rect6); g2.setPaint(Color.BLACK); g2.draw(rect6); - g2.drawString("AFR:"+value6, (int)xValueLeft6, windowHeight); + g2.drawString(titles[5]+":"+value6, (int)xValueLeft6, windowHeight); } public void getCommEvent(CommEvent e){ if(e.isLoggerData()){ - stringData = e.getData(); doubleData = e.getDoubleData(); this.repaint(); } } + + private double[] minAndMax(String value){ + String[] temp = value.split("<>"); + + double[] values = new double[2]; + values[0] = Double.parseDouble(temp[0]); + values[1] = Double.parseDouble(temp[1]); + + return values; + } } diff --git a/src/enginuity/logger/utec/properties/UtecProperties.java b/src/enginuity/logger/utec/properties/UtecProperties.java new file mode 100644 index 00000000..8a45856f --- /dev/null +++ b/src/enginuity/logger/utec/properties/UtecProperties.java @@ -0,0 +1,39 @@ +package enginuity.logger.utec.properties; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Properties; + +public class UtecProperties { + private static Properties properties = new Properties(); + + private static boolean init = false; + + public static String[] getProperties(String name){ + if(init == false){ + init(); + } + + + String propertyString = properties.getProperty(name); + String[] values = propertyString.split(","); + + + return values; + } + + private static void init(){ + try { + properties.load(new FileInputStream("utec/utec.properties")); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + init = true; + } +} diff --git a/src/enginuity/tts/VoiceThread.java b/src/enginuity/tts/SpeakString.java similarity index 57% rename from src/enginuity/tts/VoiceThread.java rename to src/enginuity/tts/SpeakString.java index 1c9d57ca..5b6da488 100755 --- a/src/enginuity/tts/VoiceThread.java +++ b/src/enginuity/tts/SpeakString.java @@ -6,22 +6,33 @@ */ package enginuity.tts; +import enginuity.logger.utec.properties.UtecProperties; + /** * @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{ +public class SpeakString extends Thread{ private String message = null; - public VoiceThread(String message){ + public SpeakString(String message){ this.message = message; - + this.speakNow(); } public void run(){ SpeakKnock.speakString(message); } + + public void speakNow(){ + String[] toSpeak = UtecProperties.getProperties("utec.sound"); + boolean parsedBoolean = Boolean.parseBoolean(toSpeak[0]); + if(parsedBoolean){ + this.start(); + } + + } } diff --git a/utec/utec.properties b/utec/utec.properties new file mode 100644 index 00000000..2b252f0b --- /dev/null +++ b/utec/utec.properties @@ -0,0 +1,10 @@ +utec.sound=false +utec.dataTransmissionPauseMS=100 +utec.afrIndex=13 +utec.startLogging=33 +utec.startMapDownload=101,*,19,19,* +utec.startMapUpload=101,*,21,13,*,13 +utec.resetUtec=24,24,24 +utec.loggerIndexes=0,1,5,6,7,13 +utec.loggerTitles=RPM,PSI,KNOCK,IGN,DUTY,AFR +utec.loggerDataRanges=0<>7500,-14.7<>26,0<>10,0<>80,0<>110,0<>26 \ No newline at end of file