An array 3 sized circle buffer

Files at this revision

API Documentation at this revision

Comitter:
oprospero
Date:
Thu Oct 17 03:58:15 2013 +0000
Parent:
0:410ebbfd5e14
Commit message:
Decrease size, added weight balance

Changed in this revision

CircleBuffer.cpp Show annotated file Show diff for this revision Revisions of this file
CircleBuffer.h Show annotated file Show diff for this revision Revisions of this file
--- a/CircleBuffer.cpp	Tue Oct 15 16:32:18 2013 +0000
+++ b/CircleBuffer.cpp	Thu Oct 17 03:58:15 2013 +0000
@@ -1,7 +1,5 @@
 #include "CircleBuffer.h"
 
-
-
 CircleBuffer::CircleBuffer(void)
 {
     index = 0;
@@ -15,24 +13,30 @@
     }
 }
 
+
 void CircleBuffer::queue(float value[3])
 {
+    index++;
+    if (index >= BUFFERSIZE) 
+    {
+        index = 0;
+    }
     for (int i = 0; i < 3 ; i++)
     {
         buffersum[i] -= buffer[index][i];
         buffersum[i] += value[i];
         buffer[index][i] = value[i];
     }
-    index++;
-    if (index >= BUFFERSIZE) 
-    {
-        index = 0;
-    }
+
 }
 
 void CircleBuffer::read(float rawfilter[3])
 {
-    rawfilter[0] = buffersum[0] / BUFFERSIZE;
-    rawfilter[1] = buffersum[1] / BUFFERSIZE;
-    rawfilter[2] = buffersum[2] / BUFFERSIZE;
+//    rawfilter[0] = buffersum[0] / BUFFERSIZE;
+//    rawfilter[1] = buffersum[1] / BUFFERSIZE;
+//    rawfilter[2] = buffersum[2] / BUFFERSIZE;
+    
+    rawfilter[0] = (buffersum[0] + buffer[index][0]) / (BUFFERSIZE + 1);
+    rawfilter[1] = (buffersum[1] + buffer[index][1]) / (BUFFERSIZE + 1);
+    rawfilter[2] = (buffersum[2] + buffer[index][2]) / (BUFFERSIZE + 1);
 }
\ No newline at end of file
--- a/CircleBuffer.h	Tue Oct 15 16:32:18 2013 +0000
+++ b/CircleBuffer.h	Thu Oct 17 03:58:15 2013 +0000
@@ -5,7 +5,7 @@
 #ifndef CIRCLEBUFFER_H
 #define CIRCLEBUFFER_H
 
-#define BUFFERSIZE 8
+#define BUFFERSIZE 2
 
 class CircleBuffer
 {