Driver for the JY-MCU v1.06 HC-06 Bluetooth module.
Dependents: DISCO-F746NG_rtos_test MbedTableControl
Diff: HC06Bluetooth.cpp
- Revision:
- 6:5ba0038a7a9a
- Parent:
- 3:ee17212e838e
- Child:
- 8:14bf9b541f9a
--- a/HC06Bluetooth.cpp Tue Jun 07 20:25:14 2016 +0000 +++ b/HC06Bluetooth.cpp Thu Jun 09 18:25:31 2016 +0000 @@ -9,15 +9,15 @@ #include <algorithm> HC06Bluetooth::HC06Bluetooth(PinName TX, PinName RX, std::string deviceName, void (*callbackFunc) (const char* readString)) -: RawSerial(TX, RX), callbackFunc (callbackFunc) { +: btSerialObj(TX, RX), callbackFunc (callbackFunc) { // The default baud rate is 9600. Overwrite it to 230400. - puts("AT+BAUD9"); - baud(230400); + btSerialObj.puts("AT+BAUD9"); + btSerialObj.baud(230400); // Set the name of the device. - puts(("AT+NAME" + deviceName).c_str()); + btSerialObj.puts(("AT+NAME" + deviceName).c_str()); // Set the interrupt to be called when a byte is received. if (callbackFunc != NULL) { - attach(this, &HC06Bluetooth::receiveByteISR); + btSerialObj.attach(this, &HC06Bluetooth::receiveByteISR); } } @@ -25,10 +25,14 @@ // TODO Auto-generated destructor stub } +void HC06Bluetooth::print(const char* buffer) { + btSerialObj.puts(buffer); +} + void HC06Bluetooth::receiveByteISR() { - while(readable()) { + while(btSerialObj.readable()) { // Get the character from the input. - char receivedChar = getc(); + char receivedChar = btSerialObj.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. @@ -43,7 +47,7 @@ } // Otherwise, just place it in the buffer and move on. else { - dataReceivedBuffer[dataReceivedBufferPos] = getc(); + dataReceivedBuffer[dataReceivedBufferPos] = btSerialObj.getc(); dataReceivedBufferPos++; } }