Ring Buffer reconciled with RTOS. If with using RTOS, this lib is enabled Mutex. Default RingBuffer size is 256 Bytes, Max size is 1024 Bytes.

Dependents:   RN41 HC05 HC05 mySerial ... more

Files at this revision

API Documentation at this revision

Comitter:
AkinoriHashimoto
Date:
Thu Jan 21 06:50:24 2016 +0000
Parent:
3:dced590a2d1b
Commit message:
adj

Changed in this revision

RingBuffer.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r dced590a2d1b -r 29917182b5c8 RingBuffer.cpp
--- a/RingBuffer.cpp	Thu Jan 21 06:21:06 2016 +0000
+++ b/RingBuffer.cpp	Thu Jan 21 06:50:24 2016 +0000
@@ -54,22 +54,11 @@
     if(chr == NULL)
         return false;
 
-// mutex for RTOS
-    /*
-    #ifdef RTOS_H
-        mutex.lock();
-    #endif
-    */
     buf[idxR] = chr;
-    idxR++;
-//    idxR %= bufSize;
-    modulo(idxR);
+//    idxR++;
+    modulo(++idxR);
     _empty= false;
-    /*
-    #ifdef RTOS_H
-        mutex.unlock();
-    #endif
-    */
+
     if(idxR == idxF)
         return true;
     return false;
@@ -80,12 +69,7 @@
     if(_empty)
         return NULL;
 
-//    string str;
-//    int idx= idxF;
-//    while(!_empty) {
     char tmp= buf[idxF];
-//        idxF++;
-//        idxF %= bufSize;
     modulo(++idxF);
     if(idxF == idxR)
         _empty= true;
@@ -99,12 +83,10 @@
         return "";
 
     string str;
-//    int idx= idxF;
     while(!_empty) {
         str += buf[idxF];
-        idxF++;
-//        idxF %= bufSize;
-        modulo(idxF);
+//        idxF++;
+        modulo(++idxF);
         if(idxF == idxR)
             _empty= true;
     }
@@ -117,7 +99,6 @@
         return "";
 
     string str;
-//    int idx= idxF;
     bool breakFlag= false;
     char chr;
     while(!breakFlag) {
@@ -127,7 +108,7 @@
         modulo(idxF);
         if(idxF == idxR) {
             _empty= true;
-            breakFalg= true;
+            breakFlag= true;
         }
 
         if(chr == '\r') {