|
|
@@ -1,59 +1,93 @@
|
|
|
-package bluetooth;
|
|
|
+package boebot;
|
|
|
import stamp.core.*;
|
|
|
-
|
|
|
public class Bluetooth
|
|
|
{
|
|
|
- final static int SERIAL_RX_PIN = CPU.pin14;
|
|
|
- final static int SERIAL_TX_PIN = CPU.pin15;
|
|
|
-
|
|
|
- static Uart rxUart = new Uart(Uart.dirReceive, SERIAL_RX_PIN, Uart.dontInvert, Uart.speed9600, Uart.stop1);
|
|
|
- static Uart txUart = new Uart(Uart.dirTransmit, SERIAL_TX_PIN, Uart.dontInvert, Uart.speed9600, Uart.stop1);
|
|
|
-
|
|
|
- private char[] data = new char[40];
|
|
|
-
|
|
|
- public void getRoute()
|
|
|
- {
|
|
|
- int adChar = 0;
|
|
|
- char endRoute = '?';
|
|
|
-
|
|
|
- while (true)
|
|
|
- {
|
|
|
- if (rxUart.byteAvailable())
|
|
|
- {
|
|
|
- char temp = (char)rxUart.receiveByte();
|
|
|
- data[adChar] = temp;
|
|
|
-
|
|
|
- if (endRoute == temp)
|
|
|
- {
|
|
|
- returnRoute();
|
|
|
- break;
|
|
|
- }
|
|
|
+ final static int SERIAL_RX_PIN = CPU.pin2;
|
|
|
+ final static int SERIAL_TX_PIN = CPU.pin0;
|
|
|
|
|
|
- adChar ++;
|
|
|
+ static Uart rxUart = new Uart(Uart.dirReceive, SERIAL_RX_PIN, Uart.dontInvert, Uart.speed9600, Uart.stop1);
|
|
|
+ static Uart txUart = new Uart(Uart.dirTransmit, SERIAL_TX_PIN,Uart.dontInvert, Uart.speed9600, Uart.stop1);
|
|
|
+
|
|
|
+ char tempChar;
|
|
|
+ char[] route = new char[40];
|
|
|
+ char romoteControl = ' ';
|
|
|
|
|
|
- if (adChar == 40)
|
|
|
- {
|
|
|
- System.out.println("De opgegeven route is te groot. Voer maximaal 40 route-aanwijzingen in.");
|
|
|
- break;
|
|
|
+ public int checkBt()
|
|
|
+ {
|
|
|
+ if (rxUart.byteAvailable())
|
|
|
+ {
|
|
|
+ tempChar = (char)rxUart.receiveByte();
|
|
|
+
|
|
|
+ if (tempChar == '?')
|
|
|
+ {
|
|
|
+ int i = 0;
|
|
|
+ clearRoute();
|
|
|
+
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ if (rxUart.byteAvailable())
|
|
|
+ {
|
|
|
+ tempChar = (char)rxUart.receiveByte();
|
|
|
+
|
|
|
+ if(tempChar == '?')
|
|
|
+ {
|
|
|
+ return 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ route[i] = tempChar;
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ else if ((tempChar == 'a') || (tempChar =='v') || (tempChar == 'l') || (tempChar == 'r') || (tempChar == 's'))
|
|
|
+ {
|
|
|
+ romoteControl = tempChar;
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public char[] getRoute()
|
|
|
+ {
|
|
|
+ return route;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getromoteControl()
|
|
|
+ {
|
|
|
+ int value = 4;
|
|
|
+
|
|
|
+ switch (romoteControl)
|
|
|
+ {
|
|
|
+ case 'v':
|
|
|
+ value = 1;
|
|
|
+ break;
|
|
|
+ case 'a':
|
|
|
+ value = 7;
|
|
|
+ break;
|
|
|
+ case 's':
|
|
|
+ value = 4;
|
|
|
+ break;
|
|
|
+ case 'r':
|
|
|
+ value = 5;
|
|
|
+ break;
|
|
|
+ case 'l':
|
|
|
+ value = 3;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void clearRoute()
|
|
|
+ {
|
|
|
+ for(int i = 0; i < 40; i++)
|
|
|
+ {
|
|
|
+ route[i] = ' ';
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- if (!rxUart.byteAvailable())
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- CPU.delay(100);
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- private char[] returnRoute()
|
|
|
- {
|
|
|
- System.out.println("Array:");
|
|
|
- System.out.println(data[0]);
|
|
|
- System.out.println(data[1]);
|
|
|
- System.out.println(data[2]);
|
|
|
-
|
|
|
- return data;
|
|
|
- }
|
|
|
}
|