An array 3 sized circle buffer
CircleBuffer.cpp@0:410ebbfd5e14, 2013-10-15 (annotated)
- Committer:
- oprospero
- Date:
- Tue Oct 15 16:32:18 2013 +0000
- Revision:
- 0:410ebbfd5e14
- Child:
- 1:8c7e5801d763
Intial;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
oprospero | 0:410ebbfd5e14 | 1 | #include "CircleBuffer.h" |
oprospero | 0:410ebbfd5e14 | 2 | |
oprospero | 0:410ebbfd5e14 | 3 | |
oprospero | 0:410ebbfd5e14 | 4 | |
oprospero | 0:410ebbfd5e14 | 5 | CircleBuffer::CircleBuffer(void) |
oprospero | 0:410ebbfd5e14 | 6 | { |
oprospero | 0:410ebbfd5e14 | 7 | index = 0; |
oprospero | 0:410ebbfd5e14 | 8 | for (int i = 0; i < 3; i++) |
oprospero | 0:410ebbfd5e14 | 9 | { |
oprospero | 0:410ebbfd5e14 | 10 | buffersum[i] = 0; |
oprospero | 0:410ebbfd5e14 | 11 | for (int j = 0; j < BUFFERSIZE; j++) |
oprospero | 0:410ebbfd5e14 | 12 | { |
oprospero | 0:410ebbfd5e14 | 13 | buffer[j][i] = 0; |
oprospero | 0:410ebbfd5e14 | 14 | } |
oprospero | 0:410ebbfd5e14 | 15 | } |
oprospero | 0:410ebbfd5e14 | 16 | } |
oprospero | 0:410ebbfd5e14 | 17 | |
oprospero | 0:410ebbfd5e14 | 18 | void CircleBuffer::queue(float value[3]) |
oprospero | 0:410ebbfd5e14 | 19 | { |
oprospero | 0:410ebbfd5e14 | 20 | for (int i = 0; i < 3 ; i++) |
oprospero | 0:410ebbfd5e14 | 21 | { |
oprospero | 0:410ebbfd5e14 | 22 | buffersum[i] -= buffer[index][i]; |
oprospero | 0:410ebbfd5e14 | 23 | buffersum[i] += value[i]; |
oprospero | 0:410ebbfd5e14 | 24 | buffer[index][i] = value[i]; |
oprospero | 0:410ebbfd5e14 | 25 | } |
oprospero | 0:410ebbfd5e14 | 26 | index++; |
oprospero | 0:410ebbfd5e14 | 27 | if (index >= BUFFERSIZE) |
oprospero | 0:410ebbfd5e14 | 28 | { |
oprospero | 0:410ebbfd5e14 | 29 | index = 0; |
oprospero | 0:410ebbfd5e14 | 30 | } |
oprospero | 0:410ebbfd5e14 | 31 | } |
oprospero | 0:410ebbfd5e14 | 32 | |
oprospero | 0:410ebbfd5e14 | 33 | void CircleBuffer::read(float rawfilter[3]) |
oprospero | 0:410ebbfd5e14 | 34 | { |
oprospero | 0:410ebbfd5e14 | 35 | rawfilter[0] = buffersum[0] / BUFFERSIZE; |
oprospero | 0:410ebbfd5e14 | 36 | rawfilter[1] = buffersum[1] / BUFFERSIZE; |
oprospero | 0:410ebbfd5e14 | 37 | rawfilter[2] = buffersum[2] / BUFFERSIZE; |
oprospero | 0:410ebbfd5e14 | 38 | } |