-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathringMod.js
78 lines (61 loc) · 1.46 KB
/
ringMod.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//ringMod.js
// 16 Feb2018
//A ring buffer for storing data in type array
function ring(hname,size,type,mult,slope,intercept,logfunc,lfargs,format,fargs){
//function ring(hname,size,type,mult,slope,intercept,logfunc,format,fargs){
this.hname=hname;
this.format=format;
this.fargs=fargs;
this.logfunc=logfunc;
this.lfargs=lfargs;
this.mult=mult;
this.slope=slope;
this.intercept=intercept;
this.size=size;
this.buf=new type(this.size);
this.ptr=0;
this.dptr=0;
this.cnt=0;
}
ring.prototype.insert=function(){
// console.log(this.logfunc);
this.buf[this.ptr]=this.logfunc(this.lfargs)*this.mult;
// this.buf[this.ptr]=this.logfunc()*this.mult;
this.ptr++;
if(this.ptr>=this.size)this.ptr=0;
if(this.cnt<this.size)this.cnt++;
};
ring.prototype.output=function(){
var i,j,a;
if(this.cnt<this.size){
j=0;
}else{
j=this.ptr;
}
for(i=0;i<this.cnt;i++){
a=this.buf[j]/this.mult*this.slope+this.intercept;
if(this.format){
console.log(i,'\t',this.format(a,this.fargs));
}else{
console.log(i,'\t',a);
}
j++;
if(j>=this.size)j=0;
}//next i
};
ring.prototype.getDatum=function(i){
var a;
if(i===0){
if(this.cnt<this.size){
this.dptr=-1;
}else{
this.dptr=this.ptr-1;
}
}
this.dptr++;
if(this.dptr>=this.size)this.dptr=0;
a=this.buf[this.dptr]/this.mult*this.slope+this.intercept;
if(this.format) return this.format(a,this.fargs);
return a;
};
module.exports=ring;