Replace do while loop with while loop

This commit is contained in:
Kristian Sloth Lauszus 2013-04-07 17:21:28 +02:00
parent 7dc1c97fe0
commit 0df6d40fce
2 changed files with 14 additions and 14 deletions

26
SPP.cpp
View file

@ -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) {

2
SPP.h
View file

@ -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.