Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: USBDevice mbed mbed-rtos
Diff: bluetoothComm.cpp
- Revision:
 - 2:1a0d675eaa6f
 - Parent:
 - 1:2af026a7c290
 - Child:
 - 3:6a249e8de7d8
 
--- a/bluetoothComm.cpp	Thu Mar 26 19:51:11 2015 +0000
+++ b/bluetoothComm.cpp	Thu Mar 26 20:21:30 2015 +0000
@@ -5,7 +5,7 @@
 bool bluetoothConnected;
 bool validBluetoothData;
 char bluetoothData[50]={0};
-
+int getIndex=0;
 // Read data from the bluetooth
 // Stores data in the bluetoothData array
 // Messages must end in the null termination character ('\0')
@@ -18,59 +18,24 @@
 {
   if(validBluetoothData) // reset array
   {
-    for(int i = 0; i < 50; i++)
-      bluetoothData[i] = '\0';
+    getIndex = 0;
+    //for(int i = 0; i < 50; i++)
+    //  bluetoothData[i] = '\0';
     validBluetoothData = false;
   }
 
   if(!bt.readable())
     return false;
 
-  int index = length(bluetoothData);
   while(bt.readable() && !validBluetoothData)
   {
-    bluetoothData[index++] = getBluetoothChar();
-    validBluetoothData = (bluetoothData[index-1] == '\0');
-  }
-  if(validBluetoothData)
-  {
-    robotPrintDebug("Got BT data <"); robotPrintDebug(bluetoothData); robotPrintlnDebug(">\0");
+    bluetoothData[getIndex] = getBluetoothChar();
+    validBluetoothData = (bluetoothData[getIndex] == '\0');
+    getIndex++;
   }
   return validBluetoothData;
 }
 
-// This method is similar to the above method, except that this version DOES BLOCK
-// It will keep trying to read until a complete message has been receieved or a timeout is reached
-// Returns true if a valid message was received
-//bool getBluetoothData()
-//{
-//  bluetoothData[0] = '\0';
-//  if(!bluetoothAvailable())
-//    return false;
-//  int timeout = 50;
-//  int index = 0;
-//  bool terminated = false;
-//  unsigned long start = millis();
-//  while(!terminated && millis() - start < timeout)
-//  {
-//    while(!bluetoothAvailable() && millis() - start < timeout);
-//    bluetoothData[index++] = getBluetoothChar();
-//    start = millis();
-//    terminated = (bluetoothData[index-1] == '\0');
-//  }
-//  if(index > 0 && bluetoothData[index-1] != '\0')
-//    bluetoothData[index] = '\0';
-//  // If it is a heartbeat, respond to it now
-//  if(equals(bluetoothData, "?"))
-//  {
-//    sendBluetoothData("?");
-//    bluetoothData[0] = '\0';
-//    return false;
-//  }
-//  robotPrintDebug("Got BT data <"); robotPrintDebug(bluetoothData); robotPrintlnDebug(">");
-//  return true;
-//}
-
 // Returns the value of bluetoothConnected
 // This variable must be set somewhere, probably in processBluetoothData
 bool isBluetoothConnected()