|
@@ -1,7 +1,7 @@
|
|
|
-package boebot;
|
|
|
|
|
|
|
+package bluetooth;
|
|
|
import stamp.core.*;
|
|
import stamp.core.*;
|
|
|
|
|
|
|
|
-public class Bluetooth extends Aansturing
|
|
|
|
|
|
|
+public class Bluetooth
|
|
|
{
|
|
{
|
|
|
final static int SERIAL_RX_PIN = CPU.pin14;
|
|
final static int SERIAL_RX_PIN = CPU.pin14;
|
|
|
final static int SERIAL_TX_PIN = CPU.pin15;
|
|
final static int SERIAL_TX_PIN = CPU.pin15;
|
|
@@ -9,99 +9,39 @@ public class Bluetooth extends Aansturing
|
|
|
static Uart rxUart = new Uart(Uart.dirReceive, SERIAL_RX_PIN, Uart.dontInvert, Uart.speed9600, Uart.stop1);
|
|
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);
|
|
static Uart txUart = new Uart(Uart.dirTransmit, SERIAL_TX_PIN, Uart.dontInvert, Uart.speed9600, Uart.stop1);
|
|
|
|
|
|
|
|
- private char[] route = new char[40];
|
|
|
|
|
- private int counter = 0;
|
|
|
|
|
|
|
+ private char[] data = new char[40];
|
|
|
|
|
|
|
|
- public void getRoute()
|
|
|
|
|
|
|
+ public char[] getRoute()
|
|
|
{
|
|
{
|
|
|
|
|
+ int adChar = 0;
|
|
|
|
|
+ char endRoute = '?';
|
|
|
|
|
+ char[] route = new char[40];
|
|
|
|
|
+
|
|
|
while (true)
|
|
while (true)
|
|
|
{
|
|
{
|
|
|
if (rxUart.byteAvailable())
|
|
if (rxUart.byteAvailable())
|
|
|
{
|
|
{
|
|
|
- route[counter] = (char)rxUart.receiveByte();
|
|
|
|
|
- counter ++;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (route[counter] == '¿')
|
|
|
|
|
- {
|
|
|
|
|
- counter = 0;
|
|
|
|
|
- givenRoute();
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (route[counter] == '¡')
|
|
|
|
|
- {
|
|
|
|
|
- counter = 0;
|
|
|
|
|
- calculateRoute();
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- CPU.delay(100);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ char temp = (char)rxUart.receiveByte();
|
|
|
|
|
+ data[adChar] = temp;
|
|
|
|
|
|
|
|
- private char[] givenRoute()
|
|
|
|
|
- {
|
|
|
|
|
- char[] sendRoute = route;
|
|
|
|
|
- return sendRoute;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private char[] calculateRoute()
|
|
|
|
|
- {
|
|
|
|
|
- char[] sendRoute = new char[40];
|
|
|
|
|
- int charTest = 0;
|
|
|
|
|
- int addValue = 0;
|
|
|
|
|
|
|
+ if (endRoute == temp)
|
|
|
|
|
+ {
|
|
|
|
|
+ route = data;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- while (true)
|
|
|
|
|
- {
|
|
|
|
|
- if (route[charTest] != ',' && route[charTest] != '!' && route[charTest] != '¡')
|
|
|
|
|
- {
|
|
|
|
|
- sendRoute[addValue] = route[charTest];
|
|
|
|
|
- addValue ++;
|
|
|
|
|
|
|
+ adChar ++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (route[charTest] == '¡')
|
|
|
|
|
|
|
+ if (adChar == 40)
|
|
|
{
|
|
{
|
|
|
|
|
+ System.out.println("De opgegeven route is te groot. Voer maximaal 40 route-aanwijzingen in.");
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- charTest ++;
|
|
|
|
|
|
|
+ CPU.delay(100);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return sendRoute;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void remoteControl(int pin)
|
|
|
|
|
- {
|
|
|
|
|
- while (true)
|
|
|
|
|
- {
|
|
|
|
|
- if (rxUart.byteAvailable())
|
|
|
|
|
- {
|
|
|
|
|
- char command = (char)rxUart.receiveByte();
|
|
|
|
|
- boolean IR = false;
|
|
|
|
|
-
|
|
|
|
|
- switch (command)
|
|
|
|
|
- {
|
|
|
|
|
- case 'v':
|
|
|
|
|
- super.vooruit();
|
|
|
|
|
- break;
|
|
|
|
|
- case 'a':
|
|
|
|
|
- super.achteruit();
|
|
|
|
|
- break;
|
|
|
|
|
- case 'l':
|
|
|
|
|
- super.turnleft();
|
|
|
|
|
- break;
|
|
|
|
|
- case 'r':
|
|
|
|
|
- super.turnrechts();
|
|
|
|
|
- break;
|
|
|
|
|
- case 's':
|
|
|
|
|
- super.stop();
|
|
|
|
|
- break;
|
|
|
|
|
- case 'i':
|
|
|
|
|
- CPU.writePin(CPU.pins[pin], !IR);
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return route;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|