recorder: Ensure Battery voltage is only stored to 0.01v

+      Add graphs for Steps+Battery
master
Gordon Williams 2025-06-19 16:10:04 +01:00
parent 782c71e85e
commit 1cdbc5c9cf
3 changed files with 39 additions and 10 deletions

View File

@ -59,3 +59,5 @@
0.46: Ensure altitude graph draws properly (or any graph using the last column of CSV data)
Lower accuracy of barometer data to ~1cm (saves about 15b/record)
0.47: Fix 'blip' on speed map on some recordings
Ensure Battery voltage is only stored to 0.01v
Add graphs for Steps+Battery

View File

@ -197,6 +197,14 @@ function viewTrack(filename, info) {
menu[/*LANG*/'Plot HRM'] = function() {
plotGraph(info, "Heartrate");
};
if (info.fields.includes("Steps"))
menu[/*LANG*/'Plot Steps'] = function() {
plotGraph(info, "Steps");
};
if (info.fields.includes("Battery Percentage"))
menu[/*LANG*/'Plot Battery'] = function() {
plotGraph(info, "Battery");
};
// TODO: steps, heart rate?
menu[/*LANG*/'Erase'] = function() {
E.showPrompt(/*LANG*/"Delete Track?").then(function(v) {
@ -358,12 +366,34 @@ function plotGraph(info, style) { "ram"
infn[i]+=+c[altIdx];
infc[i]++;
}
} else if (style=="Steps") {
title = /*LANG*/"Steps/min";
var stpIdx = info.fields.indexOf("Steps");
var t,lt = c[timeIdx];
while(l!==undefined) {
c=l.trim().split(",");l = f.readLine(f);
if (c[stpIdx]=="") continue;
t = c[timeIdx];
i = Math.round(80*(t - strt)/dur);
infn[i]+=60*c[stpIdx];
infc[i]+=t-lt;
lt = t;
}
} else if (style=="Battery") {
title = /*LANG*/"Battery %";
var batIdx = info.fields.indexOf("Battery Percentage");
while(l!==undefined) {
c=l.trim().split(",");l = f.readLine(f);
if (c[batIdx]=="") continue;
i = Math.round(80*(c[timeIdx] - strt)/dur);
infn[i]+=+c[batIdx];
infc[i]++;
}
} else if (style=="Speed") {
// use locate to work out units
var localeStr = require("locale").speed(1,5); // get what 1kph equates to
let units = localeStr.replace(/[0-9.]*/,"");
factor = parseFloat(localeStr)*3.6; // m/sec to whatever out units are
// title
title = /*LANG*/"Speed"+` (${units})`;
var latIdx = info.fields.indexOf("Latitude");
var lonIdx = info.fields.indexOf("Longitude");
@ -378,19 +408,15 @@ function plotGraph(info, style) { "ram"
while(l!==undefined) {
c=l.trim().split(",");
l = f.readLine(f);
if (c[latIdx] == "") {
continue;
}
if (c[latIdx] == "") continue;
t = c[timeIdx];
i = Math.round(80*(t - strt)/dur);
p = Bangle.project({lat:c[latIdx],lon:c[lonIdx]});
dx = p.x-lp.x;
dy = p.y-lp.y;
d = Math.sqrt(dx*dx+dy*dy);
if (t!=lt) {
infn[i]+=d / (t-lt); // speed
infc[i]++;
}
infn[i]+=d; // speed
infc[i]+=t-lt;
lp = p;
lt = t;
}
@ -406,6 +432,7 @@ function plotGraph(info, style) { "ram"
if (n>max) max=n;
if (n<min) min=n;
}
if (style=="Battery") {min=0;max=100;}
// work out a nice grid value
var heightDiff = max-min;
var grid = 1;

View File

@ -91,7 +91,7 @@ exports.getRecorders = function() {
name : "BAT",
fields : ["Battery Percentage", "Battery Voltage", "Charging"],
getValues : () => {
return [E.getBattery(), NRF.getBattery(), Bangle.isCharging()];
return [E.getBattery(), NRF.getBattery().toFixed(2), Bangle.isCharging()];
},
start : () => {
},