Driver for the JY-MCU v1.06 HC-06 Bluetooth module.
Dependents: DISCO-F746NG_rtos_test MbedTableControl
Diff: HC06Bluetooth.cpp
- Revision:
- 11:aeb8c5c27111
- Parent:
- 10:b0a0a82a9ff5
- Child:
- 12:5ba022adbbfb
--- a/HC06Bluetooth.cpp Tue Aug 02 01:32:25 2016 +0000 +++ b/HC06Bluetooth.cpp Tue Aug 02 16:48:13 2016 +0000 @@ -18,7 +18,7 @@ const int32_t BaudValue[] = {1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600, 1382400}; /* HC06 Bluetooth Class Implementation: */ -HC06Bluetooth::HC06Bluetooth(PinName TX, PinName RX, void (*lineCallbackFunc) (const char* readString), void (*charCallbackFunc) (char readChar)) +HC06Bluetooth::HC06Bluetooth(PinName TX, PinName RX, void (*lineCallbackFunc) (const char* readString, size_t strlen), void (*charCallbackFunc) (char readChar)) : btSerialObj(TX, RX), lineCallbackFunc(lineCallbackFunc), charCallbackFunc(charCallbackFunc) { btSerialObj.baud(115200); @@ -118,12 +118,12 @@ dataReceivedBuffer[dataReceivedBufferPos] = receivedChar; // Copy data from the buffer to a copy. std::copy(dataReceivedBuffer, dataReceivedBuffer + dataReceivedBufferPos, dataReceivedBufferCopy); + // Call the callback function. + if (lineCallbackFunc != NULL) { + lineCallbackFunc((const char*)dataReceivedBuffer, dataReceivedBufferPos); + } // Reset the buffer position. dataReceivedBufferPos = 0; - // Call the callback function. - if (lineCallbackFunc != NULL) { - lineCallbackFunc((const char*)dataReceivedBuffer); - } } // Otherwise, just place it in the buffer and move on. else {