Driver for the JY-MCU v1.06 HC-06 Bluetooth module.

Dependents:   DISCO-F746NG_rtos_test MbedTableControl

Revision:
21:cce827364df1
Parent:
20:13283edd1aba
--- a/HC06Bluetooth.cpp	Mon Aug 08 15:03:13 2016 -0400
+++ b/HC06Bluetooth.cpp	Mon Aug 08 19:48:19 2016 -0400
@@ -124,53 +124,46 @@
 
     while(btSerialObj.readable())
     {
-        dataReceivedBuffer.push(btSerialObj.getc());
+        dataReceivedBuffer.put((char*) btSerialObj.getc());
     }
-    receiveByteThreadObj.signal_set(SIG_BT_BYTE);
 }
 
 void HC06Bluetooth::receiveByteThread()
 {
     // Now that all characters have been read, process them.
+    char receivedChar;
     while(true)
     {
-        if (!dataReceivedBuffer.empty())
+      receivedChar = (uint32_t) dataReceivedBuffer.get().value.p;
+        // Call the character callback function if it is not null.
+        if (charCallbackFunc != NULL) charCallbackFunc(receivedChar);
+
+        if (lineCallbackFunc != NULL)
         {
-            char receivedChar = dataReceivedBuffer.front();
-            dataReceivedBuffer.pop();
-            // Call the character callback function if it is not null.
-            if (charCallbackFunc != NULL) charCallbackFunc(receivedChar);
-
-            if (lineCallbackFunc != NULL)
+            // If the character is a newline or carriage return, then call the line callback function.
+            if ((receivedChar == '\n') || (receivedChar == '\r'))
             {
-                // If the character is a newline or carriage return, then call the line callback function.
-                if ((receivedChar == '\n') || (receivedChar == '\r'))
+                // Clear whatever was in the toClient buffer before.
+                dataReceivedToClient.clear();
+                // Copy everything from the queue to the client buffer.
+                while(!dataReceivedBufferCopy.empty())
                 {
-                    // Clear whatever was in the toClient buffer before.
-                    dataReceivedToClient.clear();
-                    // Copy everything from the queue to the client buffer.
-                    while(!dataReceivedBufferCopy.empty())
-                    {
-                        dataReceivedToClient.push_back(dataReceivedBufferCopy.front());
-                        dataReceivedBufferCopy.pop();
-                    }
-                    // Null-terminate the string.
-                    dataReceivedToClient.push_back('\0');
+                    dataReceivedToClient.push_back(dataReceivedBufferCopy.front());
+                    dataReceivedBufferCopy.pop();
+                }
+                // Null-terminate the string.
+                dataReceivedToClient.push_back('\0');
 
-                    // Call the callback function with the toClient buffer.
-                    lineCallbackFunc(&dataReceivedToClient[0], dataReceivedToClient.size());
-                }
+                // Call the callback function with the toClient buffer.
+                lineCallbackFunc(&dataReceivedToClient[0], dataReceivedToClient.size());
+            }
 
-                // Otherwise, enqueue it in the copy.
-                else
-                {
-                    dataReceivedBufferCopy.push(receivedChar);
-                }
+            // Otherwise, enqueue it in the copy.
+            else
+            {
+                dataReceivedBufferCopy.push(receivedChar);
             }
         }
-        else {
-            receiveByteThreadObj.signal_wait(SIG_BT_BYTE);
-        }
     }
 }