-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDrift.java
51 lines (47 loc) · 1.47 KB
/
Drift.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* Drift.java with hostdrift.c
* ridgesoft intellibrain2 robot with atmega128 with 14.7mhz oscillator
*/
import com.ridgesoft.intellibrain.IntelliBrain;
import javax.comm.SerialPort;
import java.io.InputStream;
import java.io.OutputStream;
import com.ridgesoft.io.LED;
public class Drift {
static final int BUFSIZE = 64;
public static void main(String args[]) {
try {
// uncomment one line to choose a COM port
SerialPort comPort = IntelliBrain.getCom1();
// SerialPort comPort = IntelliBrain.getCom2();
comPort.setSerialPortParams(115200, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
InputStream inputStream = comPort.getInputStream();
OutputStream outputStream = comPort.getOutputStream();
int bytes,ms;
byte[] buffer = new byte[BUFSIZE];
LED led1 = IntelliBrain.getUserLed(1);
LED led2 = IntelliBrain.getUserLed(2);
led1.toggle();
while(true) {
bytes = inputStream.available();
if (bytes == -1) break;
if (bytes > 3) {
ms = (int) System.currentTimeMillis();
inputStream.read(buffer,0,bytes);
led1.toggle();
buffer[0] = (byte) (ms );
buffer[1] = (byte) (ms >> 8);
buffer[2] = (byte) (ms >> 16);
buffer[3] = (byte) (ms >> 24);
outputStream.write(buffer,0,4);
}
}
led1.off();
led2.off();
}
catch (Exception e) {
e.printStackTrace();
}
}
}