Update pebblepp and accelrec app
Pebbleapp
* Add date on the bottom of the screen
Accelratino
* Change zline color to yellow
* Auto save to file without selecting the file
* Timestamp on the file name
* Storage option to delet records
master
parent
7466078356
commit
368ae251d2
|
|
@ -9,7 +9,9 @@ var accelz = new Int16Array(SAMPLES); // Into clock face
|
|||
var timestep = new Int16Array(SAMPLES); // Into clock face
|
||||
var accelIdx = 0;
|
||||
var lastAccel;
|
||||
function accelHandlerTrigger(a) {"ram"
|
||||
|
||||
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);
|
||||
|
|
@ -22,7 +24,9 @@ function accelHandlerTrigger(a) {"ram"
|
|||
lastAccel.push(a);
|
||||
}
|
||||
}
|
||||
function accelHandlerRecord(a) {"ram"
|
||||
|
||||
function accelHandlerRecord(a) {
|
||||
"ram"
|
||||
var i = accelIdx++;
|
||||
accelx[i] = a.x * SCALE * 2; // *2 because of 8g mode
|
||||
accely[i] = -a.y * SCALE * 2;
|
||||
|
|
@ -30,7 +34,9 @@ function accelHandlerRecord(a) {"ram"
|
|||
timestep[i] = (getTime() - tStart) * 1000;
|
||||
if (accelIdx >= SAMPLES) recordStop();
|
||||
}
|
||||
function recordStart() {"ram"
|
||||
|
||||
function recordStart() {
|
||||
"ram"
|
||||
Bangle.setLCDTimeout(0); // force LCD on
|
||||
accelIdx = 0;
|
||||
lastAccel = [];
|
||||
|
|
@ -46,7 +52,8 @@ function recordStart() {"ram"
|
|||
}
|
||||
|
||||
|
||||
function recordStop() {"ram"
|
||||
function recordStop() {
|
||||
"ram"
|
||||
//console.log("Length:",getTime()-tStart);
|
||||
Bangle.setPollInterval(80); // default poll interval
|
||||
Bangle.accelWr(0x18, 0b01101100); // off, +-4g
|
||||
|
|
@ -60,6 +67,9 @@ function recordStop() {"ram"
|
|||
|
||||
function showData() {
|
||||
g.clear(1);
|
||||
let csv_files_N = require("Storage").list(/^acc.*.csv$/).length;
|
||||
let w_full = g.getWidth();
|
||||
let h = g.getHeight();
|
||||
var w = g.getWidth() - 20; // width
|
||||
var m = g.getHeight() / 2; // middle
|
||||
var s = 12; // how many pixels per G
|
||||
|
|
@ -73,7 +83,7 @@ function showData() {
|
|||
for (var i = 0; i < SAMPLES; i++)
|
||||
g.lineTo(10 + i * w / SAMPLES, m - a[i] * s / SCALE);
|
||||
}
|
||||
g.setColor("#0000ff");
|
||||
g.setColor("#FFFA5F");
|
||||
plot(accelz);
|
||||
g.setColor("#ff0000");
|
||||
plot(accelx);
|
||||
|
|
@ -82,24 +92,27 @@ function showData() {
|
|||
|
||||
// work out stats
|
||||
var maxAccel = 0;
|
||||
var tStart = SAMPLES, tEnd = 0;
|
||||
var vel = 0, maxVel = 0;
|
||||
var tStart = SAMPLES,
|
||||
tEnd = 0;
|
||||
var vel = 0,
|
||||
maxVel = 0;
|
||||
for (var i = 0; i < SAMPLES; i++) {
|
||||
var a = accely[i]/SCALE;
|
||||
var a = Math.abs(accely[i] / SCALE);
|
||||
let a_yz = Math.sqrt(Math.pow(accely[i] / SCALE, 2) + Math.pow(accelz[i] / SCALE, 2));
|
||||
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;
|
||||
if (a_yz > maxVel) maxVel = a_yz;
|
||||
}
|
||||
g.reset();
|
||||
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("Max X Accel: " + maxAccel.toFixed(2) + " g", g.getWidth() - 14, g.getHeight() - 50);
|
||||
g.drawString("Max YZ Accel: " + maxVel.toFixed(2) + " g", g.getWidth() - 14, g.getHeight() - 40);
|
||||
g.drawString("Time moving: " + (tEnd - tStart) / HZ + " s", g.getWidth() - 14, g.getHeight() - 30);
|
||||
//console.log("End Velocity "+vel);
|
||||
g.setFont("6x8", 2).setFontAlign(0, 0);
|
||||
g.drawString("File num: " + (csv_files_N + 1), w_full / 2, h - 20);
|
||||
g.setFont("6x8").setFontAlign(0, 0, 1);
|
||||
g.drawString("FINISH", g.getWidth() - 4, g.getHeight() / 2);
|
||||
setWatch(function() {
|
||||
|
|
@ -135,7 +148,8 @@ function showMenu() {
|
|||
E.showMenu();
|
||||
if (accelIdx == 0) countDown();
|
||||
else E.showPrompt("Overwrite Recording?").then(ok => {
|
||||
if (ok) countDown(); else showMenu();
|
||||
if (ok) countDown();
|
||||
else showMenu();
|
||||
});
|
||||
},
|
||||
"Plot": function() {
|
||||
|
|
@ -145,10 +159,12 @@ function showMenu() {
|
|||
showMenu();
|
||||
});
|
||||
},
|
||||
"Save" : function() {
|
||||
"Storage": function() {
|
||||
E.showMenu();
|
||||
if (accelIdx) showSaveMenu();
|
||||
else E.showAlert("No Data").then(()=>{
|
||||
if (require("Storage").list(/^acc.*.csv$/).length)
|
||||
StorageMenu();
|
||||
else
|
||||
E.showAlert("No Data").then(() => {
|
||||
showMenu();
|
||||
});
|
||||
},
|
||||
|
|
@ -160,22 +176,76 @@ function showMenu() {
|
|||
}
|
||||
|
||||
function showSaveMenu() {
|
||||
var menu = {
|
||||
"" : { title : "Save" }
|
||||
};
|
||||
[1,2,3,4,5,6].forEach(i=>{
|
||||
var fn = "accelrec."+i+".csv";
|
||||
var exists = require("Storage").read(fn)!==undefined;
|
||||
menu["Recording "+i+(exists?" *":"")] = function() {
|
||||
var csv = "";
|
||||
E.showPrompt("Save recording?").then(ok => {
|
||||
if (ok)
|
||||
SaveFile();
|
||||
else
|
||||
showMenu();
|
||||
});
|
||||
}
|
||||
|
||||
function SaveFile() {
|
||||
let csv_files_N = require("Storage").list(/^acc.*.csv$/).length;
|
||||
//if (csv_files_N > 20)
|
||||
// E.showMessage("Storage is full");
|
||||
// showMenu();
|
||||
let csv = "";
|
||||
let date = new Date();
|
||||
let fn = "accelrec_" + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + "_" + (csv_files_N + 1) + ".csv";
|
||||
E.showMessage("Saveing to file \n" + fn);
|
||||
for (var i = 0; i < SAMPLES; i++)
|
||||
csv += `${timestep[i]},${accelx[i]/SCALE},${accely[i]/SCALE},${accelz[i]/SCALE}\n`;
|
||||
require("Storage").write(fn, csv);
|
||||
showMenu();
|
||||
}
|
||||
|
||||
function StorageMenu() {
|
||||
var menu = {
|
||||
"": {
|
||||
title: "Storage"
|
||||
}
|
||||
};
|
||||
let csv_files = require("Storage").list(/^acc.*.csv$/);
|
||||
var inx = 0;
|
||||
csv_files.forEach(fn => {
|
||||
inx++;
|
||||
menu[inx + ". " + fn] = function() {
|
||||
StorageOptions(fn);
|
||||
};
|
||||
});
|
||||
menu["< Back"] = function() {showMenu();};
|
||||
menu["< Back"] = function() {
|
||||
showMenu();
|
||||
};
|
||||
E.showMenu(menu);
|
||||
}
|
||||
|
||||
function StorageOptions(file) {
|
||||
let menu = {
|
||||
"": {
|
||||
title: "Options"
|
||||
},
|
||||
"Plot": function() {
|
||||
showMenu();
|
||||
},
|
||||
"Delete": function() {
|
||||
E.showMenu();
|
||||
E.showPrompt("Delete recording?").then(ok => {
|
||||
if (ok)
|
||||
DeleteRecord(file);
|
||||
else
|
||||
StorageMenu();
|
||||
});
|
||||
},
|
||||
"< Back": function() {
|
||||
StorageMenu();
|
||||
},
|
||||
};
|
||||
E.showMenu(menu);
|
||||
}
|
||||
|
||||
function DeleteRecord(file) {
|
||||
E.showMessage("Deleteing file \n" + file);
|
||||
require("Storage").erase(file);
|
||||
StorageMenu();
|
||||
}
|
||||
showMenu();
|
||||
|
|
@ -38,6 +38,8 @@ let draw = function() {
|
|||
|
||||
g.reset();
|
||||
g.setBgColor(theme.bg).clearRect(0, h2, w, h3);
|
||||
g.setFontLECO1976Regular22().setFontAlign(0, -1);
|
||||
g.setColor(0, 0, 0).drawString(date.getDay() + "." + (date.getMonth() + 1), w / 2, h3 + 5);
|
||||
g.setFontLECO1976Regular42().setFontAlign(0, -1);
|
||||
g.setColor(theme.fg);
|
||||
g.drawString(time, w/2, h2 + 8);
|
||||
|
|
@ -133,7 +135,7 @@ background.fillRect(Bangle.appRect); // start off with completely clear backgrou
|
|||
// contrast bar (top)
|
||||
g.setColor(theme.fg).fillRect(0, h2 - 6, w, h2);
|
||||
// contrast bar (bottom)
|
||||
g.setColor(theme.fg).fillRect(0, h3, w, h3 + 6);
|
||||
g.setColor(theme.fg).fillRect(w / 2 - 30, h3, w / 2 + 30, h);
|
||||
|
||||
draw();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue