Skip to content

Commit d2ec2ce

Browse files
committed
run 0.04: Use the exstats module, and make what is displayed configurable
1 parent 30d0383 commit d2ec2ce

File tree

5 files changed

+43
-19
lines changed

5 files changed

+43
-19
lines changed

apps/run/ChangeLog

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
0.02: Set pace format to mm:ss, time format to h:mm:ss,
33
added settings to opt out of GPS and HRM
44
0.03: Fixed distance calculation, tested against Garmin Etrex, Amazfit GTS 2
5+
0.04: Use the exstats module, and make what is displayed configurable

apps/run/README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ that, and then start the `Run` app.
3232

3333
Under `Settings` -> `App` -> `Run` you can change settings for this app.
3434

35-
* `Pace` is the distance that pace should be shown over - 1km, 1 mile, 1/2 Marathon or 1 Maraton
35+
* `Pace` is the distance that pace should be shown over - 1km, 1 mile, 1/2 Marathon or 1 Marathon
3636
* `Box 1/2/3/4/5/6` are what should be shown in each of the 6 boxes on the display. From the top left, down.
3737
If you set it to `-` nothing will be displayed, so you can display only 4 boxes of information
3838
if you wish by setting the last 2 boxes to `-`.
@@ -41,3 +41,11 @@ Under `Settings` -> `App` -> `Run` you can change settings for this app.
4141

4242
* Allow this app to trigger the `Recorder` app on and off directly.
4343
* Keep a log of each run's stats (distance/steps/etc)
44+
45+
## Development
46+
47+
This app uses the [`exstats` module](/modules/exstats.js). When uploaded via the
48+
app loader, the module is automatically included in the app's source. However
49+
when developing via the IDE the module won't get pulled in by default.
50+
51+
There are some options to fix this easily - please check out the [modules README.md file](/modules/README.md)

apps/run/metadata.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{ "id": "run",
22
"name": "Run",
3-
"version":"0.03",
3+
"version":"0.04",
44
"description": "Displays distance, time, steps, cadence, pace and more for runners.",
55
"icon": "app.png",
66
"tags": "run,running,fitness,outdoors,gps",

apps/run/settings.js

+9-17
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
B6 : "caden",
1818
paceLength : 1000
1919
}, storage.readJSON(SETTINGS_FILE, 1) || {});
20-
function save() {
20+
function saveSettings() {
2121
storage.write(SETTINGS_FILE, settings)
2222
}
2323

@@ -28,31 +28,23 @@
2828
format: v => statsList[v].name,
2929
onchange: v => {
3030
settings[boxID] = statsIDs[v];
31-
save();
31+
saveSettings();
3232
},
3333
}
3434
}
3535

36-
var paceNames = ["1000m","1 mile","1/2 Mthn", "Marathon",];
37-
var paceAmts = [1000,1609,21098,42195];
38-
E.showMenu({
36+
var menu = {
3937
'': { 'title': 'Run' },
40-
'< Back': back,
41-
'Pace': {
42-
min :0, max: paceNames.length-1,
43-
value: Math.max(paceAmts.indexOf(settings.paceLength),0),
44-
format: v => paceNames[v],
45-
onchange: v => {
46-
settings.paceLength = paceAmts[v];
47-
print(settings);
48-
save();
49-
},
50-
},
38+
'< Back': back
39+
};
40+
ExStats.appendMenuItems(menu, settings, saveSettings);
41+
Object.assign(menu,{
5142
'Box 1': getBoxChooser("B1"),
5243
'Box 2': getBoxChooser("B2"),
5344
'Box 3': getBoxChooser("B3"),
5445
'Box 4': getBoxChooser("B4"),
5546
'Box 5': getBoxChooser("B5"),
5647
'Box 6': getBoxChooser("B6"),
57-
})
48+
});
49+
E.showMenu(menu);
5850
})

modules/exstats.js

+23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
/* Copyright (c) 2022 Bangle.js contibutors. See the file LICENSE for copying permission. */
12
/* Exercise Stats module
23
4+
Take a look at README.md for hints on developing with this library.
5+
36
Usage
47
-----
58
@@ -39,6 +42,12 @@ var exs = ExStats.getStats(["dist", "time", "pacea","bpm","step","caden"], optio
3942
stop : function, // call to stop exercise
4043
}
4144
45+
/// Or you can display a menu where the settings can be configured - these are passed as the 'options' argument of getStats
46+
47+
var menu = { ... };
48+
ExStats.appendMenuItems(menu, settings, saveSettingsFunction);
49+
E.showMenu(menu);
50+
4251
*/
4352
var state = {
4453
active : false, // are we working or not?
@@ -237,3 +246,17 @@ exports.getStats = function(statIDs, options) {
237246
}
238247
};
239248
};
249+
250+
exports.appendMenuItems = function(menu, settings, saveSettings) {
251+
var paceNames = ["1000m","1 mile","1/2 Mthn", "Marathon",];
252+
var paceAmts = [1000,1609,21098,42195];
253+
menu['Pace'] = {
254+
min :0, max: paceNames.length-1,
255+
value: Math.max(paceAmts.indexOf(settings.paceLength),0),
256+
format: v => paceNames[v],
257+
onchange: v => {
258+
settings.paceLength = paceAmts[v];
259+
saveSettings();
260+
},
261+
};
262+
};

0 commit comments

Comments
 (0)