Skip to content

Commit 1cdbc5c

Browse files
committed
recorder: Ensure Battery voltage is only stored to 0.01v
+ Add graphs for Steps+Battery
1 parent 782c71e commit 1cdbc5c

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

apps/recorder/ChangeLog

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,6 @@
5858
Improve recorder ClockInfo icons
5959
0.46: Ensure altitude graph draws properly (or any graph using the last column of CSV data)
6060
Lower accuracy of barometer data to ~1cm (saves about 15b/record)
61-
0.47: Fix 'blip' on speed map on some recordings
61+
0.47: Fix 'blip' on speed map on some recordings
62+
Ensure Battery voltage is only stored to 0.01v
63+
Add graphs for Steps+Battery

apps/recorder/app.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ function viewTrack(filename, info) {
197197
menu[/*LANG*/'Plot HRM'] = function() {
198198
plotGraph(info, "Heartrate");
199199
};
200+
if (info.fields.includes("Steps"))
201+
menu[/*LANG*/'Plot Steps'] = function() {
202+
plotGraph(info, "Steps");
203+
};
204+
if (info.fields.includes("Battery Percentage"))
205+
menu[/*LANG*/'Plot Battery'] = function() {
206+
plotGraph(info, "Battery");
207+
};
200208
// TODO: steps, heart rate?
201209
menu[/*LANG*/'Erase'] = function() {
202210
E.showPrompt(/*LANG*/"Delete Track?").then(function(v) {
@@ -358,12 +366,34 @@ function plotGraph(info, style) { "ram"
358366
infn[i]+=+c[altIdx];
359367
infc[i]++;
360368
}
369+
} else if (style=="Steps") {
370+
title = /*LANG*/"Steps/min";
371+
var stpIdx = info.fields.indexOf("Steps");
372+
var t,lt = c[timeIdx];
373+
while(l!==undefined) {
374+
c=l.trim().split(",");l = f.readLine(f);
375+
if (c[stpIdx]=="") continue;
376+
t = c[timeIdx];
377+
i = Math.round(80*(t - strt)/dur);
378+
infn[i]+=60*c[stpIdx];
379+
infc[i]+=t-lt;
380+
lt = t;
381+
}
382+
} else if (style=="Battery") {
383+
title = /*LANG*/"Battery %";
384+
var batIdx = info.fields.indexOf("Battery Percentage");
385+
while(l!==undefined) {
386+
c=l.trim().split(",");l = f.readLine(f);
387+
if (c[batIdx]=="") continue;
388+
i = Math.round(80*(c[timeIdx] - strt)/dur);
389+
infn[i]+=+c[batIdx];
390+
infc[i]++;
391+
}
361392
} else if (style=="Speed") {
362393
// use locate to work out units
363394
var localeStr = require("locale").speed(1,5); // get what 1kph equates to
364395
let units = localeStr.replace(/[0-9.]*/,"");
365396
factor = parseFloat(localeStr)*3.6; // m/sec to whatever out units are
366-
// title
367397
title = /*LANG*/"Speed"+` (${units})`;
368398
var latIdx = info.fields.indexOf("Latitude");
369399
var lonIdx = info.fields.indexOf("Longitude");
@@ -378,19 +408,15 @@ function plotGraph(info, style) { "ram"
378408
while(l!==undefined) {
379409
c=l.trim().split(",");
380410
l = f.readLine(f);
381-
if (c[latIdx] == "") {
382-
continue;
383-
}
411+
if (c[latIdx] == "") continue;
384412
t = c[timeIdx];
385413
i = Math.round(80*(t - strt)/dur);
386414
p = Bangle.project({lat:c[latIdx],lon:c[lonIdx]});
387415
dx = p.x-lp.x;
388416
dy = p.y-lp.y;
389417
d = Math.sqrt(dx*dx+dy*dy);
390-
if (t!=lt) {
391-
infn[i]+=d / (t-lt); // speed
392-
infc[i]++;
393-
}
418+
infn[i]+=d; // speed
419+
infc[i]+=t-lt;
394420
lp = p;
395421
lt = t;
396422
}
@@ -406,6 +432,7 @@ function plotGraph(info, style) { "ram"
406432
if (n>max) max=n;
407433
if (n<min) min=n;
408434
}
435+
if (style=="Battery") {min=0;max=100;}
409436
// work out a nice grid value
410437
var heightDiff = max-min;
411438
var grid = 1;

apps/recorder/lib.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ exports.getRecorders = function() {
9191
name : "BAT",
9292
fields : ["Battery Percentage", "Battery Voltage", "Charging"],
9393
getValues : () => {
94-
return [E.getBattery(), NRF.getBattery(), Bangle.isCharging()];
94+
return [E.getBattery(), NRF.getBattery().toFixed(2), Bangle.isCharging()];
9595
},
9696
start : () => {
9797
},

0 commit comments

Comments
 (0)