sistemaMicrontrolador3

Dependencies:   mbed

Revision:
0:390287d3dcb6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RingBuffer/Bufferinguint.cpp	Mon Dec 19 15:13:15 2016 +0000
@@ -0,0 +1,91 @@
+#include "Bufferinguint.h"
+ 
+Bufferinguint::Bufferinguint()
+{
+    for(int i = 0; i < BUFFERSIZE; i++){
+        data[i] = 0;
+    }
+    windex = 0;
+    rindex = 0;
+    full = false;
+    empty = true;
+    bufSize = BUFFERSIZE;
+}
+ 
+void Bufferinguint::put(unsigned int 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 int Bufferinguint::get()
+{  
+    unsigned int 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 Bufferinguint::isFull()
+{
+    return full;
+}
+ 
+bool Bufferinguint::isEmpty()
+{
+    return empty;
+}
+ 
+int Bufferinguint::getSize()
+{
+    return bufSize;
+}
+ 
+unsigned int Bufferinguint::getWritingIndex()
+{
+    return windex;
+}
+
+unsigned int Bufferinguint::getReadingIndex()
+{
+    return rindex;
+}   
+
+unsigned int Bufferinguint::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