mirror of https://github.com/espruino/BangleApps
run 0.05: exstats updated so update 'distance' label is updated, option for 'speed'
parent
8305b66b24
commit
5708e0b433
|
@ -3,3 +3,4 @@
|
||||||
added settings to opt out of GPS and HRM
|
added settings to opt out of GPS and HRM
|
||||||
0.03: Fixed distance calculation, tested against Garmin Etrex, Amazfit GTS 2
|
0.03: Fixed distance calculation, tested against Garmin Etrex, Amazfit GTS 2
|
||||||
0.04: Use the exstats module, and make what is displayed configurable
|
0.04: Use the exstats module, and make what is displayed configurable
|
||||||
|
0.05: exstats updated so update 'distance' label is updated, option for 'speed'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{ "id": "run",
|
{ "id": "run",
|
||||||
"name": "Run",
|
"name": "Run",
|
||||||
"version":"0.04",
|
"version":"0.05",
|
||||||
"description": "Displays distance, time, steps, cadence, pace and more for runners.",
|
"description": "Displays distance, time, steps, cadence, pace and more for runners.",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"tags": "run,running,fitness,outdoors,gps",
|
"tags": "run,running,fitness,outdoors,gps",
|
||||||
|
|
|
@ -54,7 +54,7 @@ var state = {
|
||||||
// startTime, // time exercise started
|
// startTime, // time exercise started
|
||||||
lastGPS:{}, thisGPS:{}, // This & previous GPS readings
|
lastGPS:{}, thisGPS:{}, // This & previous GPS readings
|
||||||
// distance : 0, ///< distance in meters
|
// distance : 0, ///< distance in meters
|
||||||
// avrSpeed : 0, ///< in m/sec
|
// avrSpeed : 0, ///< speed over whole run in m/sec
|
||||||
startSteps : Bangle.getStepCount(), ///< number of steps when we started
|
startSteps : Bangle.getStepCount(), ///< number of steps when we started
|
||||||
lastSteps : Bangle.getStepCount(), // last time 'step' was called
|
lastSteps : Bangle.getStepCount(), // last time 'step' was called
|
||||||
stepHistory : new Uint8Array(60), // steps each second for the last minute (0 = current minute)
|
stepHistory : new Uint8Array(60), // steps each second for the last minute (0 = current minute)
|
||||||
|
@ -72,7 +72,7 @@ function calcDistance(a,b) {
|
||||||
function radians(a) { return a*Math.PI/180; }
|
function radians(a) { return a*Math.PI/180; }
|
||||||
var x = radians(a.lon-b.lon) * Math.cos(radians((a.lat+b.lat)/2));
|
var x = radians(a.lon-b.lon) * Math.cos(radians((a.lat+b.lat)/2));
|
||||||
var y = radians(b.lat-a.lat);
|
var y = radians(b.lat-a.lat);
|
||||||
return Math.round(Math.sqrt(x*x + y*y) * 6371000);
|
return Math.sqrt(x*x + y*y) * 6371000;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Given milliseconds, return a time
|
// Given milliseconds, return a time
|
||||||
|
@ -104,12 +104,14 @@ Bangle.on("GPS", function(fix) {
|
||||||
if (!state.active) return;
|
if (!state.active) return;
|
||||||
if( state.lastGPS.fix)
|
if( state.lastGPS.fix)
|
||||||
state.distance += calcDistance(state.lastGPS, fix);
|
state.distance += calcDistance(state.lastGPS, fix);
|
||||||
|
if (stats["dist"]) stats["dist"].emit("changed",stats["dist"]);
|
||||||
var duration = Date.now() - state.startTime; // in ms
|
var duration = Date.now() - state.startTime; // in ms
|
||||||
state.avrSpeed = state.distance * 1000 / duration; // meters/sec
|
state.avrSpeed = state.distance * 1000 / duration; // meters/sec
|
||||||
if (stats["pacea"]) stats["pacea"].emit("changed",stats["pacea"]);
|
if (stats["pacea"]) stats["pacea"].emit("changed",stats["pacea"]);
|
||||||
state.lastGPS = state.thisGPS;
|
state.lastGPS = state.thisGPS;
|
||||||
state.thisGPS = fix;
|
state.thisGPS = fix;
|
||||||
if (stats["pacec"]) stats["pacec"].emit("changed",stats["pacec"]);
|
if (stats["pacec"]) stats["pacec"].emit("changed",stats["pacec"]);
|
||||||
|
if (stats["speed"]) stats["speed"].emit("changed",stats["speed"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
Bangle.on("step", function(steps) {
|
Bangle.on("step", function(steps) {
|
||||||
|
@ -134,6 +136,7 @@ exports.getList = function() {
|
||||||
{name: "Heart (BPM)", id:"bpm"},
|
{name: "Heart (BPM)", id:"bpm"},
|
||||||
{name: "Pace (avr)", id:"pacea"},
|
{name: "Pace (avr)", id:"pacea"},
|
||||||
{name: "Pace (current)", id:"pacec"},
|
{name: "Pace (current)", id:"pacec"},
|
||||||
|
{name: "Speed", id:"speed"},
|
||||||
{name: "Cadence", id:"caden"},
|
{name: "Cadence", id:"caden"},
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
@ -180,7 +183,7 @@ exports.getStats = function(statIDs, options) {
|
||||||
if (statIDs.includes("pacea")) {
|
if (statIDs.includes("pacea")) {
|
||||||
needGPS = true;
|
needGPS = true;
|
||||||
stats["pacea"]={
|
stats["pacea"]={
|
||||||
title : "Pace(avr)",
|
title : "A Pace",
|
||||||
getValue : function() { return state.avrSpeed; }, // in m/sec
|
getValue : function() { return state.avrSpeed; }, // in m/sec
|
||||||
getString : function() { return formatPace(state.avrSpeed, options.paceLength); },
|
getString : function() { return formatPace(state.avrSpeed, options.paceLength); },
|
||||||
};
|
};
|
||||||
|
@ -188,11 +191,19 @@ exports.getStats = function(statIDs, options) {
|
||||||
if (statIDs.includes("pacec")) {
|
if (statIDs.includes("pacec")) {
|
||||||
needGPS = true;
|
needGPS = true;
|
||||||
stats["pacec"]={
|
stats["pacec"]={
|
||||||
title : "Pace(now)",
|
title : "C Pace",
|
||||||
getValue : function() { return (state.thisGPS.speed||0)/3.6; }, // in m/sec
|
getValue : function() { return (state.thisGPS.speed||0)/3.6; }, // in m/sec
|
||||||
getString : function() { return formatPace(this.getValue(), options.paceLength); },
|
getString : function() { return formatPace(this.getValue(), options.paceLength); },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (statIDs.includes("speed")) {
|
||||||
|
needGPS = true;
|
||||||
|
stats["speed"]={
|
||||||
|
title : "Speed",
|
||||||
|
getValue : function() { return state.thisGPS.speed||0; }, // in kph
|
||||||
|
getString : function() { return require("locale").speed(state.thisGPS.speed||0); },
|
||||||
|
};
|
||||||
|
}
|
||||||
if (statIDs.includes("caden")) {
|
if (statIDs.includes("caden")) {
|
||||||
needGPS = true;
|
needGPS = true;
|
||||||
stats["caden"]={
|
stats["caden"]={
|
||||||
|
|
Loading…
Reference in New Issue