blob: d4d120f9662b2bc03e7018079d13efc0ec2d225b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#include "xc.h"
#include "circBuffer.h"
#define SIZE 1024
volatile unsigned int buffer[SIZE];
int buffSize = 0, write = 0, read = 0;
void initBuffer(){
int i;
for (i=0; i<SIZE; i++) {
buffer[i]=0;
}
buffSize = 0, write = 0, read = 0;
}
void putVal(int newValue){
if (buffSize < SIZE) {
buffer[write++] = newValue;
write %= SIZE;
++buffSize;
}
//Otherwise get rid of the data.
}
int getAvg(){
int i, sum = 0;
for (i=0; i<SIZE; i++) {
sum += buffer[i];
} return sum / SIZE;
}
|