Commit 04949080a2f0b0a011ef7fed836633595bee306a

Authored by pfrison
1 parent 53915f04

PercTeacher stable + RxTx installation guide

Showing 28 changed files with 395 additions and 34 deletions   Show diff stats
PercTeacher/Binaires/PercTeacher.jar 0 → 100644
No preview for this file type
PercTeacher/Librairies/Linux/i686-unknown-linux-gnu/librxtxParallel.so 0 → 100644
No preview for this file type
PercTeacher/Librairies/Linux/i686-unknown-linux-gnu/librxtxSerial.so 0 → 100644
No preview for this file type
PercTeacher/Librairies/Linux/ia64-unkown-linux-gnu/librxtxSerial.so 0 → 100644
No preview for this file type
PercTeacher/Librairies/Linux/x86_64-unknown-linux-gnu/librxtxSerial.so 0 → 100644
No preview for this file type
PercTeacher/Librairies/Mac_OS_X/README 0 → 100644
@@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
  1 +Wed Mar 1 12:05:10 MST 2006
  2 +We forgot to update the Mac OS X binary. Previously, it was an old version
  3 +(RXTX-2.1-7pre20). This has now been corrected.
  4 +
PercTeacher/Librairies/Mac_OS_X/librxtxSerial.jnilib 0 → 100644
No preview for this file type
PercTeacher/Librairies/RXTXcomm.jar 0 → 100644
No preview for this file type
PercTeacher/Librairies/Solaris/sparc-solaris/sparc32-sun-solaris2.8/librxtxSerial-2.1-7.so 0 → 100644
No preview for this file type
PercTeacher/Librairies/Solaris/sparc-solaris/sparc32-sun-solaris2.8/librxtxSerial.so 0 → 100644
No preview for this file type
PercTeacher/Librairies/Solaris/sparc-solaris/sparc64-sun-solaris2.8/librxtxSerial-2.1-7.so 0 → 100644
No preview for this file type
PercTeacher/Librairies/Solaris/sparc-solaris/sparc64-sun-solaris2.8/librxtxSerial.so 0 → 100644
No preview for this file type
PercTeacher/Librairies/Windows/i368-mingw32/README 0 → 100644
@@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
  1 +Wed Mar 1 12:01:05 MST 2006
  2 +rxtxSerial.dll had to be recomopiled to link in missing native methods.
  3 +
PercTeacher/Librairies/Windows/i368-mingw32/rxtxParallel.dll 0 → 100644
No preview for this file type
PercTeacher/Librairies/Windows/i368-mingw32/rxtxSerial.dll 0 → 100644
No preview for this file type
PercTeacher/RxTx INSTALL GUIDE 0 → 100644
@@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
  1 +Trent Here. I do those ugly brown pages at rxtx.org. Documentation is not
  2 +what I do well :) So please help me when you see problems or something is
  3 +confusing.
  4 +
  5 +For more information provided by end users please visit the rxtx wiki at
  6 +http://rxtx.qbang.org/wiki. This is also where you can help.
  7 +
  8 +Short Install Instructions
  9 +
  10 +Windows
  11 +
  12 +RXTXcomm.jar goes in \jre\lib\ext (under java)
  13 +rxtxSerial.dll goes in \jre\bin
  14 +
  15 +Mac OS X (x86 and ppc) (there is an Installer with the source)
  16 +
  17 +RXTXcomm.jar goes in /Library/Java/Extensions
  18 +librxtxSerial.jnilib goes in /Library/Java/Extensions
  19 +Run fixperm.sh thats in the directory. Fix perms is in the Mac_OS_X
  20 +subdirectory.
  21 +
  22 +Linux (only x86, x86_64, ia64 here but more in the ToyBox)
  23 +
  24 +RXTXcomm.jar goes in /jre/lib/ext (under java)
  25 +librxtxSerial.so goes in /jre/lib/[machine type] (i386 for instance)
  26 +Make sure the user is in group lock or uucp so lockfiles work.
  27 +
  28 +Solaris (sparc only so far)
  29 +
  30 +RXTXcomm.jar goes in /jre/lib/ext (under java)
  31 +librxtxSerial.so goes in /jre/lib/[machine type]
  32 +Make sure the user is in group uucp so lockfiles work.
  33 +
  34 +
  35 +
  36 +
  37 +A person is added to group lock or uucp by editing /etc/groups. Distributions
  38 +have various tools but this works:
  39 +
  40 +lock:x:54: becomes:
  41 +lock:x:53:jarvi,taj
  42 +
  43 +Now jarvi and taj are in group lock.
  44 +
  45 +Also make sure jarvi and taj have read and write permissions on the port.
  46 +
  47 +
  48 +
  49 +
  50 +If there are problems please help each other on the wiki and ask questions
  51 +on the mail-list. User contributed changes will be used here in the next
  52 +release. If you don't like the documentation, you can improve it.
  53 +
  54 +
  55 +--
  56 +Trent Jarvi
  57 +tjarvi@qbang.org
