Driver for the JY-MCU v1.06 HC-06 Bluetooth module.
Dependents: DISCO-F746NG_rtos_test MbedTableControl
Diff: HC06Bluetooth.cpp
- Revision:
- 10:b0a0a82a9ff5
- Parent:
- 9:3e23f3f615f2
- Child:
- 11:aeb8c5c27111
--- a/HC06Bluetooth.cpp Sun Jun 19 00:30:18 2016 +0000 +++ b/HC06Bluetooth.cpp Tue Aug 02 01:32:25 2016 +0000 @@ -5,7 +5,7 @@ * Author: Developer */ -#include <HC06Bluetooth.hpp> +#include <HC06Bluetooth.h> #include <algorithm> /* Static methods used to help configure the Baudrate. */ @@ -91,6 +91,11 @@ btSerialObj.puts(buffer); } +void HC06Bluetooth::println(const char* buffer) { + btSerialObj.puts(buffer); + btSerialObj.putc('\n'); +} + void HC06Bluetooth::print(char c) { btSerialObj.putc(c); } @@ -105,24 +110,28 @@ charCallbackFunc(receivedChar); } - // If the character is a newline or carriage return, then call the line callback function. - if ((receivedChar == '\n') || (receivedChar == '\r')) { - // Terminate the buffer with a null character, since that is what strings end with. - receivedChar = '\0'; - dataReceivedBuffer[dataReceivedBufferPos] = receivedChar; - // Copy data from the buffer to a copy. - std::copy(dataReceivedBuffer, dataReceivedBuffer + dataReceivedBufferPos, dataReceivedBufferCopy); - // Reset the buffer position. - dataReceivedBufferPos = 0; - // Call the callback function. - if (lineCallbackFunc != NULL) { - lineCallbackFunc((const char*)dataReceivedBuffer); + if (lineCallbackFunc != NULL) { + // If the character is a newline or carriage return, then call the line callback function. + if ((receivedChar == '\n') || (receivedChar == '\r')) { + // Terminate the buffer with a null character, since that is what strings end with. + receivedChar = '\0'; + dataReceivedBuffer[dataReceivedBufferPos] = receivedChar; + // Copy data from the buffer to a copy. + std::copy(dataReceivedBuffer, dataReceivedBuffer + dataReceivedBufferPos, dataReceivedBufferCopy); + // 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 { - dataReceivedBuffer[dataReceivedBufferPos] = receivedChar; - dataReceivedBufferPos++; + // Otherwise, just place it in the buffer and move on. + else { + if (dataReceivedBufferPos < dataBufferSize) { + dataReceivedBuffer[dataReceivedBufferPos] = receivedChar; + dataReceivedBufferPos++; + } + } } } }