adafruit / Adafruit_BluefruitLE_nRF51

Arduino library for nRF51822-based Adafruit Bluefruit LE modules
197 stars 122 forks source link

peek function fails and stops any more data from being read. #7

Closed HamAndEggs closed 8 years ago

HamAndEggs commented 8 years ago

If you call peek then it's game over, read will not work.

Here is a use case, I have altered the loop from the bleuart_datamode example. All I done is add a peek() before the read() call and it breaks the app.

void loop(void) { // Check for user input char n, inputs[BUFSIZE+1];

if (Serial.available()) { n = Serial.readBytes(inputs, BUFSIZE); inputs[n] = 0; // Send characters to Bluefruit Serial.print("Sending: "); Serial.println(inputs);

// Send input data to host via Bluefruit
ble.print(inputs);

}

// Echo received data while ( ble.available() ) { int x = 'x'; // x = ble.peek(); // !!!!! Uncomment this line and the app breaks !!!!! int c = ble.read();

Serial.print((char)c);
Serial.print((char)32);
Serial.print(x);

// Hex output too, helps w/debugging!
Serial.print(" [0x");
if (c <= 0xF) Serial.print(F("0"));
Serial.print(c, HEX);
Serial.print("] ");

} }

microbuilder commented 8 years ago

Can you please confirm that you are using the following:

Also, which board are you using (Atmel 32U4 or ATSAMD21 based)?

HamAndEggs commented 8 years ago

Hi, this was fixed a while ago. Not sure why the bug was not closed. Was dealt with on the forums. There was a typo in the function and was fixed.

Ta. :)