Marcus Lee / SerialBuffer

Dependencies:   LinearArray

Revision:
6:ca024bcee813
Parent:
1:985b6f1c7347
Child:
8:93d1469f3f6d
diff -r d18626a8876a -r ca024bcee813 serialBuffer.cpp
--- a/serialBuffer.cpp	Tue Jan 24 15:11:05 2017 +0000
+++ b/serialBuffer.cpp	Wed Mar 08 11:11:20 2017 +0000
@@ -1,7 +1,7 @@
 #include "serialBuffer.h"
 
 utils::SerialBuffer::SerialBuffer(PinName tx, PinName rx) : RawSerial(tx, rx), rx_buffer(255) {
-    RawSerial::attach(this, &utils::SerialBuffer::rx_interrupt, Serial::RxIrq);
+    RawSerial::attach(callback(this, &utils::SerialBuffer::rx_interrupt), Serial::RxIrq);
     return;
 }
 
@@ -11,26 +11,23 @@
 }
 
 int utils::SerialBuffer::readable() {
-    return rx_buffer.readable();
+    return rx_buffer.count() > 0;
 }
 
 char utils::SerialBuffer::getc() {
-    char * output;
     RawSerial::attach(NULL, RawSerial::RxIrq);
     
-    CircularBuffer<char>::nextItem nextChar = rx_buffer.getNext();
-    if (nextChar.success)
-        output = (char*)nextChar.item;        
+    char nextChar = rx_buffer.pop();
 
-    RawSerial::attach(this, &utils::SerialBuffer::rx_interrupt, Serial::RxIrq);
+    RawSerial::attach(callback(this, &utils::SerialBuffer::rx_interrupt), Serial::RxIrq);
     
-    return *output;
+    return nextChar;
 }
 
 void utils::SerialBuffer::rx_interrupt(void) {
-    if(serial_readable(&_serial) && rx_buffer.writeable()) {
-        rx_buffer.add(serial_getc(&_serial));
+    if(serial_readable(&_serial) && !rx_buffer.full()) {
+        rx_buffer.push(serial_getc(&_serial));
     }
 
     return;   
-}
\ No newline at end of file
+}