diff --git a/PercTeacher/Binaires/PercTeacher.jar b/PercTeacher/Binaires/PercTeacher.jar new file mode 100644 index 0000000..4712859 Binary files /dev/null and b/PercTeacher/Binaires/PercTeacher.jar differ diff --git a/PercTeacher/Librairies/Linux/i686-unknown-linux-gnu/librxtxParallel.so b/PercTeacher/Librairies/Linux/i686-unknown-linux-gnu/librxtxParallel.so new file mode 100644 index 0000000..476313f Binary files /dev/null and b/PercTeacher/Librairies/Linux/i686-unknown-linux-gnu/librxtxParallel.so differ diff --git a/PercTeacher/Librairies/Linux/i686-unknown-linux-gnu/librxtxSerial.so b/PercTeacher/Librairies/Linux/i686-unknown-linux-gnu/librxtxSerial.so new file mode 100644 index 0000000..e60c5e6 Binary files /dev/null and b/PercTeacher/Librairies/Linux/i686-unknown-linux-gnu/librxtxSerial.so differ diff --git a/PercTeacher/Librairies/Linux/ia64-unkown-linux-gnu/librxtxSerial.so b/PercTeacher/Librairies/Linux/ia64-unkown-linux-gnu/librxtxSerial.so new file mode 100644 index 0000000..916db00 Binary files /dev/null and b/PercTeacher/Librairies/Linux/ia64-unkown-linux-gnu/librxtxSerial.so differ diff --git a/PercTeacher/Librairies/Linux/x86_64-unknown-linux-gnu/librxtxSerial.so b/PercTeacher/Librairies/Linux/x86_64-unknown-linux-gnu/librxtxSerial.so new file mode 100644 index 0000000..eba4e0e Binary files /dev/null and b/PercTeacher/Librairies/Linux/x86_64-unknown-linux-gnu/librxtxSerial.so differ diff --git a/PercTeacher/Librairies/Mac_OS_X/README b/PercTeacher/Librairies/Mac_OS_X/README new file mode 100644 index 0000000..8803841 --- /dev/null +++ b/PercTeacher/Librairies/Mac_OS_X/README @@ -0,0 +1,4 @@ +Wed Mar 1 12:05:10 MST 2006 +We forgot to update the Mac OS X binary. Previously, it was an old version +(RXTX-2.1-7pre20). This has now been corrected. + diff --git a/PercTeacher/Librairies/Mac_OS_X/librxtxSerial.jnilib b/PercTeacher/Librairies/Mac_OS_X/librxtxSerial.jnilib new file mode 100644 index 0000000..2d3f20d Binary files /dev/null and b/PercTeacher/Librairies/Mac_OS_X/librxtxSerial.jnilib differ diff --git a/PercTeacher/Librairies/RXTXcomm.jar b/PercTeacher/Librairies/RXTXcomm.jar new file mode 100644 index 0000000..e1e7503 Binary files /dev/null and b/PercTeacher/Librairies/RXTXcomm.jar differ diff --git a/PercTeacher/Librairies/Solaris/sparc-solaris/sparc32-sun-solaris2.8/librxtxSerial-2.1-7.so b/PercTeacher/Librairies/Solaris/sparc-solaris/sparc32-sun-solaris2.8/librxtxSerial-2.1-7.so new file mode 100644 index 0000000..24d2190 Binary files /dev/null and b/PercTeacher/Librairies/Solaris/sparc-solaris/sparc32-sun-solaris2.8/librxtxSerial-2.1-7.so differ diff --git a/PercTeacher/Librairies/Solaris/sparc-solaris/sparc32-sun-solaris2.8/librxtxSerial.so b/PercTeacher/Librairies/Solaris/sparc-solaris/sparc32-sun-solaris2.8/librxtxSerial.so new file mode 100644 index 0000000..24d2190 Binary files /dev/null and b/PercTeacher/Librairies/Solaris/sparc-solaris/sparc32-sun-solaris2.8/librxtxSerial.so differ diff --git a/PercTeacher/Librairies/Solaris/sparc-solaris/sparc64-sun-solaris2.8/librxtxSerial-2.1-7.so b/PercTeacher/Librairies/Solaris/sparc-solaris/sparc64-sun-solaris2.8/librxtxSerial-2.1-7.so new file mode 100644 index 0000000..e38d78e Binary files /dev/null and b/PercTeacher/Librairies/Solaris/sparc-solaris/sparc64-sun-solaris2.8/librxtxSerial-2.1-7.so differ diff --git a/PercTeacher/Librairies/Solaris/sparc-solaris/sparc64-sun-solaris2.8/librxtxSerial.so b/PercTeacher/Librairies/Solaris/sparc-solaris/sparc64-sun-solaris2.8/librxtxSerial.so new file mode 100644 index 0000000..e38d78e Binary files /dev/null and b/PercTeacher/Librairies/Solaris/sparc-solaris/sparc64-sun-solaris2.8/librxtxSerial.so differ diff --git a/PercTeacher/Librairies/Windows/i368-mingw32/README b/PercTeacher/Librairies/Windows/i368-mingw32/README new file mode 100644 index 0000000..2b2ea6c --- /dev/null +++ b/PercTeacher/Librairies/Windows/i368-mingw32/README @@ -0,0 +1,3 @@ +Wed Mar 1 12:01:05 MST 2006 +rxtxSerial.dll had to be recomopiled to link in missing native methods. + diff --git a/PercTeacher/Librairies/Windows/i368-mingw32/rxtxParallel.dll b/PercTeacher/Librairies/Windows/i368-mingw32/rxtxParallel.dll new file mode 100644 index 0000000..c1bdfce Binary files /dev/null and b/PercTeacher/Librairies/Windows/i368-mingw32/rxtxParallel.dll differ diff --git a/PercTeacher/Librairies/Windows/i368-mingw32/rxtxSerial.dll b/PercTeacher/Librairies/Windows/i368-mingw32/rxtxSerial.dll new file mode 100644 index 0000000..c0e6b58 Binary files /dev/null and b/PercTeacher/Librairies/Windows/i368-mingw32/rxtxSerial.dll differ diff --git a/PercTeacher/RxTx INSTALL GUIDE b/PercTeacher/RxTx INSTALL GUIDE new file mode 100644 index 0000000..6b4c71d --- /dev/null +++ b/PercTeacher/RxTx INSTALL GUIDE @@ -0,0 +1,57 @@ +Trent Here. I do those ugly brown pages at rxtx.org. Documentation is not +what I do well :) So please help me when you see problems or something is +confusing. + +For more information provided by end users please visit the rxtx wiki at +http://rxtx.qbang.org/wiki. This is also where you can help. + +Short Install Instructions + +Windows + +RXTXcomm.jar goes in \jre\lib\ext (under java) +rxtxSerial.dll goes in \jre\bin + +Mac OS X (x86 and ppc) (there is an Installer with the source) + +RXTXcomm.jar goes in /Library/Java/Extensions +librxtxSerial.jnilib goes in /Library/Java/Extensions +Run fixperm.sh thats in the directory. Fix perms is in the Mac_OS_X +subdirectory. + +Linux (only x86, x86_64, ia64 here but more in the ToyBox) + +RXTXcomm.jar goes in /jre/lib/ext (under java) +librxtxSerial.so goes in /jre/lib/[machine type] (i386 for instance) +Make sure the user is in group lock or uucp so lockfiles work. + +Solaris (sparc only so far) + +RXTXcomm.jar goes in /jre/lib/ext (under java) +librxtxSerial.so goes in /jre/lib/[machine type] +Make sure the user is in group uucp so lockfiles work. + + + + +A person is added to group lock or uucp by editing /etc/groups. Distributions +have various tools but this works: + +lock:x:54: becomes: +lock:x:53:jarvi,taj + +Now jarvi and taj are in group lock. + +Also make sure jarvi and taj have read and write permissions on the port. + + + + +If there are problems please help each other on the wiki and ask questions +on the mail-list. User contributed changes will be used here in the next +release. If you don't like the documentation, you can improve it. + + +-- +Trent Jarvi +tjarvi@qbang.org diff --git a/PercTeacher/Sources/Action.java b/PercTeacher/Sources/Action.java index b7b3455..8b9ce7f 100644 --- a/PercTeacher/Sources/Action.java +++ b/PercTeacher/Sources/Action.java @@ -5,19 +5,19 @@ public class Action { private boolean endAction = true; - private long deltaL = 0; - private long deltaR = 0; + private int deltaL = 0; + private int deltaR = 0; private long delaiL = DELAI_DEFAULT; // in us private long delaiR = DELAI_DEFAULT; // in us public Action() {} - public Action(long deltaL, long deltaR) { + public Action(int deltaL, int deltaR) { this.deltaL = deltaL; this.deltaR = deltaR; this.endAction = false; } - public Action(long deltaL, long deltaR, long delaiL, long delaiR) { + public Action(int deltaL, int deltaR, long delaiL, long delaiR) { this.deltaL = deltaL; this.deltaR = deltaR; this.delaiL = delaiL; @@ -25,12 +25,12 @@ public class Action { this.endAction = false; } - public void addDeltaL(long amount){this.deltaL += amount; endAction = false;} - public void addDeltaR(long amount){this.deltaR += amount; endAction = false;} - public void setDeltaL(long amount){this.deltaL = amount; endAction = false;} - public void setDeltaR(long amount){this.deltaR = amount; endAction = false;} - public long getDeltaL(){return this.deltaL;} - public long getDeltaR(){return this.deltaR;} + public void addDeltaL(int amount){this.deltaL += amount; endAction = false;} + public void addDeltaR(int amount){this.deltaR += amount; endAction = false;} + public void setDeltaL(int amount){this.deltaL = amount; endAction = false;} + public void setDeltaR(int amount){this.deltaR = amount; endAction = false;} + public int getDeltaL(){return this.deltaL;} + public int getDeltaR(){return this.deltaR;} public void setDelaiL(long delai){this.delaiL = delai; endAction = false;} public void setDelaiR(long delai){this.delaiR = delai; endAction = false;} @@ -73,7 +73,7 @@ public class Action { if(deltaL > 0) return "Going forward for " + String.valueOf(deltaL) + " steps during " + String.valueOf((double) (deltaL * delaiL) / 1000d) + " miliseconds"; else - return "Going backward for " + String.valueOf(-deltaL) + " steps during " + String.valueOf((double) (deltaL * delaiL) / 1000d) + " miliseconds"; + return "Going backward for " + String.valueOf(-deltaL) + " steps during " + String.valueOf((double) (-deltaL * delaiL) / 1000d) + " miliseconds"; } if(deltaR == -deltaL) { if(deltaL > 0) return "Turning on the spot clockwise for " + String.valueOf(deltaL) + " steps during " diff --git a/PercTeacher/Sources/ActionList.java b/PercTeacher/Sources/ActionList.java index 3d7393a..d77f68d 100644 --- a/PercTeacher/Sources/ActionList.java +++ b/PercTeacher/Sources/ActionList.java @@ -2,12 +2,14 @@ import java.util.ArrayList; public class ActionList { private ArrayList actions; + private SerialCom serialCom; - public ActionList() { + public ActionList(SerialCom serialCom) { + this.serialCom = serialCom; actions = new ArrayList<>(); actions.add(new Action()); } - public ActionList(long[] leftDeltaArray, long[] rightDeltaArray, long[] leftDelaiArray, long[] rightDelaiArray) { + public ActionList(int[] leftDeltaArray, int[] rightDeltaArray, long[] leftDelaiArray, long[] rightDelaiArray) { if(leftDelaiArray.length != rightDelaiArray.length || leftDelaiArray.length != leftDelaiArray.length || leftDelaiArray.length != rightDelaiArray.length) @@ -18,7 +20,7 @@ public class ActionList { actions.add(new Action()); } - public void addToActionList(int i, int j, long step) { + public void addToActionList(int i, int j, int step) { switch (j * 10 + i) { case 00: //ACTION_LEFT_PLUS; addToLastAction(step, 0); @@ -62,30 +64,38 @@ public class ActionList { completeAction(); } - private void addToLastAction(long deltaL, long deltaR) { + private void addToLastAction(int deltaL, int deltaR) { actions.get(actions.size() - 1).addDeltaL(deltaL); actions.get(actions.size() - 1).addDeltaR(deltaR); + SerialCommands.sendDeltas(serialCom, deltaL, deltaR); } public void revertLastAction() { if(actions.size() <= 0) return; + + Action toRevert = null; if(actions.get(actions.size() - 1).isEmpty()) { actions.remove(actions.size() - 1); - if(actions.size() != 0) + if(actions.size() != 0) { + toRevert = actions.get(actions.size() - 1); actions.set(actions.size() - 1, new Action()); + } else actions.add(new Action()); } else { + toRevert = actions.get(actions.size() - 1); actions.set(actions.size() - 1, new Action()); } + if(toRevert != null) + SerialCommands.sendDeltas(serialCom, -toRevert.getDeltaL(), -toRevert.getDeltaR()); } public String getLeftDeltaArray() { String str = "{"; for(Action action : actions) { if(!action.isEmpty()) - str += String.valueOf(action.getDeltaL()) + "L, "; + str += String.valueOf(action.getDeltaL()) + ", "; } str = str.substring(0, str.length() - 2) + "}"; return str; @@ -94,7 +104,7 @@ public class ActionList { String str = "{"; for(Action action : actions) { if(!action.isEmpty()) - str += String.valueOf(action.getDeltaR()) + "L, "; + str += String.valueOf(action.getDeltaR()) + ", "; } str = str.substring(0, str.length() - 2) + "}"; return str; diff --git a/PercTeacher/Sources/ImportExport.java b/PercTeacher/Sources/ImportExport.java index 9307a66..63928c5 100644 --- a/PercTeacher/Sources/ImportExport.java +++ b/PercTeacher/Sources/ImportExport.java @@ -55,10 +55,18 @@ public class ImportExport { try { byte[] encoded = Files.readAllBytes(Paths.get(path)); String str = new String(encoded, Charset.defaultCharset()); + long[][] longList = Util.getArraysFromImport(str); - if(longList != null) - return new ActionList(longList[0], longList[1], longList[2], longList[3]); - JOptionPane.showMessageDialog(null, "The choosen file is invalid or currupted", "Import error", JOptionPane.ERROR_MESSAGE); + if(longList == null) { + JOptionPane.showMessageDialog(null, "The choosen file is invalid or currupted", "Import error", JOptionPane.ERROR_MESSAGE); + return null; + } + int[][] intList = new int[2][longList[0].length]; + for(int i=0; i<2; i++) + for(int j=0; j portEnum = CommPortIdentifier.getPortIdentifiers(); + + // Search for serial port + while (portEnum.hasMoreElements()) { + CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement(); + if (currPortId.getName().equals(portName)) { + portId = currPortId; + break; + } + } + if (portId == null) + throw new SerialComPortException(portName); + + // open connection + try { + serialPort = (SerialPort) portId.open(this.getClass().getName(), TIME_OUT); + serialPort.setSerialPortParams(DATA_RATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); + + input = serialPort.getInputStream(); + output = serialPort.getOutputStream(); + } catch (IOException + | UnsupportedCommOperationException + | PortInUseException e) { + throw new SerialComPortException(portName); + } + } + + public void close() { + try { + input.close(); + output.close(); + } catch (IOException e) { + e.printStackTrace(); + } + serialPort.removeEventListener(); + serialPort.close(); + } + public void send(byte[] bytes) { + try { + this.output.write(bytes); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public byte[] recieve() { + byte[] buffer = new byte[BUFFER_SIZE]; + int len = -1; + + try { len = this.input.read(buffer); } + catch (IOException e) { return null; } + + if(len == -1 || len == 0) + return null; + byte[] data = new byte[len]; + for(int i=0; i> 8); + byte dataL2 = (byte) (deltaLeft & 0xFF); + byte dataR1 = (byte) ((deltaRight & 0xFF00) >> 8); + byte dataR2 = (byte) (deltaRight & 0xFF); + byte[] data = new byte[] {dataL1, dataL2, dataR1, dataR2}; + serialCom.send(data); + + // wait for a response = move complete + byte[] bytes = null; + while(bytes == null + || bytes.length <= 0) { + bytes = serialCom.recieve(); + } + } +} diff --git a/PercTeacher/Sources/SerialPortChooserDialog.java b/PercTeacher/Sources/SerialPortChooserDialog.java new file mode 100644 index 0000000..10d0e79 --- /dev/null +++ b/PercTeacher/Sources/SerialPortChooserDialog.java @@ -0,0 +1,119 @@ +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.Enumeration; + +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +import gnu.io.CommPortIdentifier; + +public class SerialPortChooserDialog extends JDialog implements ActionListener, ListSelectionListener { + private static final long serialVersionUID = 1L; + + private boolean onlyOneChoice; + private boolean emptyChoice; + private ArrayList portNames; + private String choosedPort = null; + + private JList list; + private JButton ok; + private JButton cancel; + + private SerialPortChooserDialog() { + Enumeration portEnum = CommPortIdentifier.getPortIdentifiers(); + portNames = new ArrayList<>(); + + while (portEnum.hasMoreElements()) { + CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement(); + portNames.add(currPortId.getName()); + } + + onlyOneChoice = portNames.size() <= 1; + emptyChoice = portNames.size() == 0; + if(onlyOneChoice || emptyChoice) + return; + + // JDialog creation + JPanel mainPanel = new JPanel(new BorderLayout()); + setModal(true); + setTitle("Serial port chooser"); + + // title + mainPanel.add(new JLabel("Choose a serial port : "), BorderLayout.NORTH); + + // list ports + DefaultListModel listModel = new DefaultListModel<>(); + for(String str : portNames) + listModel.addElement(str); + list = new JList<>(listModel); + list.addListSelectionListener(this); + list.setVisibleRowCount(3); + list.setLayoutOrientation(JList.VERTICAL); + list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + + JScrollPane scrollPane = new JScrollPane(list, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + scrollPane.setPreferredSize(new Dimension(200, 100)); + mainPanel.add(scrollPane, BorderLayout.CENTER); + + // buttons ok / cancel + JPanel borderLayoutPanel = new JPanel(new BorderLayout()); + JPanel buttonsLayout = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 3)); + ok = new JButton("Ok"); + cancel = new JButton("Cancel"); + ok.addActionListener(this); + cancel.addActionListener(this); + ok.setEnabled(false); + buttonsLayout.add(cancel); + buttonsLayout.add(ok); + borderLayoutPanel.add(buttonsLayout, BorderLayout.EAST); + mainPanel.add(borderLayoutPanel, BorderLayout.SOUTH); + + // padding + JPanel padding = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); + padding.add(mainPanel); + add(padding); + + setResizable(false); + pack(); + setLocationRelativeTo(null); + setVisible(true); + } + + public static String showSerialPortChooserDialog() throws NoSerialPortException { + SerialPortChooserDialog dialog = new SerialPortChooserDialog(); + if(dialog.emptyChoice) + throw new NoSerialPortException(); + if(dialog.onlyOneChoice) + return dialog.portNames.get(0); + return dialog.choosedPort; + } + + @Override + public void actionPerformed(ActionEvent e) { + if(e.getSource() == ok) { + choosedPort = list.getSelectedValue(); + dispose(); + } else if(e.getSource() == cancel) { + dispose(); + } + } + + @Override + public void valueChanged(ListSelectionEvent e) { + if(e.getSource() == list) { + ok.setEnabled(list.getSelectedIndex() != -1); + } + } +} diff --git a/PercTeacher/Sources/Util.java b/PercTeacher/Sources/Util.java index da9daff..73778cd 100644 --- a/PercTeacher/Sources/Util.java +++ b/PercTeacher/Sources/Util.java @@ -7,15 +7,20 @@ public class Util { return null; for(int i=0; i