Added flush()

This commit is contained in:
Kristian Lauszus 2012-10-09 20:41:47 +02:00
parent 36044a4356
commit 702b07d03c
2 changed files with 3 additions and 0 deletions

View file

@ -823,6 +823,8 @@ void SPP::printNumberln(uint16_t n) {
} }
uint8_t SPP::read() { uint8_t SPP::read() {
if(rfcommAvailable == 0) // Don't read if there is nothing in the buffer
return 0;
uint8_t output = rfcommDataBuffer[0]; uint8_t output = rfcommDataBuffer[0];
for(uint8_t i = 1; i < rfcommAvailable; i++) for(uint8_t i = 1; i < rfcommAvailable; i++)
rfcommDataBuffer[i-1] = rfcommDataBuffer[i]; // Shift the buffer one left rfcommDataBuffer[i-1] = rfcommDataBuffer[i]; // Shift the buffer one left

1
SPP.h
View file

@ -120,6 +120,7 @@ public:
uint8_t available() { return rfcommAvailable; }; // Get the bytes waiting to be read uint8_t available() { return rfcommAvailable; }; // Get the bytes waiting to be read
uint8_t read(); // Used to read the buffer uint8_t read(); // Used to read the buffer
void flush() { rfcommAvailable = 0; }; // Discard all the bytes in the buffer
private: private:
/* Bluetooth dongle library pointer */ /* Bluetooth dongle library pointer */