diff --git a/PercTeacher/Sources/Action.java b/PercTeacher/Sources/Action.java deleted file mode 100644 index 8b9ce7f..0000000 --- a/PercTeacher/Sources/Action.java +++ /dev/null @@ -1,88 +0,0 @@ - - -public class Action { - public static final long DELAI_DEFAULT = 1000; - - private boolean endAction = true; - - 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(int deltaL, int deltaR) { - this.deltaL = deltaL; - this.deltaR = deltaR; - this.endAction = false; - } - public Action(int deltaL, int deltaR, long delaiL, long delaiR) { - this.deltaL = deltaL; - this.deltaR = deltaR; - this.delaiL = delaiL; - this.delaiR = delaiR; - this.endAction = false; - } - - 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;} - public long getDelaiL(){return this.delaiL;} - public long getDelaiR(){return this.delaiR;} - - public boolean isEmpty() {return endAction;} - - public void calculateDelais(long microseconds) { - // left - double ticksL = (double) microseconds / (double) deltaL; - delaiL = (long) (ticksL / 2d); // 1 step = 1 "on state" + 1 "off state" - - // right - double ticksR = (double) microseconds / (double) deltaR; - delaiR = (long) (ticksR / 2d); - - // tests - if(delaiL < 50 || delaiR < 50) - System.out.println("Warning : delais are very small ! (< 50 us)"); - } - - @Override - public String toString() { - if(endAction) - return "End sequence"; - if(deltaL == 0 && deltaR == 0) - return "Pause for " + String.valueOf((double) delaiL / 1000d) + " miliseconds"; - if(deltaL == 0) { - if(deltaR > 0) - return "Turning right forward for " + String.valueOf(deltaR) + " steps during " + String.valueOf((double) (deltaR * delaiR) / 1000d) + " miliseconds"; - else - return "Turning right backward for " + String.valueOf(-deltaR) + " steps during " + String.valueOf((double) (-deltaR * delaiR) / 1000d) + " miliseconds"; - } if(deltaR == 0) { - if(deltaL > 0) - return "Turning left forward for " + String.valueOf(deltaL) + " steps during " + String.valueOf((double) (deltaL * delaiL) / 1000d) + " miliseconds"; - else - return "Turning left backward for " + String.valueOf(-deltaL) + " steps during " + String.valueOf((double) (-deltaL * delaiL) / 1000d) + " miliseconds"; - } if(deltaR == deltaL) { - 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"; - } if(deltaR == -deltaL) { - if(deltaL > 0) - return "Turning on the spot clockwise for " + String.valueOf(deltaL) + " steps during " - + String.valueOf((double) (deltaL * delaiL) / 1000d) + " miliseconds"; - else - return "Turning on the spot anti-clockwise for " + String.valueOf(deltaR) + " steps during " - + String.valueOf((double) (deltaR * delaiR) / 1000d) + " miliseconds"; - } - return "Custom curve dL:" + String.valueOf(deltaL) + "steps tL:" + String.valueOf((double) (deltaL * delaiL) / 1000d) + "ms | dR" - + String.valueOf(deltaR) + "steps tR:" + String.valueOf((double) (deltaR * delaiR) / 1000d) + "ms"; - } -} diff --git a/PercTeacher/Sources/ActionList.java b/PercTeacher/Sources/ActionList.java deleted file mode 100644 index d77f68d..0000000 --- a/PercTeacher/Sources/ActionList.java +++ /dev/null @@ -1,139 +0,0 @@ -import java.util.ArrayList; - -public class ActionList { - private ArrayList actions; - private SerialCom serialCom; - - public ActionList(SerialCom serialCom) { - this.serialCom = serialCom; - actions = new ArrayList<>(); - actions.add(new Action()); - } - public ActionList(int[] leftDeltaArray, int[] rightDeltaArray, long[] leftDelaiArray, long[] rightDelaiArray) { - if(leftDelaiArray.length != rightDelaiArray.length - || leftDelaiArray.length != leftDelaiArray.length - || leftDelaiArray.length != rightDelaiArray.length) - throw new InvalidActionListArrays(); - actions = new ArrayList<>(); - for(int i=0; i 0) + return "Turning right forward for " + String.valueOf(deltaR) + " steps during " + String.valueOf((double) (deltaR * delaiR) / 1000d) + " miliseconds"; + else + return "Turning right backward for " + String.valueOf(-deltaR) + " steps during " + String.valueOf((double) (-deltaR * delaiR) / 1000d) + " miliseconds"; + } if(deltaR == 0) { + if(deltaL > 0) + return "Turning left forward for " + String.valueOf(deltaL) + " steps during " + String.valueOf((double) (deltaL * delaiL) / 1000d) + " miliseconds"; + else + return "Turning left backward for " + String.valueOf(-deltaL) + " steps during " + String.valueOf((double) (-deltaL * delaiL) / 1000d) + " miliseconds"; + } if(deltaR == deltaL) { + 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"; + } if(deltaR == -deltaL) { + if(deltaL > 0) + return "Turning on the spot clockwise for " + String.valueOf(deltaL) + " steps during " + + String.valueOf((double) (deltaL * delaiL) / 1000d) + " miliseconds"; + else + return "Turning on the spot anti-clockwise for " + String.valueOf(deltaR) + " steps during " + + String.valueOf((double) (deltaR * delaiR) / 1000d) + " miliseconds"; + } + return "Custom curve dL:" + String.valueOf(deltaL) + "steps tL:" + String.valueOf((double) (deltaL * delaiL) / 1000d) + "ms | dR" + + String.valueOf(deltaR) + "steps tR:" + String.valueOf((double) (deltaR * delaiR) / 1000d) + "ms"; + } +} diff --git a/PercTeacher/Sources/ApplicationJava/ActionList.java b/PercTeacher/Sources/ApplicationJava/ActionList.java new file mode 100644 index 0000000..d77f68d --- /dev/null +++ b/PercTeacher/Sources/ApplicationJava/ActionList.java @@ -0,0 +1,139 @@ +import java.util.ArrayList; + +public class ActionList { + private ArrayList actions; + private SerialCom serialCom; + + public ActionList(SerialCom serialCom) { + this.serialCom = serialCom; + actions = new ArrayList<>(); + actions.add(new Action()); + } + public ActionList(int[] leftDeltaArray, int[] rightDeltaArray, long[] leftDelaiArray, long[] rightDelaiArray) { + if(leftDelaiArray.length != rightDelaiArray.length + || leftDelaiArray.length != leftDelaiArray.length + || leftDelaiArray.length != rightDelaiArray.length) + throw new InvalidActionListArrays(); + actions = new ArrayList<>(); + for(int i=0; i execute actions + * - textfields to tweak delays (+ button set to default) + * - clean Interface class + */ + +public class Main { + + public static void main(String[] args) throws InterruptedException { + String serialPort = null; + try { + serialPort = SerialPortChooserDialog.showSerialPortChooserDialog(); + } catch (NoSerialPortException e) { + JOptionPane.showMessageDialog(null, "No serial port available !", "Error", JOptionPane.ERROR_MESSAGE); + System.exit(-1); + } + if(serialPort == null) System.exit(-1); + + final SerialCom serialCom = new SerialCom(serialPort); + // arduino need time before accepting serial data + Thread.sleep(1000); + + ActionList actionList = new ActionList(serialCom); + Interface i = new Interface(actionList, new Runnable() { + @Override + public void run() { + serialCom.close(); + } + }); + i.setVisible(true); + } +} diff --git a/PercTeacher/Sources/ApplicationJava/NoSerialPortException.java b/PercTeacher/Sources/ApplicationJava/NoSerialPortException.java new file mode 100644 index 0000000..c29ea0c --- /dev/null +++ b/PercTeacher/Sources/ApplicationJava/NoSerialPortException.java @@ -0,0 +1,8 @@ + +public class NoSerialPortException extends Exception { + private static final long serialVersionUID = 1L; + + public NoSerialPortException() { + super("No serial port available !"); + } +} diff --git a/PercTeacher/Sources/ApplicationJava/SerialCom.java b/PercTeacher/Sources/ApplicationJava/SerialCom.java new file mode 100644 index 0000000..3c265ea --- /dev/null +++ b/PercTeacher/Sources/ApplicationJava/SerialCom.java @@ -0,0 +1,82 @@ +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Enumeration; + +import gnu.io.CommPortIdentifier; +import gnu.io.PortInUseException; +import gnu.io.SerialPort; +import gnu.io.UnsupportedCommOperationException; + +public class SerialCom { + private static final int DATA_RATE = 9600; + private static final int TIME_OUT = 2000; + private static final int BUFFER_SIZE = 1024; + + private SerialPort serialPort; + private InputStream input; + private OutputStream output; + + public SerialCom(int portNumberWindows) { this("COM" + String.valueOf(portNumberWindows)); } + public SerialCom(String portName) { + CommPortIdentifier portId = null; + Enumeration 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/ApplicationJava/SerialPortChooserDialog.java b/PercTeacher/Sources/ApplicationJava/SerialPortChooserDialog.java new file mode 100644 index 0000000..10d0e79 --- /dev/null +++ b/PercTeacher/Sources/ApplicationJava/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/ApplicationJava/Util.java b/PercTeacher/Sources/ApplicationJava/Util.java new file mode 100644 index 0000000..73778cd --- /dev/null +++ b/PercTeacher/Sources/ApplicationJava/Util.java @@ -0,0 +1,32 @@ + +public class Util { + public static long[][] getArraysFromImport(String str){ + long[][] arrays = new long[4][]; + String[] split = str.split("\n"); + if(split.length < 4) + return null; + + for(int i=0; i execute actions - * - textfields to tweak delays (+ button set to default) - * - clean Interface class - */ - -public class Main { - - public static void main(String[] args) throws InterruptedException { - String serialPort = null; - try { - serialPort = SerialPortChooserDialog.showSerialPortChooserDialog(); - } catch (NoSerialPortException e) { - JOptionPane.showMessageDialog(null, "No serial port available !", "Error", JOptionPane.ERROR_MESSAGE); - System.exit(-1); - } - if(serialPort == null) System.exit(-1); - - final SerialCom serialCom = new SerialCom(serialPort); - // arduino need time before accepting serial data - Thread.sleep(1000); - - ActionList actionList = new ActionList(serialCom); - Interface i = new Interface(actionList, new Runnable() { - @Override - public void run() { - serialCom.close(); - } - }); - i.setVisible(true); - } -} diff --git a/PercTeacher/Sources/NoSerialPortException.java b/PercTeacher/Sources/NoSerialPortException.java deleted file mode 100644 index c29ea0c..0000000 --- a/PercTeacher/Sources/NoSerialPortException.java +++ /dev/null @@ -1,8 +0,0 @@ - -public class NoSerialPortException extends Exception { - private static final long serialVersionUID = 1L; - - public NoSerialPortException() { - super("No serial port available !"); - } -} diff --git a/PercTeacher/Sources/Robot/makefile b/PercTeacher/Sources/Robot/makefile new file mode 100644 index 0000000..0d506a1 --- /dev/null +++ b/PercTeacher/Sources/Robot/makefile @@ -0,0 +1,36 @@ +export CC = avr-gcc + +export MCU = atmega2560 +export TARGET_ARCH = -mmcu=$(MCU) + +export CFLAGS = -Wall -I. -DF_CPU=16000000 -Os #-g +export LDFLAGS = -g $(TARGET_ARCH) -lm -Wl,--gc-sections # -Os + +TARGET = servoAndStepperControl +TERM = /dev/ttyACM0 +CPPFLAGS = -mmcu=$(MCU) +PGMERISP = -c wiring -b 115200 -P $(TERM) -D +export DUDE = /usr/bin/avrdude -F -v -p $(MCU) + +C_SRC = $(wildcard *.c) +OBJS = $(C_SRC:.c=.o) + +all: $(TARGET).hex + +clean: + rm -f *.o *.hex *.elf + +%.o:%.c + $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ + +$(TARGET).elf: $(OBJS) + $(CC) $(LDFLAGS) -o $@ $(OBJS) + +$(TARGET).hex: $(TARGET).elf + avr-objcopy -j .text -j .data -O ihex $(TARGET).elf $(TARGET).hex + avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $(TARGET).elf eeprom.hex + +upload: $(TARGET).hex + stty -F $(TERM) hupcl # reset + $(DUDE) $(PGMERISP) -U flash:w:$(TARGET).hex + make clean diff --git a/PercTeacher/Sources/Robot/servoAndStepperControl.c b/PercTeacher/Sources/Robot/servoAndStepperControl.c new file mode 100644 index 0000000..5231d23 --- /dev/null +++ b/PercTeacher/Sources/Robot/servoAndStepperControl.c @@ -0,0 +1,74 @@ +#include +#include + +#define SERIAL_BAUDE_RATE 9600 +#define DELAI_STEP 1000 +#define PIN_MOTEUR_GAUCHE 0x40 // pin 12 +#define PIN_MOTEUR_DROIT 0x20 // pin 11 + +//gestion des moteurs +void init_pins(void){ + // pin 12 et 11 + DDRB = PIN_MOTEUR_GAUCHE | PIN_MOTEUR_DROIT; +} + +void pas_moteur_gauche(void){ + // pin 12 + PORTB |= PIN_MOTEUR_GAUCHE; + _delay_us(DELAI_STEP); + PORTB &= ~PIN_MOTEUR_GAUCHE; + _delay_us(DELAI_STEP); +} + +void pas_moteur_droit(void){ + // pin 11 + PORTB |= PIN_MOTEUR_DROIT; + _delay_us(DELAI_STEP); + PORTB &= ~PIN_MOTEUR_DROIT; + _delay_us(DELAI_STEP); +} + +//gestion de la liaison serie +void init_serial(int speed){ + UBRR0 = CPU_FREQ / (((unsigned long int) speed) << 4) - 1; //Set baud rate + UCSR0B = (1 << TXEN0 | 1 << RXEN0); //Enable transmitter & receiver + UCSR0C = (1 << UCSZ01 | 1 << UCSZ00); //Set 8 bits character and 1 stop bit + UCSR0A &= ~(1 << U2X0); //Set off UART baud doubler +} + +void send_serial(unsigned char c){ + loop_until_bit_is_set(UCSR0A, UDRE0); + UDR0 = c; +} + +unsigned char get_serial(void){ + loop_until_bit_is_set(UCSR0A, RXC0); + return UDR0; +} + +int main(void){ + init_pins(); + init_serial(SERIAL_BAUDE_RATE); + + while(1){ + unsigned char deltaL1 = get_serial(); + unsigned char deltaL2 = get_serial(); + unsigned char deltaR1 = get_serial(); + unsigned char deltaR2 = get_serial(); + + // conversion 2x8 bits => 16 bits + int deltaL = deltaL1 << 8 + deltaL2; + int deltaR = deltaR1 << 8 + deltaR2; + + int deltaMax = deltaL > deltaR ? deltaL : deltaR; + for(int i=0; i i) + pas_moteur_gauche(); + if(deltaR > i) + pas_moteur_droit(); + } + + } + return 0; +} + diff --git a/PercTeacher/Sources/SerialCom.java b/PercTeacher/Sources/SerialCom.java deleted file mode 100644 index 3c265ea..0000000 --- a/PercTeacher/Sources/SerialCom.java +++ /dev/null @@ -1,82 +0,0 @@ -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Enumeration; - -import gnu.io.CommPortIdentifier; -import gnu.io.PortInUseException; -import gnu.io.SerialPort; -import gnu.io.UnsupportedCommOperationException; - -public class SerialCom { - private static final int DATA_RATE = 9600; - private static final int TIME_OUT = 2000; - private static final int BUFFER_SIZE = 1024; - - private SerialPort serialPort; - private InputStream input; - private OutputStream output; - - public SerialCom(int portNumberWindows) { this("COM" + String.valueOf(portNumberWindows)); } - public SerialCom(String portName) { - CommPortIdentifier portId = null; - Enumeration 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 deleted file mode 100644 index 10d0e79..0000000 --- a/PercTeacher/Sources/SerialPortChooserDialog.java +++ /dev/null @@ -1,119 +0,0 @@ -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 deleted file mode 100644 index 73778cd..0000000 --- a/PercTeacher/Sources/Util.java +++ /dev/null @@ -1,32 +0,0 @@ - -public class Util { - public static long[][] getArraysFromImport(String str){ - long[][] arrays = new long[4][]; - String[] split = str.split("\n"); - if(split.length < 4) - return null; - - for(int i=0; i