Blame view

PercTeacher/Sources/ApplicationJava/SerialCommands.java 684 Bytes
04949080   pfrison   PercTeacher stabl...
1
2
3
4
  
  public class SerialCommands {
  	public static void sendDeltas(SerialCom serialCom, int deltaLeft, int deltaRight) {
  		byte dataL1 = (byte) ((deltaLeft & 0xFF00) >> 8);
01e0e7b7   pfrison   modification Perc...
5
6
7
8
  		if(deltaLeft < 0)
  			dataL1 &= 0x7F;
  		else
  			dataL1 |= 0x80;
04949080   pfrison   PercTeacher stabl...
9
  		byte dataL2 = (byte) (deltaLeft & 0xFF);
01e0e7b7   pfrison   modification Perc...
10
  
04949080   pfrison   PercTeacher stabl...
11
  		byte dataR1 = (byte) ((deltaRight & 0xFF00) >> 8);
01e0e7b7   pfrison   modification Perc...
12
13
14
15
  		if(deltaRight < 0)
  			dataR1 &= 0x7F;
  		else
  			dataR1 |= 0x80;
04949080   pfrison   PercTeacher stabl...
16
  		byte dataR2 = (byte) (deltaRight & 0xFF);
01e0e7b7   pfrison   modification Perc...
17
  
04949080   pfrison   PercTeacher stabl...
18
19
20
21
22
23
24
25
26
27
28
  		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();
  		}
  	}
  }