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

Dependents:   DISCO-F746NG_rtos_test MbedTableControl

Revision:
3:ee17212e838e
Parent:
2:7e0453895727
Child:
6:5ba0038a7a9a
--- a/HC06Bluetooth.cpp	Tue Jun 07 18:10:14 2016 +0000
+++ b/HC06Bluetooth.cpp	Tue Jun 07 19:51:22 2016 +0000
@@ -9,29 +9,26 @@
 #include <algorithm>
 
 HC06Bluetooth::HC06Bluetooth(PinName TX, PinName RX, std::string deviceName, void (*callbackFunc) (const char* readString))
-: btSerialObj(TX, RX), callbackFunc (callbackFunc) {
+: RawSerial(TX, RX), callbackFunc (callbackFunc) {
     // The default baud rate is 9600. Overwrite it to 230400.
-    btSerialObj.puts("AT+BAUD9");
-    btSerialObj.baud(230400);
+    puts("AT+BAUD9");
+    baud(230400);
     // Set the name of the device.
-    btSerialObj.puts(("AT+NAME" + deviceName).c_str());
+    puts(("AT+NAME" + deviceName).c_str());
     // Set the interrupt to be called when a byte is received.
-    btSerialObj.attach(this, &HC06Bluetooth::receiveByteISR);
+    if (callbackFunc != NULL) {
+        attach(this, &HC06Bluetooth::receiveByteISR);
+    }
 }
 
 HC06Bluetooth::~HC06Bluetooth() {
     // TODO Auto-generated destructor stub
 }
 
-
-void HC06Bluetooth::print(const char *buffer) {
-    btSerialObj.puts(buffer);
-}
-
 void HC06Bluetooth::receiveByteISR() {
-    while(btSerialObj.readable()) {
+    while(readable()) {
         // Get the character from the input.
-        char receivedChar = btSerialObj.getc();
+        char receivedChar = getc();
         // If the character is a newline, then a full command has been read.
         if (receivedChar == '\n') {
             // Terminate the buffer with a null character, since that is what strings end with.
@@ -46,7 +43,7 @@
         }
         // Otherwise, just place it in the buffer and move on.
         else {
-            dataReceivedBuffer[dataReceivedBufferPos] = btSerialObj.getc();
+            dataReceivedBuffer[dataReceivedBufferPos] = getc();
             dataReceivedBufferPos++;
         }
     }