mirror of https://github.com/espruino/BangleApps
run: Keep run state between runs (allowing you to exit and restart the app)
parent
7459635362
commit
5ebb56e950
|
@ -13,3 +13,4 @@
|
||||||
0.12: Fix for recorder not stopping at end of run. Bug introduced in 0.11
|
0.12: Fix for recorder not stopping at end of run. Bug introduced in 0.11
|
||||||
0.13: Revert #1578 (stop duplicate entries) as with 2v12 menus it causes other boxes to be wiped (fix #1643)
|
0.13: Revert #1578 (stop duplicate entries) as with 2v12 menus it causes other boxes to be wiped (fix #1643)
|
||||||
0.14: Fix Bangle.js 1 issue where after the 'overwrite track' menu, the start/stop button stopped working
|
0.14: Fix Bangle.js 1 issue where after the 'overwrite track' menu, the start/stop button stopped working
|
||||||
|
0.15: Keep run state between runs (allowing you to exit and restart the app)
|
||||||
|
|
|
@ -41,6 +41,13 @@ var statIDs = [settings.B1,settings.B2,settings.B3,settings.B4,settings.B5,setti
|
||||||
var exs = ExStats.getStats(statIDs, settings);
|
var exs = ExStats.getStats(statIDs, settings);
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
|
|
||||||
|
function setStatus(running) {
|
||||||
|
layout.button.label = running ? "STOP" : "START";
|
||||||
|
layout.status.label = running ? "RUN" : "STOP";
|
||||||
|
layout.status.bgCol = running ? "#0f0" : "#f00";
|
||||||
|
layout.render();
|
||||||
|
}
|
||||||
|
|
||||||
// Called to start/stop running
|
// Called to start/stop running
|
||||||
function onStartStop() {
|
function onStartStop() {
|
||||||
var running = !exs.state.active;
|
var running = !exs.state.active;
|
||||||
|
@ -77,12 +84,9 @@ function onStartStop() {
|
||||||
} else {
|
} else {
|
||||||
exs.stop();
|
exs.stop();
|
||||||
}
|
}
|
||||||
layout.button.label = running ? "STOP" : "START";
|
|
||||||
layout.status.label = running ? "RUN" : "STOP";
|
|
||||||
layout.status.bgCol = running ? "#0f0" : "#f00";
|
|
||||||
// if stopping running, don't clear state
|
// if stopping running, don't clear state
|
||||||
// so we can at least refer to what we've done
|
// so we can at least refer to what we've done
|
||||||
layout.render();
|
setStatus(running);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,13 +109,14 @@ for (var i=0;i<statIDs.length;i+=2) {
|
||||||
lc.push({ type:"h", filly:1, c:[
|
lc.push({ type:"h", filly:1, c:[
|
||||||
{type:"txt", font:fontHeading, label:"GPS", id:"gps", fillx:1, bgCol:"#f00" },
|
{type:"txt", font:fontHeading, label:"GPS", id:"gps", fillx:1, bgCol:"#f00" },
|
||||||
{type:"txt", font:fontHeading, label:"00:00", id:"clock", fillx:1, bgCol:g.theme.fg, col:g.theme.bg },
|
{type:"txt", font:fontHeading, label:"00:00", id:"clock", fillx:1, bgCol:g.theme.fg, col:g.theme.bg },
|
||||||
{type:"txt", font:fontHeading, label:"STOP", id:"status", fillx:1 }
|
{type:"txt", font:fontHeading, label:"---", id:"status", fillx:1 }
|
||||||
]});
|
]});
|
||||||
// Now calculate the layout
|
// Now calculate the layout
|
||||||
var layout = new Layout( {
|
var layout = new Layout( {
|
||||||
type:"v", c: lc
|
type:"v", c: lc
|
||||||
},{lazy:true, btns:[{ label:"START", cb: onStartStop, id:"button"}]});
|
},{lazy:true, btns:[{ label:"---", cb: onStartStop, id:"button"}]});
|
||||||
delete lc;
|
delete lc;
|
||||||
|
setStatus(exs.state.active);
|
||||||
layout.render();
|
layout.render();
|
||||||
|
|
||||||
function configureNotification(stat) {
|
function configureNotification(stat) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{ "id": "run",
|
{ "id": "run",
|
||||||
"name": "Run",
|
"name": "Run",
|
||||||
"version":"0.14",
|
"version":"0.15",
|
||||||
"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",
|
||||||
|
|
|
@ -14,3 +14,4 @@
|
||||||
0.13: Revert #1578 (stop duplicate entries) as with 2v12 menus it causes other boxes to be wiped (fix #1643)
|
0.13: Revert #1578 (stop duplicate entries) as with 2v12 menus it causes other boxes to be wiped (fix #1643)
|
||||||
0.14: Fix Bangle.js 1 issue where after the 'overwrite track' menu, the start/stop button stopped working
|
0.14: Fix Bangle.js 1 issue where after the 'overwrite track' menu, the start/stop button stopped working
|
||||||
0.15: Diverge from the standard "Run" app. Swipe to intensity interface a la Karvonnen (curtesy of FTeacher at https://github.com/f-teacher)
|
0.15: Diverge from the standard "Run" app. Swipe to intensity interface a la Karvonnen (curtesy of FTeacher at https://github.com/f-teacher)
|
||||||
|
Keep run state between runs (allowing you to exit and restart the app)
|
||||||
|
|
|
@ -52,6 +52,13 @@ let statIDs = [settings.B1,settings.B2,settings.B3,settings.B4,settings.B5,setti
|
||||||
let exs = ExStats.getStats(statIDs, settings);
|
let exs = ExStats.getStats(statIDs, settings);
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
|
|
||||||
|
function setStatus(running) {
|
||||||
|
layout.button.label = running ? "STOP" : "START";
|
||||||
|
layout.status.label = running ? "RUN" : "STOP";
|
||||||
|
layout.status.bgCol = running ? "#0f0" : "#f00";
|
||||||
|
layout.render();
|
||||||
|
}
|
||||||
|
|
||||||
// Called to start/stop running
|
// Called to start/stop running
|
||||||
function onStartStop() {
|
function onStartStop() {
|
||||||
let running = !exs.state.active;
|
let running = !exs.state.active;
|
||||||
|
@ -88,12 +95,9 @@ function onStartStop() {
|
||||||
} else {
|
} else {
|
||||||
exs.stop();
|
exs.stop();
|
||||||
}
|
}
|
||||||
layout.button.label = running ? "STOP" : "START";
|
|
||||||
layout.status.label = running ? "RUN" : "STOP";
|
|
||||||
layout.status.bgCol = running ? "#0f0" : "#f00";
|
|
||||||
// if stopping running, don't clear state
|
// if stopping running, don't clear state
|
||||||
// so we can at least refer to what we've done
|
// so we can at least refer to what we've done
|
||||||
layout.render();
|
setStatus(running);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,13 +120,14 @@ for (let i=0;i<statIDs.length;i+=2) {
|
||||||
lc.push({ type:"h", filly:1, c:[
|
lc.push({ type:"h", filly:1, c:[
|
||||||
{type:"txt", font:fontHeading, label:"GPS", id:"gps", fillx:1, bgCol:"#f00" },
|
{type:"txt", font:fontHeading, label:"GPS", id:"gps", fillx:1, bgCol:"#f00" },
|
||||||
{type:"txt", font:fontHeading, label:"00:00", id:"clock", fillx:1, bgCol:g.theme.fg, col:g.theme.bg },
|
{type:"txt", font:fontHeading, label:"00:00", id:"clock", fillx:1, bgCol:g.theme.fg, col:g.theme.bg },
|
||||||
{type:"txt", font:fontHeading, label:"STOP", id:"status", fillx:1 }
|
{type:"txt", font:fontHeading, label:"---", id:"status", fillx:1 }
|
||||||
]});
|
]});
|
||||||
// Now calculate the layout
|
// Now calculate the layout
|
||||||
let layout = new Layout( {
|
let layout = new Layout( {
|
||||||
type:"v", c: lc
|
type:"v", c: lc
|
||||||
},{lazy:true, btns:[{ label:"START", cb: ()=>{if (karvonnenActive) {stopKarvonnenUI();run();} onStartStop();}, id:"button"}]});
|
},{lazy:true, btns:[{ label:"---", cb: ()=>{if (karvonnenActive) {stopKarvonnenUI();run();} onStartStop();}, id:"button"}]});
|
||||||
delete lc;
|
delete lc;
|
||||||
|
setStatus(exs.state.active);
|
||||||
layout.render();
|
layout.render();
|
||||||
|
|
||||||
function configureNotification(stat) {
|
function configureNotification(stat) {
|
||||||
|
|
|
@ -93,6 +93,16 @@ var state = {
|
||||||
// list of active stats (indexed by ID)
|
// list of active stats (indexed by ID)
|
||||||
var stats = {};
|
var stats = {};
|
||||||
|
|
||||||
|
const DATA_FILE = "exstats.json";
|
||||||
|
// Load the state from a saved file if there was one
|
||||||
|
state = Object.assign(state, require("Storage").readJSON(DATA_FILE,1)||{});
|
||||||
|
// force step history to a uint8array
|
||||||
|
state.stepHistory = new Uint8Array(state.stepHistory);
|
||||||
|
// when we exit, write the current state
|
||||||
|
E.on('kill', function() {
|
||||||
|
require("Storage").writeJSON(DATA_FILE, state);
|
||||||
|
});
|
||||||
|
|
||||||
// distance between 2 lat and lons, in meters, Mean Earth Radius = 6371km
|
// distance between 2 lat and lons, in meters, Mean Earth Radius = 6371km
|
||||||
// https://www.movable-type.co.uk/scripts/latlong.html
|
// https://www.movable-type.co.uk/scripts/latlong.html
|
||||||
// (Equirectangular approximation)
|
// (Equirectangular approximation)
|
||||||
|
@ -359,9 +369,10 @@ exports.getStats = function(statIDs, options) {
|
||||||
state.notify.time.next = state.startTime + options.notify.time.increment;
|
state.notify.time.next = state.startTime + options.notify.time.increment;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reset();
|
if (!state.active) reset(); // we might already be active
|
||||||
return {
|
return {
|
||||||
stats : stats, state : state,
|
stats : stats,
|
||||||
|
state : state,
|
||||||
start : function() {
|
start : function() {
|
||||||
state.active = true;
|
state.active = true;
|
||||||
reset();
|
reset();
|
||||||
|
|
Loading…
Reference in New Issue