forked from FOSS/BangleApps
accelrec: Increase record time to 5 second
Calculate the time moving in graph display Trigger on 1.04g now, and record 10 samples before triggermaster
parent
c88179bce6
commit
d7cf959bab
|
@ -2109,7 +2109,7 @@
|
|||
"name": "Acceleration Recorder",
|
||||
"shortName":"Accel Rec",
|
||||
"icon": "app.png",
|
||||
"version":"0.01",
|
||||
"version":"0.02",
|
||||
"interface": "interface.html",
|
||||
"description": "This app puts the Bangle's accelerometer into 100Hz mode and reads 2 seconds worth of data after movement starts. The data can then be exported back to the PC.",
|
||||
"tags": "",
|
||||
|
|
|
@ -1 +1,4 @@
|
|||
0.01: New App!
|
||||
0.02: Increase record time to 5 second
|
||||
Calculate the time moving in graph display
|
||||
Trigger on 1.04g now, and record 10 samples before trigger
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
var acc;
|
||||
var HZ = 100;
|
||||
var SAMPLES = 2*HZ; // 2 seconds
|
||||
var SAMPLES = 5*HZ; // 5 seconds
|
||||
var SCALE = 5000;
|
||||
var THRESH = 1.01;
|
||||
var THRESH = 1.04;
|
||||
var accelx = new Int16Array(SAMPLES);
|
||||
var accely = new Int16Array(SAMPLES); // North
|
||||
var accelz = new Int16Array(SAMPLES); // Into clock face
|
||||
var accelIdx = 0;
|
||||
var lastAccel = undefined;
|
||||
var lastAccel;
|
||||
function accelHandlerTrigger(a) {"ram"
|
||||
if (a.mag*2>THRESH) { // *2 because 8g mode
|
||||
tStart = getTime();
|
||||
g.drawString("Recording",g.getWidth()/2,g.getHeight()/2,1);
|
||||
Bangle.removeListener('accel',accelHandlerTrigger);
|
||||
Bangle.on('accel',accelHandlerRecord);
|
||||
if (lastAccel) accelHandlerRecord(lastAccel);
|
||||
lastAccel.forEach(accelHandlerRecord);
|
||||
accelHandlerRecord(a);
|
||||
}
|
||||
lastAccel = a;
|
||||
if (lastAccel.length>10) lastAccel.shift();
|
||||
lastAccel.push(a);
|
||||
}
|
||||
function accelHandlerRecord(a) {"ram"
|
||||
var i = accelIdx++;
|
||||
|
@ -29,7 +30,8 @@ function accelHandlerRecord(a) {"ram"
|
|||
function recordStart() {"ram"
|
||||
Bangle.setLCDTimeout(0); // force LCD on
|
||||
accelIdx = 0;
|
||||
lastAccel = undefined;
|
||||
lastAccel = [];
|
||||
Bangle.accelWr(0x18,0b01110100); // off, +-8g
|
||||
Bangle.accelWr(0x1B,0x03 | 0x40); // 100hz output, ODR/2 filter
|
||||
Bangle.accelWr(0x18,0b11110100); // +-8g
|
||||
Bangle.setPollInterval(10); // 100hz input
|
||||
|
@ -42,8 +44,9 @@ function recordStart() {"ram"
|
|||
|
||||
|
||||
function recordStop() {"ram"
|
||||
console.log("Length:",getTime()-tStart);
|
||||
//console.log("Length:",getTime()-tStart);
|
||||
Bangle.setPollInterval(80); // default poll interval
|
||||
Bangle.accelWr(0x18,0b01101100); // off, +-4g
|
||||
Bangle.accelWr(0x1B,0x0); // default 12.5hz output
|
||||
Bangle.accelWr(0x18,0b11101100); // +-4g
|
||||
Bangle.removeListener('accel',accelHandlerRecord);
|
||||
|
@ -76,9 +79,14 @@ function showData() {
|
|||
|
||||
// work out stats
|
||||
var maxAccel = 0;
|
||||
var tStart = SAMPLES, tEnd = 0;
|
||||
var vel = 0, maxVel = 0;
|
||||
for (var i=0;i<SAMPLES;i++) {
|
||||
var a = accely[i]/SCALE;
|
||||
if (a>0.1) {
|
||||
if (i<tStart) tStart=i;
|
||||
if (i>tEnd) tEnd=i;
|
||||
}
|
||||
if (a>maxAccel) maxAccel=a;
|
||||
vel += a/HZ;
|
||||
if (vel>maxVel) maxVel=vel;
|
||||
|
@ -87,6 +95,7 @@ function showData() {
|
|||
g.setFont("6x8").setFontAlign(1,0);
|
||||
g.drawString("Max Y Accel: "+maxAccel.toFixed(2)+" g",g.getWidth()-14,g.getHeight()-50);
|
||||
g.drawString("Max Y Vel: "+maxVel.toFixed(2)+" m/s",g.getWidth()-14,g.getHeight()-40);
|
||||
g.drawString("Time moving: "+(tEnd-tStart)/HZ,g.getWidth()-14,g.getHeight()-30);
|
||||
//console.log("End Velocity "+vel);
|
||||
g.setFont("6x8").setFontAlign(0,0,1);
|
||||
g.drawString("FINISH",g.getWidth()-4,g.getHeight()/2);
|
||||
|
|
Loading…
Reference in New Issue