Merge pull request #1309 from hughbarney/master

Run: set format of time to h:mm:ss, pace to mm:ss, settings to disable GPS/HRM
pull/1312/head
Gordon Williams 2022-01-18 10:12:08 +00:00 committed by GitHub
commit 0d07f68ebd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 12 deletions

View File

@ -2298,7 +2298,7 @@
},
{ "id": "run",
"name": "Run",
"version":"0.01",
"version":"0.02",
"description": "Displays distance, time, steps, cadence, pace and more for runners.",
"icon": "app.png",
"tags": "run,running,fitness,outdoors,gps",
@ -2307,8 +2307,10 @@
"readme": "README.md",
"storage": [
{"name":"run.app.js","url":"app.js"},
{"name":"run.img","url":"app-icon.js","evaluate":true}
]
{"name":"run.img","url":"app-icon.js","evaluate":true},
{"name":"run.settings.js","url":"settings.js"}
],
"data": [{"name":"run.json"}]
},
{
"id": "banglerun",

View File

@ -1 +1,3 @@
0.01: New App!
0.02: Set pace format to mm:ss, time format to h:mm:ss,
added settings to opt out of GPS and HRM

View File

@ -1,6 +1,6 @@
var B2 = process.env.HWVERSION==2;
var Layout = require("Layout");
var locale = require("locale")
var locale = require("locale");
var fontHeading = "6x8:2";
var fontValue = B2 ? "6x15:2" : "6x8:3";
var headingCol = "#888";
@ -21,21 +21,25 @@ Bangle.drawWidgets();
// ---------------------------
function formatTime(ms) {
var s = Math.round(ms/1000);
var min = Math.floor(s/60).toString();
s = (s%60).toString();
return min.padStart(2,0)+":"+s.padStart(2,0);
let hrs = Math.floor(ms/3600000).toString();
let mins = (Math.floor(ms/60000)%60).toString();
let secs = (Math.floor(ms/1000)%60).toString();
if (hrs === '0')
return mins.padStart(2,0)+":"+secs.padStart(2,0);
else
return hrs+":"+mins.padStart(2,0)+":"+secs.padStart(2,0); // dont pad hours
}
// Format speed in meters/second
function formatPace(speed) {
if (speed < 0.1667) {
return `__'__"`;
return `__:__`;
}
const pace = Math.round(1000 / speed); // seconds for 1km
const min = Math.floor(pace / 60); // minutes for 1km
const sec = pace % 60;
return ('0' + min).substr(-2) + `'` + ('0' + sec).substr(-2) + `"`;
return ('0' + min).substr(-2) + `:` + ('0' + sec).substr(-2);
}
// ---------------------------
@ -149,10 +153,12 @@ Bangle.on("step", function(steps) {
lastStepCount = steps;
});
let settings = require("Storage").readJSON('run.json',1)||{"use_gps":true,"use_hrm":true};
// We always call ourselves once a second, if only to update the time
setInterval(onTimer, 1000);
/* Turn GPS and HRM on right at the start to ensure
we get the highest chance of a lock. */
Bangle.setHRMPower(true,"app");
Bangle.setGPSPower(true,"app");
if (settings.use_hrm) Bangle.setHRMPower(true,"app");
if (settings.use_gps) Bangle.setGPSPower(true,"app");

44
apps/run/settings.js Normal file
View File

@ -0,0 +1,44 @@
(function(back) {
const SETTINGS_FILE = "run.json";
// initialize with default settings...
let s = {
'use_gps': true,
'use_hrm': true
}
// ...and overwrite them with any saved values
// This way saved values are preserved if a new version adds more settings
const storage = require('Storage')
let settings = storage.readJSON(SETTINGS_FILE, 1) || {}
const saved = settings || {}
for (const key in saved) {
s[key] = saved[key]
}
function save() {
settings = s
storage.write(SETTINGS_FILE, settings)
}
E.showMenu({
'': { 'title': 'Run' },
'< Back': back,
'Use GPS': {
value: s.use_gps,
format: () => (s.use_gps ? 'Yes' : 'No'),
onchange: () => {
s.use_gps = !s.use_gps;
save();
},
},
'Use HRM': {
value: s.use_hrm,
format: () => (s.use_hrm ? 'Yes' : 'No'),
onchange: () => {
s.use_hrm = !s.use_hrm;
save();
},
}
})
})