Programa mbed1 excelencia

Dependencies:   mbed

Revision:
0:a5908bca4740
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RingBuffer/BufferBig.cpp	Wed Jan 18 12:58:15 2017 +0000
@@ -0,0 +1,91 @@
+#include "BufferBig.h"
+ 
+BufferBig::BufferBig()
+{
+    for(int i = 0; i < BUFFERSIZE; i++){
+        data[i] = 0;
+    }
+    windex = 0;
+    rindex = 0;
+    full = false;
+    empty = true;
+    bufSize = BUFFERSIZE;
+}
+ 
+void BufferBig::put(unsigned char val)
+{
+    if(!full)
+    {
+        data[windex] = val;
+        windex++;
+        empty = false;
+        if(windex >= bufSize)
+        {
+            windex = 0;
+        }
+        if(getDif() >= bufSize - 1){
+            full = true;
+        }
+        /*if(windex >= rindex)
+        {
+            full = true;
+        }*/
+    }
+}
+ 
+unsigned char BufferBig::get()
+{  
+    unsigned char temp = 0;
+    if(!empty)
+    {
+        temp = data[rindex];
+        data[rindex] = 0;
+        full = false;
+        rindex++;
+        if(rindex >= bufSize)
+        {
+            rindex = 0;
+        }
+        if(getDif() == 0){
+            empty = true;
+        }
+        /*if(rindex >= windex)
+        {
+            empty = true;
+        }*/
+    }
+    return temp;
+}
+ 
+bool BufferBig::isFull()
+{
+    return full;
+}
+ 
+bool BufferBig::isEmpty()
+{
+    return empty;
+}
+ 
+int BufferBig::getSize()
+{
+    return bufSize;
+}
+ 
+unsigned int BufferBig::getWritingIndex()
+{
+    return windex;
+}
+
+unsigned int BufferBig::getReadingIndex()
+{
+    return rindex;
+}   
+
+unsigned int BufferBig::getDif()
+{
+        unsigned int dif = 0;
+        if((int)(windex-rindex)>=0) { dif = windex-rindex; }
+        else { dif = bufSize+windex-rindex; }   
+        return dif;
+}
\ No newline at end of file