forked from espruino/BangleApps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Found that problem with HRM test app was that drawing graph was takin…
…g two seconds and blocking HRM raw data readings, so disabled the graph. Added some data with fixed LED current
- Loading branch information
Showing
6 changed files
with
1,508 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
vals = []; | ||
|
||
vals.push(1); | ||
vals.push(2); | ||
vals.push(3); | ||
|
||
console.log(vals); | ||
|
||
vals.shift(1); | ||
|
||
console.log(vals) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
class CircBuf { | ||
constructor(bufSize) { | ||
this.size = bufSize; | ||
this.valArr = new Array(bufSize); | ||
this.idx = 0; | ||
|
||
this.getVal = function(n) { | ||
/** | ||
* Return the value stored in position n in the buffer. | ||
*/ | ||
|
||
let i = n + this.idx; | ||
if (i>=this.valArr.length) | ||
i = i - this.valArr.length; | ||
return(this.valArr[i]); | ||
}; | ||
|
||
this.setVal = function(val) { | ||
/** | ||
* Add value val to the end of the buffer | ||
*/ | ||
this.valArr[this.idx] = val; | ||
this.idx++; | ||
if (this.idx == this.valArr.length) | ||
this.idx = 0 | ||
}; | ||
|
||
this.getLastVal = function() { | ||
/** | ||
* get the last value added to the buffer | ||
*/ | ||
if (this.idx > 0) | ||
return this.valArr[this.idx-1]; | ||
else | ||
return this.valArr[this.valArr.length -1]; | ||
}; | ||
|
||
this.getFirstVal = function() { | ||
/** | ||
* get the first value in the buffer | ||
*/ | ||
// FIXME - this is only correct once the buffer is full | ||
return this.valArr[this.idx]; | ||
}; | ||
|
||
this.getMaxMinVals = function() { | ||
/** | ||
* return [minVal, maxVal] for the buffer. | ||
*/ | ||
let i = 0; | ||
let minVal = this.valArr[0]; | ||
let maxVal = this.valArr[0]; | ||
for (i=0;i<this.size;i++) { | ||
if (this.valArr[i]<minVal) | ||
minVal = this.valArr[i]; | ||
if (this.valArr[i]>maxVal) | ||
maxVal = this.valArr[i]; | ||
} | ||
return [minVal, maxVal]; | ||
} | ||
} | ||
} | ||
|
||
function runTests() { | ||
console.log("CircBuf.runTests()"); | ||
let buf = new CircBuf(5); | ||
buf.setVal(1); | ||
buf.setVal(2); | ||
buf.setVal(3); | ||
buf.setVal(4); | ||
buf.setVal(5); | ||
buf.setVal(6); | ||
console.log(buf); | ||
|
||
console.log("first="+buf.getFirstVal()+", last="+buf.getLastVal()); | ||
for (let i=0;i<5;i++) { | ||
console.log("buf("+i+") = "+buf.getVal(i)); | ||
} | ||
|
||
buf.setVal(7); | ||
buf.setVal(8); | ||
console.log("first="+buf.getFirstVal()+", last="+buf.getLastVal()); | ||
for (let i=0;i<5;i++) { | ||
console.log("buf("+i+") = "+buf.getVal(i)); | ||
} | ||
} | ||
|
||
runTests(); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.