Bluetooth.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package boebot;
  2. import stamp.core.*;
  3. public class Bluetooth
  4. {
  5. final static int SERIAL_RX_PIN = CPU.pin2;
  6. final static int SERIAL_TX_PIN = CPU.pin0;
  7. static Uart rxUart = new Uart(Uart.dirReceive, SERIAL_RX_PIN, Uart.dontInvert, Uart.speed9600, Uart.stop1);
  8. static Uart txUart = new Uart(Uart.dirTransmit, SERIAL_TX_PIN,Uart.dontInvert, Uart.speed9600, Uart.stop1);
  9. char tempChar;
  10. char[] route = new char[40];
  11. char romoteControl = ' ';
  12. public int checkBt()
  13. {
  14. if (rxUart.byteAvailable())
  15. {
  16. tempChar = (char)rxUart.receiveByte();
  17. if (tempChar == '?')
  18. {
  19. int i = 0;
  20. clearRoute();
  21. while (true)
  22. {
  23. if (rxUart.byteAvailable())
  24. {
  25. tempChar = (char)rxUart.receiveByte();
  26. if(tempChar == '?')
  27. {
  28. return 2;
  29. }
  30. route[i] = tempChar;
  31. i++;
  32. }
  33. }
  34. }
  35. else if ((tempChar == 'a') || (tempChar =='v') || (tempChar == 'l') || (tempChar == 'r') || (tempChar == 's'))
  36. {
  37. romoteControl = tempChar;
  38. return 1;
  39. }
  40. return 0;
  41. }
  42. return 0;
  43. }
  44. public char[] getRoute()
  45. {
  46. return route;
  47. }
  48. public int getromoteControl()
  49. {
  50. int value = 4;
  51. switch (romoteControl)
  52. {
  53. case 'v':
  54. value = 1;
  55. break;
  56. case 'a':
  57. value = 7;
  58. break;
  59. case 's':
  60. value = 4;
  61. break;
  62. case 'r':
  63. value = 5;
  64. break;
  65. case 'l':
  66. value = 3;
  67. break;
  68. }
  69. return value;
  70. }
  71. public void clearRoute()
  72. {
  73. for(int i = 0; i < 40; i++)
  74. {
  75. route[i] = ' ';
  76. }
  77. }
  78. }