diff --git a/SPP.cpp b/SPP.cpp index a2415011..08502877 100644 --- a/SPP.cpp +++ b/SPP.cpp @@ -681,7 +681,7 @@ void SPP::RFCOMM_Command(uint8_t* data, uint8_t nbytes) { void SPP::sendRfcomm(uint8_t channel, uint8_t direction, uint8_t CR, uint8_t channelType, uint8_t pfBit, uint8_t* data, uint8_t length) { l2capoutbuf[0] = channel | direction | CR | extendAddress; // RFCOMM Address l2capoutbuf[1] = channelType | pfBit; // RFCOMM Control - l2capoutbuf[2] = length << 1 | 0x01; // Length and format (allways 0x01 bytes format) + l2capoutbuf[2] = length << 1 | 0x01; // Length and format (always 0x01 bytes format) uint8_t i = 0; for (; i < length; i++) l2capoutbuf[i + 3] = data[i]; @@ -729,15 +729,15 @@ uint8_t SPP::calcFcs(uint8_t *data) { void SPP::print(const String &str) { if (!connected) return; - int16_t stringLength = str.length(); // This will be used to store the characters that still needs to be sent + uint8_t stringLength = str.length(); // This will be used to store the characters that still needs to be sent uint8_t length; // This is the length of the string we are sending uint8_t offset = 0; // This is used to keep track of where we are in the string l2capoutbuf[0] = rfcommChannelConnection | 0 | 0 | extendAddress; // RFCOMM Address l2capoutbuf[1] = RFCOMM_UIH; // RFCOMM Control - do { - if (stringLength > (sizeof (l2capoutbuf) - 4)) // Check if the string is larger that the outgoing puffer + while (stringLength) { // We will run this while loop until this variable is 0 + if (stringLength > (sizeof (l2capoutbuf) - 4)) // Check if the string is larger that the outgoing buffer length = sizeof (l2capoutbuf) - 4; else length = stringLength; @@ -752,21 +752,21 @@ void SPP::print(const String &str) { stringLength -= length; offset += length; // Increment the offset - } while (stringLength); // We will run this loop until this variable is less than 0 + } } void SPP::print(const char* str) { if (!connected) return; - int16_t stringLength = strlen(str); // This will be used to store the characters that still needs to be sent + uint8_t stringLength = strlen(str); // This will be used to store the characters that still needs to be sent uint8_t length; // This is the length of the string we are sending uint8_t offset = 0; // This is used to keep track of where we are in the string l2capoutbuf[0] = rfcommChannelConnection | 0 | 0 | extendAddress; // RFCOMM Address l2capoutbuf[1] = RFCOMM_UIH; // RFCOMM Control - do { - if (stringLength > (sizeof (l2capoutbuf) - 4)) // Check if the string is larger that the outgoing puffer + while (stringLength) { // We will run this while loop until this variable is 0 + if (stringLength > (sizeof (l2capoutbuf) - 4)) // Check if the string is larger that the outgoing buffer length = sizeof (l2capoutbuf) - 4; else length = stringLength; @@ -781,10 +781,10 @@ void SPP::print(const char* str) { stringLength -= length; offset += length; // Increment the offset - } while (stringLength); // We will run this loop until this variable is less than 0 + } } -void SPP::print(uint8_t* array, int16_t stringLength) { +void SPP::print(uint8_t* array, uint8_t stringLength) { if (!connected) return; uint8_t length; // This is the length of the string we are sending @@ -793,8 +793,8 @@ void SPP::print(uint8_t* array, int16_t stringLength) { l2capoutbuf[0] = rfcommChannelConnection | 0 | 0 | extendAddress; // RFCOMM Address l2capoutbuf[1] = RFCOMM_UIH; // RFCOMM Control - do { - if (stringLength > (sizeof (l2capoutbuf) - 4)) // Check if the string is larger that the outgoing puffer + while (stringLength) { // We will run this while loop until this variable is 0 + if (stringLength > (sizeof (l2capoutbuf) - 4)) // Check if the string is larger that the outgoing buffer length = sizeof (l2capoutbuf) - 4; else length = stringLength; @@ -809,7 +809,7 @@ void SPP::print(uint8_t* array, int16_t stringLength) { stringLength -= length; offset += length; // Increment the offset - } while (stringLength); // We will run this loop until this variable is less than 0 + } } void SPP::println(const String &str) { diff --git a/SPP.h b/SPP.h index 9dbbad8b..61a5a4c2 100644 --- a/SPP.h +++ b/SPP.h @@ -158,7 +158,7 @@ public: * @param array Array to send. * @param length Number of bytes to send. */ - void print(uint8_t* array, int16_t length); + void print(uint8_t* array, uint8_t length); /** * Same as print(uint8_t* array, uint8_t length), but will include newline and carriage return. * @param array Array to send.