From 5708e0b4331e33564c7f15c9c55d0f82e430cb73 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Mon, 31 Jan 2022 10:40:35 +0000 Subject: [PATCH] run 0.05: exstats updated so update 'distance' label is updated, option for 'speed' --- apps/run/ChangeLog | 1 + apps/run/metadata.json | 2 +- modules/exstats.js | 19 +++++++++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/apps/run/ChangeLog b/apps/run/ChangeLog index 811e3afba..11d63b402 100644 --- a/apps/run/ChangeLog +++ b/apps/run/ChangeLog @@ -3,3 +3,4 @@ added settings to opt out of GPS and HRM 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.05: exstats updated so update 'distance' label is updated, option for 'speed' diff --git a/apps/run/metadata.json b/apps/run/metadata.json index 2fd4497f6..0d718a1b3 100644 --- a/apps/run/metadata.json +++ b/apps/run/metadata.json @@ -1,6 +1,6 @@ { "id": "run", "name": "Run", - "version":"0.04", + "version":"0.05", "description": "Displays distance, time, steps, cadence, pace and more for runners.", "icon": "app.png", "tags": "run,running,fitness,outdoors,gps", diff --git a/modules/exstats.js b/modules/exstats.js index dfeee9042..60f45688f 100644 --- a/modules/exstats.js +++ b/modules/exstats.js @@ -54,7 +54,7 @@ var state = { // startTime, // time exercise started lastGPS:{}, thisGPS:{}, // This & previous GPS readings // 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 lastSteps : Bangle.getStepCount(), // last time 'step' was called 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; } var x = radians(a.lon-b.lon) * Math.cos(radians((a.lat+b.lat)/2)); 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 @@ -104,12 +104,14 @@ Bangle.on("GPS", function(fix) { if (!state.active) return; if( 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 state.avrSpeed = state.distance * 1000 / duration; // meters/sec if (stats["pacea"]) stats["pacea"].emit("changed",stats["pacea"]); state.lastGPS = state.thisGPS; state.thisGPS = fix; if (stats["pacec"]) stats["pacec"].emit("changed",stats["pacec"]); + if (stats["speed"]) stats["speed"].emit("changed",stats["speed"]); }); Bangle.on("step", function(steps) { @@ -134,6 +136,7 @@ exports.getList = function() { {name: "Heart (BPM)", id:"bpm"}, {name: "Pace (avr)", id:"pacea"}, {name: "Pace (current)", id:"pacec"}, + {name: "Speed", id:"speed"}, {name: "Cadence", id:"caden"}, ]; }; @@ -180,7 +183,7 @@ exports.getStats = function(statIDs, options) { if (statIDs.includes("pacea")) { needGPS = true; stats["pacea"]={ - title : "Pace(avr)", + title : "A Pace", getValue : function() { return state.avrSpeed; }, // in m/sec getString : function() { return formatPace(state.avrSpeed, options.paceLength); }, }; @@ -188,11 +191,19 @@ exports.getStats = function(statIDs, options) { if (statIDs.includes("pacec")) { needGPS = true; stats["pacec"]={ - title : "Pace(now)", + title : "C Pace", getValue : function() { return (state.thisGPS.speed||0)/3.6; }, // in m/sec 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")) { needGPS = true; stats["caden"]={