An array 3 sized circle buffer

Committer:
oprospero
Date:
Thu Oct 17 03:58:15 2013 +0000
Revision:
1:8c7e5801d763
Parent:
0:410ebbfd5e14
Decrease size, added weight balance

Who changed what in which revision?

UserRevisionLine numberNew contents of line
oprospero 0:410ebbfd5e14 1 #include "CircleBuffer.h"
oprospero 0:410ebbfd5e14 2
oprospero 0:410ebbfd5e14 3 CircleBuffer::CircleBuffer(void)
oprospero 0:410ebbfd5e14 4 {
oprospero 0:410ebbfd5e14 5 index = 0;
oprospero 0:410ebbfd5e14 6 for (int i = 0; i < 3; i++)
oprospero 0:410ebbfd5e14 7 {
oprospero 0:410ebbfd5e14 8 buffersum[i] = 0;
oprospero 0:410ebbfd5e14 9 for (int j = 0; j < BUFFERSIZE; j++)
oprospero 0:410ebbfd5e14 10 {
oprospero 0:410ebbfd5e14 11 buffer[j][i] = 0;
oprospero 0:410ebbfd5e14 12 }
oprospero 0:410ebbfd5e14 13 }
oprospero 0:410ebbfd5e14 14 }
oprospero 0:410ebbfd5e14 15
oprospero 1:8c7e5801d763 16
oprospero 0:410ebbfd5e14 17 void CircleBuffer::queue(float value[3])
oprospero 0:410ebbfd5e14 18 {
oprospero 1:8c7e5801d763 19 index++;
oprospero 1:8c7e5801d763 20 if (index >= BUFFERSIZE)
oprospero 1:8c7e5801d763 21 {
oprospero 1:8c7e5801d763 22 index = 0;
oprospero 1:8c7e5801d763 23 }
oprospero 0:410ebbfd5e14 24 for (int i = 0; i < 3 ; i++)
oprospero 0:410ebbfd5e14 25 {
oprospero 0:410ebbfd5e14 26 buffersum[i] -= buffer[index][i];
oprospero 0:410ebbfd5e14 27 buffersum[i] += value[i];
oprospero 0:410ebbfd5e14 28 buffer[index][i] = value[i];
oprospero 0:410ebbfd5e14 29 }
oprospero 1:8c7e5801d763 30
oprospero 0:410ebbfd5e14 31 }
oprospero 0:410ebbfd5e14 32
oprospero 0:410ebbfd5e14 33 void CircleBuffer::read(float rawfilter[3])
oprospero 0:410ebbfd5e14 34 {
oprospero 1:8c7e5801d763 35 // rawfilter[0] = buffersum[0] / BUFFERSIZE;
oprospero 1:8c7e5801d763 36 // rawfilter[1] = buffersum[1] / BUFFERSIZE;
oprospero 1:8c7e5801d763 37 // rawfilter[2] = buffersum[2] / BUFFERSIZE;
oprospero 1:8c7e5801d763 38
oprospero 1:8c7e5801d763 39 rawfilter[0] = (buffersum[0] + buffer[index][0]) / (BUFFERSIZE + 1);
oprospero 1:8c7e5801d763 40 rawfilter[1] = (buffersum[1] + buffer[index][1]) / (BUFFERSIZE + 1);
oprospero 1:8c7e5801d763 41 rawfilter[2] = (buffersum[2] + buffer[index][2]) / (BUFFERSIZE + 1);
oprospero 0:410ebbfd5e14 42 }