1
0
Fork 0

run: Keep run state between runs (allowing you to exit and restart the app)

master
Gordon Williams 2023-02-23 11:00:06 +00:00
parent 7459635362
commit 5ebb56e950
6 changed files with 38 additions and 15 deletions

View File

@ -13,3 +13,4 @@
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.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)

View File

@ -41,6 +41,13 @@ var statIDs = [settings.B1,settings.B2,settings.B3,settings.B4,settings.B5,setti
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
function onStartStop() {
var running = !exs.state.active;
@ -77,12 +84,9 @@ function onStartStop() {
} else {
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
// 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:[
{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:"STOP", id:"status", fillx:1 }
{type:"txt", font:fontHeading, label:"---", id:"status", fillx:1 }
]});
// Now calculate the layout
var layout = new Layout( {
type:"v", c: lc
},{lazy:true, btns:[{ label:"START", cb: onStartStop, id:"button"}]});
},{lazy:true, btns:[{ label:"---", cb: onStartStop, id:"button"}]});
delete lc;
setStatus(exs.state.active);
layout.render();
function configureNotification(stat) {

View File

@ -1,6 +1,6 @@
{ "id": "run",
"name": "Run",
"version":"0.14",
"version":"0.15",
"description": "Displays distance, time, steps, cadence, pace and more for runners.",
"icon": "app.png",
"tags": "run,running,fitness,outdoors,gps",

View File

@ -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.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)
Keep run state between runs (allowing you to exit and restart the app)

View File

@ -52,6 +52,13 @@ let statIDs = [settings.B1,settings.B2,settings.B3,settings.B4,settings.B5,setti
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
function onStartStop() {
let running = !exs.state.active;
@ -88,12 +95,9 @@ function onStartStop() {
} else {
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
// 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:[
{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:"STOP", id:"status", fillx:1 }
{type:"txt", font:fontHeading, label:"---", id:"status", fillx:1 }
]});
// Now calculate the layout
let layout = new Layout( {
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;
setStatus(exs.state.active);
layout.render();
function configureNotification(stat) {

View File

@ -93,6 +93,16 @@ var state = {
// list of active stats (indexed by ID)
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
// https://www.movable-type.co.uk/scripts/latlong.html
// (Equirectangular approximation)
@ -359,9 +369,10 @@ exports.getStats = function(statIDs, options) {
state.notify.time.next = state.startTime + options.notify.time.increment;
}
}
reset();
if (!state.active) reset(); // we might already be active
return {
stats : stats, state : state,
stats : stats,
state : state,
start : function() {
state.active = true;
reset();