From 702b07d03c03cfc6c4f312ac88caf033c650bbef Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Tue, 9 Oct 2012 20:41:47 +0200 Subject: [PATCH] Added flush() --- SPP.cpp | 2 ++ SPP.h | 1 + 2 files changed, 3 insertions(+) diff --git a/SPP.cpp b/SPP.cpp index 08ca0241..c6b4b8ca 100644 --- a/SPP.cpp +++ b/SPP.cpp @@ -823,6 +823,8 @@ void SPP::printNumberln(uint16_t n) { } uint8_t SPP::read() { + if(rfcommAvailable == 0) // Don't read if there is nothing in the buffer + return 0; uint8_t output = rfcommDataBuffer[0]; for(uint8_t i = 1; i < rfcommAvailable; i++) rfcommDataBuffer[i-1] = rfcommDataBuffer[i]; // Shift the buffer one left diff --git a/SPP.h b/SPP.h index f6fc97ec..bdddb566 100644 --- a/SPP.h +++ b/SPP.h @@ -120,6 +120,7 @@ public: uint8_t available() { return rfcommAvailable; }; // Get the bytes waiting to be read uint8_t read(); // Used to read the buffer + void flush() { rfcommAvailable = 0; }; // Discard all the bytes in the buffer private: /* Bluetooth dongle library pointer */