PercTeacher/Sources/Action.java
@@ -5,19 +5,19 @@ public class Action { @@ -5,19 +5,19 @@ public class Action {
5 5
6 private boolean endAction = true; 6 private boolean endAction = true;
7 7
8 - private long deltaL = 0;  
9 - private long deltaR = 0; 8 + private int deltaL = 0;
  9 + private int deltaR = 0;
10 10
11 private long delaiL = DELAI_DEFAULT; // in us 11 private long delaiL = DELAI_DEFAULT; // in us
12 private long delaiR = DELAI_DEFAULT; // in us 12 private long delaiR = DELAI_DEFAULT; // in us
13 13
14 public Action() {} 14 public Action() {}
15 - public Action(long deltaL, long deltaR) { 15 + public Action(int deltaL, int deltaR) {
16 this.deltaL = deltaL; 16 this.deltaL = deltaL;
17 this.deltaR = deltaR; 17 this.deltaR = deltaR;
18 this.endAction = false; 18 this.endAction = false;
19 } 19 }
20 - public Action(long deltaL, long deltaR, long delaiL, long delaiR) { 20 + public Action(int deltaL, int deltaR, long delaiL, long delaiR) {
21 this.deltaL = deltaL; 21 this.deltaL = deltaL;
22 this.deltaR = deltaR; 22 this.deltaR = deltaR;
23 this.delaiL = delaiL; 23 this.delaiL = delaiL;
@@ -25,12 +25,12 @@ public class Action { @@ -25,12 +25,12 @@ public class Action {
25 this.endAction = false; 25 this.endAction = false;
26 } 26 }
27 27
28 - public void addDeltaL(long amount){this.deltaL += amount; endAction = false;}  
29 - public void addDeltaR(long amount){this.deltaR += amount; endAction = false;}  
30 - public void setDeltaL(long amount){this.deltaL = amount; endAction = false;}  
31 - public void setDeltaR(long amount){this.deltaR = amount; endAction = false;}  
32 - public long getDeltaL(){return this.deltaL;}  
33 - public long getDeltaR(){return this.deltaR;} 28 + public void addDeltaL(int amount){this.deltaL += amount; endAction = false;}
  29 + public void addDeltaR(int amount){this.deltaR += amount; endAction = false;}
  30 + public void setDeltaL(int amount){this.deltaL = amount; endAction = false;}
  31 + public void setDeltaR(int amount){this.deltaR = amount; endAction = false;}
  32 + public int getDeltaL(){return this.deltaL;}
  33 + public int getDeltaR(){return this.deltaR;}
34 34
35 public void setDelaiL(long delai){this.delaiL = delai; endAction = false;} 35 public void setDelaiL(long delai){this.delaiL = delai; endAction = false;}
36 public void setDelaiR(long delai){this.delaiR = delai; endAction = false;} 36 public void setDelaiR(long delai){this.delaiR = delai; endAction = false;}
@@ -73,7 +73,7 @@ public class Action { @@ -73,7 +73,7 @@ public class Action {
73 if(deltaL > 0) 73 if(deltaL > 0)
74 return "Going forward for " + String.valueOf(deltaL) + " steps during " + String.valueOf((double) (deltaL * delaiL) / 1000d) + " miliseconds"; 74 return "Going forward for " + String.valueOf(deltaL) + " steps during " + String.valueOf((double) (deltaL * delaiL) / 1000d) + " miliseconds";
75 else 75 else
76 - return "Going backward for " + String.valueOf(-deltaL) + " steps during " + String.valueOf((double) (deltaL * delaiL) / 1000d) + " miliseconds"; 76 + return "Going backward for " + String.valueOf(-deltaL) + " steps during " + String.valueOf((double) (-deltaL * delaiL) / 1000d) + " miliseconds";
77 } if(deltaR == -deltaL) { 77 } if(deltaR == -deltaL) {
78 if(deltaL > 0) 78 if(deltaL > 0)
79 return "Turning on the spot clockwise for " + String.valueOf(deltaL) + " steps during " 79 return "Turning on the spot clockwise for " + String.valueOf(deltaL) + " steps during "
PercTeacher/Sources/ActionList.java
@@ -2,12 +2,14 @@ import java.util.ArrayList; @@ -2,12 +2,14 @@ import java.util.ArrayList;
2 2
3 public class ActionList { 3 public class ActionList {
4 private ArrayList<Action> actions; 4 private ArrayList<Action> actions;
  5 + private SerialCom serialCom;
5 6
6 - public ActionList() { 7 + public ActionList(SerialCom serialCom) {
  8 + this.serialCom = serialCom;
7 actions = new ArrayList<>(); 9 actions = new ArrayList<>();
8 actions.add(new Action()); 10 actions.add(new Action());
9 } 11 }
10 - public ActionList(long[] leftDeltaArray, long[] rightDeltaArray, long[] leftDelaiArray, long[] rightDelaiArray) { 12 + public ActionList(int[] leftDeltaArray, int[] rightDeltaArray, long[] leftDelaiArray, long[] rightDelaiArray) {
11 if(leftDelaiArray.length != rightDelaiArray.length 13 if(leftDelaiArray.length != rightDelaiArray.length
12 || leftDelaiArray.length != leftDelaiArray.length 14 || leftDelaiArray.length != leftDelaiArray.length
13 || leftDelaiArray.length != rightDelaiArray.length) 15 || leftDelaiArray.length != rightDelaiArray.length)
@@ -18,7 +20,7 @@ public class ActionList { @@ -18,7 +20,7 @@ public class ActionList {
18 actions.add(new Action()); 20 actions.add(new Action());
19 } 21 }
20 22
21 - public void addToActionList(int i, int j, long step) { 23 + public void addToActionList(int i, int j, int step) {
22 switch (j * 10 + i) { 24 switch (j * 10 + i) {
23 case 00: //ACTION_LEFT_PLUS; 25 case 00: //ACTION_LEFT_PLUS;
24 addToLastAction(step, 0); 26 addToLastAction(step, 0);
@@ -62,30 +64,38 @@ public class ActionList { @@ -62,30 +64,38 @@ public class ActionList {
62 completeAction(); 64 completeAction();
63 } 65 }
64 66
65 - private void addToLastAction(long deltaL, long deltaR) { 67 + private void addToLastAction(int deltaL, int deltaR) {
66 actions.get(actions.size() - 1).addDeltaL(deltaL); 68 actions.get(actions.size() - 1).addDeltaL(deltaL);
67 actions.get(actions.size() - 1).addDeltaR(deltaR); 69 actions.get(actions.size() - 1).addDeltaR(deltaR);
  70 + SerialCommands.sendDeltas(serialCom, deltaL, deltaR);
68 } 71 }
69 72
70 public void revertLastAction() { 73 public void revertLastAction() {
71 if(actions.size() <= 0) 74 if(actions.size() <= 0)
72 return; 75 return;
  76 +
  77 + Action toRevert = null;
73 if(actions.get(actions.size() - 1).isEmpty()) { 78 if(actions.get(actions.size() - 1).isEmpty()) {
74 actions.remove(actions.size() - 1); 79 actions.remove(actions.size() - 1);
75 - if(actions.size() != 0) 80 + if(actions.size() != 0) {
  81 + toRevert = actions.get(actions.size() - 1);
76 actions.set(actions.size() - 1, new Action()); 82 actions.set(actions.size() - 1, new Action());
  83 + }
77 else 84 else
78 actions.add(new Action()); 85 actions.add(new Action());
79 } else { 86 } else {
  87 + toRevert = actions.get(actions.size() - 1);
80 actions.set(actions.size() - 1, new Action()); 88 actions.set(actions.size() - 1, new Action());
81 } 89 }
  90 + if(toRevert != null)
  91 + SerialCommands.sendDeltas(serialCom, -toRevert.getDeltaL(), -toRevert.getDeltaR());
82 } 92 }
83 93
84 public String getLeftDeltaArray() { 94 public String getLeftDeltaArray() {
85 String str = "{"; 95 String str = "{";
86 for(Action action : actions) { 96 for(Action action : actions) {
87 if(!action.isEmpty()) 97 if(!action.isEmpty())
88 - str += String.valueOf(action.getDeltaL()) + "L, "; 98 + str += String.valueOf(action.getDeltaL()) + ", ";
89 } 99 }
90 str = str.substring(0, str.length() - 2) + "}"; 100 str = str.substring(0, str.length() - 2) + "}";
91 return str; 101 return str;
@@ -94,7 +104,7 @@ public class ActionList { @@ -94,7 +104,7 @@ public class ActionList {
94 String str = "{"; 104 String str = "{";
95 for(Action action : actions) { 105 for(Action action : actions) {
96 if(!action.isEmpty()) 106 if(!action.isEmpty())
97 - str += String.valueOf(action.getDeltaR()) + "L, "; 107 + str += String.valueOf(action.getDeltaR()) + ", ";
98 } 108 }
99 str = str.substring(0, str.length() - 2) + "}"; 109 str = str.substring(0, str.length() - 2) + "}";
100 return str; 110 return str;
PercTeacher/Sources/ImportExport.java
@@ -55,10 +55,18 @@ public class ImportExport { @@ -55,10 +55,18 @@ public class ImportExport {
55 try { 55 try {
56 byte[] encoded = Files.readAllBytes(Paths.get(path)); 56 byte[] encoded = Files.readAllBytes(Paths.get(path));
57 String str = new String(encoded, Charset.defaultCharset()); 57 String str = new String(encoded, Charset.defaultCharset());
  58 +
58 long[][] longList = Util.getArraysFromImport(str); 59 long[][] longList = Util.getArraysFromImport(str);
59 - if(longList != null)  
60 - return new ActionList(longList[0], longList[1], longList[2], longList[3]);  
61 - JOptionPane.showMessageDialog(null, "The choosen file is invalid or currupted", "Import error", JOptionPane.ERROR_MESSAGE); 60 + if(longList == null) {
  61 + JOptionPane.showMessageDialog(null, "The choosen file is invalid or currupted", "Import error", JOptionPane.ERROR_MESSAGE);
  62 + return null;
  63 + }
  64 + int[][] intList = new int[2][longList[0].length];
  65 + for(int i=0; i<2; i++)
  66 + for(int j=0; j<longList[0].length; j++)
  67 + intList[i][j] = (int) longList[i][j];
  68 +
  69 + return new ActionList(intList[0], intList[1], longList[2], longList[3]);
62 } catch (IOException ignored) {} 70 } catch (IOException ignored) {}
63 return null; 71 return null;
64 } 72 }
PercTeacher/Sources/Interface.java
@@ -11,6 +11,8 @@ import java.awt.event.ActionListener; @@ -11,6 +11,8 @@ import java.awt.event.ActionListener;
11 import java.awt.event.FocusEvent; 11 import java.awt.event.FocusEvent;
12 import java.awt.event.FocusListener; 12 import java.awt.event.FocusListener;
13 import java.awt.event.KeyEvent; 13 import java.awt.event.KeyEvent;
  14 +import java.awt.event.WindowAdapter;
  15 +import java.awt.event.WindowEvent;
14 16
15 import javax.swing.BorderFactory; 17 import javax.swing.BorderFactory;
16 import javax.swing.BoxLayout; 18 import javax.swing.BoxLayout;
@@ -44,15 +46,26 @@ public class Interface extends JFrame implements ActionListener, FocusListener { @@ -44,15 +46,26 @@ public class Interface extends JFrame implements ActionListener, FocusListener {
44 46
45 private ActionList actionList; 47 private ActionList actionList;
46 48
47 - public Interface(ActionList actionList) { 49 + public Interface(ActionList actionList, final Runnable executeOnClose) {
48 super("PercTeacher"); 50 super("PercTeacher");
49 this.actionList = actionList; 51 this.actionList = actionList;
50 setResizable(false); 52 setResizable(false);
51 populateWindow(); 53 populateWindow();
52 pack(); 54 pack();
53 setLocationRelativeTo(null); // center window 55 setLocationRelativeTo(null); // center window
54 - KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new CustomDispatcher()); 56 +
  57 + KeyboardFocusManager.getCurrentKeyboardFocusManager()
  58 + .addKeyEventDispatcher(new InterfaceKeyboardDispatcher());
55 getContentPane().requestFocusInWindow(); 59 getContentPane().requestFocusInWindow();
  60 +
  61 + addWindowListener(new WindowAdapter() {
  62 + @Override
  63 + public void windowClosing(WindowEvent e) {
  64 + if(executeOnClose != null)
  65 + executeOnClose.run();
  66 + dispose();
  67 + }
  68 + });
56 } 69 }
57 70
58 private void populateWindow() { 71 private void populateWindow() {
@@ -189,7 +202,7 @@ public class Interface extends JFrame implements ActionListener, FocusListener { @@ -189,7 +202,7 @@ public class Interface extends JFrame implements ActionListener, FocusListener {
189 String str = stepsField.getText(); 202 String str = stepsField.getText();
190 try { 203 try {
191 if(str != null && !str.equals("")) { 204 if(str != null && !str.equals("")) {
192 - long step = Long.parseLong(str); 205 + int step = Integer.parseInt(str);
193 actionList.addToActionList(i, j, step); 206 actionList.addToActionList(i, j, step);
194 } 207 }
195 } catch (NumberFormatException ignored) { 208 } catch (NumberFormatException ignored) {
@@ -239,7 +252,7 @@ public class Interface extends JFrame implements ActionListener, FocusListener { @@ -239,7 +252,7 @@ public class Interface extends JFrame implements ActionListener, FocusListener {
239 keyboardWait = false; 252 keyboardWait = false;
240 } 253 }
241 254
242 - private class CustomDispatcher implements KeyEventDispatcher { 255 + private class InterfaceKeyboardDispatcher implements KeyEventDispatcher {
243 @Override 256 @Override
244 public boolean dispatchKeyEvent(KeyEvent e) { 257 public boolean dispatchKeyEvent(KeyEvent e) {
245 if(keyboardWait && Interface.this.getFocusOwner() == stepsField && e.getKeyCode() == KeyEvent.VK_ENTER) { 258 if(keyboardWait && Interface.this.getFocusOwner() == stepsField && e.getKeyCode() == KeyEvent.VK_ENTER) {
PercTeacher/Sources/Main.java
1 -import javax.swing.JFrame; 1 +import javax.swing.JOptionPane;
2 2
3 /* TODO list : 3 /* TODO list :
4 - * - data to send to the arduino : do action, revert action 4 + * - test import export
5 * - textfields to tweak delays (+ button set to default) 5 * - textfields to tweak delays (+ button set to default)
  6 + * - clean Interface class
6 */ 7 */
7 8
8 public class Main { 9 public class Main {
9 - public static void main(String[] args) {  
10 - ActionList actionList = new ActionList(); 10 +
  11 + public static void main(String[] args) throws InterruptedException {
  12 + String serialPort = null;
  13 + try {
  14 + serialPort = SerialPortChooserDialog.showSerialPortChooserDialog();
  15 + } catch (NoSerialPortException e) {
  16 + JOptionPane.showMessageDialog(null, "No serial port available !", "Error", JOptionPane.ERROR_MESSAGE);
  17 + System.exit(-1);
  18 + }
  19 + if(serialPort == null) System.exit(-1);
  20 +
  21 + final SerialCom serialCom = new SerialCom(serialPort);
  22 + // arduino need time before accepting serial data
  23 + Thread.sleep(1000);
11 24
12 - Interface i = new Interface(actionList); 25 + ActionList actionList = new ActionList(serialCom);
  26 + Interface i = new Interface(actionList, new Runnable() {
  27 + @Override
  28 + public void run() {
  29 + serialCom.close();
  30 + }
  31 + });
13 i.setVisible(true); 32 i.setVisible(true);
14 - i.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
15 } 33 }
16 } 34 }
PercTeacher/Sources/NoSerialPortException.java 0 → 100644
@@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
  1 +
  2 +public class NoSerialPortException extends Exception {
  3 + private static final long serialVersionUID = 1L;
  4 +
  5 + public NoSerialPortException() {
  6 + super("No serial port available !");
  7 + }
  8 +}
PercTeacher/Sources/SerialCom.java 0 → 100644
@@ -0,0 +1,82 @@ @@ -0,0 +1,82 @@
  1 +import java.io.IOException;
  2 +import java.io.InputStream;
  3 +import java.io.OutputStream;
  4 +import java.util.Enumeration;
  5 +
  6 +import gnu.io.CommPortIdentifier;
  7 +import gnu.io.PortInUseException;
  8 +import gnu.io.SerialPort;
  9 +import gnu.io.UnsupportedCommOperationException;
  10 +
  11 +public class SerialCom {
  12 + private static final int DATA_RATE = 9600;
  13 + private static final int TIME_OUT = 2000;
  14 + private static final int BUFFER_SIZE = 1024;
  15 +
  16 + private SerialPort serialPort;
  17 + private InputStream input;
  18 + private OutputStream output;
  19 +
  20 + public SerialCom(int portNumberWindows) { this("COM" + String.valueOf(portNumberWindows)); }
  21 + public SerialCom(String portName) {
  22 + CommPortIdentifier portId = null;
  23 + Enumeration<?> portEnum = CommPortIdentifier.getPortIdentifiers();
  24 +
  25 + // Search for serial port
  26 + while (portEnum.hasMoreElements()) {
  27 + CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
  28 + if (currPortId.getName().equals(portName)) {
  29 + portId = currPortId;
  30 + break;
  31 + }
  32 + }
  33 + if (portId == null)
  34 + throw new SerialComPortException(portName);
  35 +
  36 + // open connection
  37 + try {
  38 + serialPort = (SerialPort) portId.open(this.getClass().getName(), TIME_OUT);
  39 + serialPort.setSerialPortParams(DATA_RATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
  40 +
  41 + input = serialPort.getInputStream();
  42 + output = serialPort.getOutputStream();
  43 + } catch (IOException
  44 + | UnsupportedCommOperationException
  45 + | PortInUseException e) {
  46 + throw new SerialComPortException(portName);
  47 + }
  48 + }
  49 +
  50 + public void close() {
  51 + try {
  52 + input.close();
  53 + output.close();
  54 + } catch (IOException e) {
  55 + e.printStackTrace();
  56 + }
  57 + serialPort.removeEventListener();
  58 + serialPort.close();
  59 + }
  60 + public void send(byte[] bytes) {
  61 + try {
  62 + this.output.write(bytes);
  63 + } catch (IOException e) {
  64 + e.printStackTrace();
  65 + }
  66 + }
  67 +
  68 + public byte[] recieve() {
  69 + byte[] buffer = new byte[BUFFER_SIZE];
  70 + int len = -1;
  71 +
  72 + try { len = this.input.read(buffer); }
  73 + catch (IOException e) { return null; }
  74 +
  75 + if(len == -1 || len == 0)
  76 + return null;
  77 + byte[] data = new byte[len];
  78 + for(int i=0; i<len; i++)
  79 + data[i] = buffer[i];
  80 + return data;
  81 + }
  82 +}
PercTeacher/Sources/SerialComPortException.java 0 → 100644
@@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
  1 +
  2 +public class SerialComPortException extends RuntimeException {
  3 + private static final long serialVersionUID = 1L;
  4 +
  5 + public SerialComPortException(String portName) {
  6 + super("Connection to port " + portName + " failed !");
  7 + }
  8 +}
PercTeacher/Sources/SerialComWrongCallbackMethod.java 0 → 100644
@@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
  1 +
  2 +public class SerialComWrongCallbackMethod extends RuntimeException {
  3 + private static final long serialVersionUID = 1L;
  4 +
  5 + public SerialComWrongCallbackMethod() {
  6 + super("Wrong callback method format !");
  7 + }
  8 +}
PercTeacher/Sources/SerialCommands.java 0 → 100644
@@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
  1 +
  2 +public class SerialCommands {
  3 + public static void sendDeltas(SerialCom serialCom, int deltaLeft, int deltaRight) {
  4 + byte dataL1 = (byte) ((deltaLeft & 0xFF00) >> 8);
  5 + byte dataL2 = (byte) (deltaLeft & 0xFF);
  6 + byte dataR1 = (byte) ((deltaRight & 0xFF00) >> 8);
  7 + byte dataR2 = (byte) (deltaRight & 0xFF);
  8 + byte[] data = new byte[] {dataL1, dataL2, dataR1, dataR2};
  9 + serialCom.send(data);
  10 +
  11 + // wait for a response = move complete
  12 + byte[] bytes = null;
  13 + while(bytes == null
  14 + || bytes.length <= 0) {
  15 + bytes = serialCom.recieve();
  16 + }
  17 + }
  18 +}
PercTeacher/Sources/SerialPortChooserDialog.java 0 → 100644
@@ -0,0 +1,119 @@ @@ -0,0 +1,119 @@
  1 +import java.awt.BorderLayout;
  2 +import java.awt.Dimension;
  3 +import java.awt.FlowLayout;
  4 +import java.awt.event.ActionEvent;
  5 +import java.awt.event.ActionListener;
  6 +import java.util.ArrayList;
  7 +import java.util.Enumeration;
  8 +
  9 +import javax.swing.DefaultListModel;
  10 +import javax.swing.JButton;
  11 +import javax.swing.JDialog;
  12 +import javax.swing.JLabel;
  13 +import javax.swing.JList;
  14 +import javax.swing.JPanel;
  15 +import javax.swing.JScrollPane;
  16 +import javax.swing.ListSelectionModel;
  17 +import javax.swing.event.ListSelectionEvent;
  18 +import javax.swing.event.ListSelectionListener;
  19 +
  20 +import gnu.io.CommPortIdentifier;
  21 +
  22 +public class SerialPortChooserDialog extends JDialog implements ActionListener, ListSelectionListener {
  23 + private static final long serialVersionUID = 1L;
  24 +
  25 + private boolean onlyOneChoice;
  26 + private boolean emptyChoice;
  27 + private ArrayList<String> portNames;
  28 + private String choosedPort = null;
  29 +
  30 + private JList<String> list;
  31 + private JButton ok;
  32 + private JButton cancel;
  33 +
  34 + private SerialPortChooserDialog() {
  35 + Enumeration<?> portEnum = CommPortIdentifier.getPortIdentifiers();
  36 + portNames = new ArrayList<>();
  37 +
  38 + while (portEnum.hasMoreElements()) {
  39 + CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
  40 + portNames.add(currPortId.getName());
  41 + }
  42 +
  43 + onlyOneChoice = portNames.size() <= 1;
  44 + emptyChoice = portNames.size() == 0;
  45 + if(onlyOneChoice || emptyChoice)
  46 + return;
  47 +
  48 + // JDialog creation
  49 + JPanel mainPanel = new JPanel(new BorderLayout());
  50 + setModal(true);
  51 + setTitle("Serial port chooser");
  52 +
  53 + // title
  54 + mainPanel.add(new JLabel("Choose a serial port : "), BorderLayout.NORTH);
  55 +
  56 + // list ports
  57 + DefaultListModel<String> listModel = new DefaultListModel<>();
  58 + for(String str : portNames)
  59 + listModel.addElement(str);
  60 + list = new JList<>(listModel);
  61 + list.addListSelectionListener(this);
  62 + list.setVisibleRowCount(3);
  63 + list.setLayoutOrientation(JList.VERTICAL);
  64 + list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  65 +
  66 + JScrollPane scrollPane = new JScrollPane(list, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  67 + scrollPane.setPreferredSize(new Dimension(200, 100));
  68 + mainPanel.add(scrollPane, BorderLayout.CENTER);
  69 +
  70 + // buttons ok / cancel
  71 + JPanel borderLayoutPanel = new JPanel(new BorderLayout());
  72 + JPanel buttonsLayout = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 3));
  73 + ok = new JButton("Ok");
  74 + cancel = new JButton("Cancel");
  75 + ok.addActionListener(this);
  76 + cancel.addActionListener(this);
  77 + ok.setEnabled(false);
  78 + buttonsLayout.add(cancel);
  79 + buttonsLayout.add(ok);
  80 + borderLayoutPanel.add(buttonsLayout, BorderLayout.EAST);
  81 + mainPanel.add(borderLayoutPanel, BorderLayout.SOUTH);
  82 +
  83 + // padding
  84 + JPanel padding = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
  85 + padding.add(mainPanel);
  86 + add(padding);
  87 +
  88 + setResizable(false);
  89 + pack();
  90 + setLocationRelativeTo(null);
  91 + setVisible(true);
  92 + }
  93 +
  94 + public static String showSerialPortChooserDialog() throws NoSerialPortException {
  95 + SerialPortChooserDialog dialog = new SerialPortChooserDialog();
  96 + if(dialog.emptyChoice)
  97 + throw new NoSerialPortException();
  98 + if(dialog.onlyOneChoice)
  99 + return dialog.portNames.get(0);
  100 + return dialog.choosedPort;
  101 + }
  102 +
  103 + @Override
  104 + public void actionPerformed(ActionEvent e) {
  105 + if(e.getSource() == ok) {
  106 + choosedPort = list.getSelectedValue();
  107 + dispose();
  108 + } else if(e.getSource() == cancel) {
  109 + dispose();
  110 + }
  111 + }
  112 +
  113 + @Override
  114 + public void valueChanged(ListSelectionEvent e) {
  115 + if(e.getSource() == list) {
  116 + ok.setEnabled(list.getSelectedIndex() != -1);
  117 + }
  118 + }
  119 +}
PercTeacher/Sources/Util.java
@@ -7,15 +7,20 @@ public class Util { @@ -7,15 +7,20 @@ public class Util {
7 return null; 7 return null;
8 8
9 for(int i=0; i<arrays.length; i++) { 9 for(int i=0; i<arrays.length; i++) {
10 - arrays[i] = getArrayFromLine(split[i]); 10 + arrays[i] = getArrayFromLine(split[i], i);
11 if(arrays[i] == null) 11 if(arrays[i] == null)
12 return null; 12 return null;
13 } 13 }
14 return arrays; 14 return arrays;
15 } 15 }
16 - private static long[] getArrayFromLine(String str) { 16 + private static long[] getArrayFromLine(String str, int nLine) {
17 str = str.substring(1, str.length() - 2); // remove { and } 17 str = str.substring(1, str.length() - 2); // remove { and }
18 - String[] longsStr = str.split("L, "); 18 + String[] longsStr;
  19 + if(nLine <= 1)
  20 + longsStr = str.split(", ");
  21 + else
  22 + longsStr = str.split("L, ");
  23 +
19 try { 24 try {
20 long[] longs = new long[longsStr.length]; 25 long[] longs = new long[longsStr.length];
21 for(int i=0; i<longs.length; i++) 26 for(int i=0; i<longs.length; i++)