From d2ec2ce3e61f0ffcf6b8d27d767010132c47372b Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Fri, 28 Jan 2022 09:45:56 +0000 Subject: [PATCH] run 0.04: Use the exstats module, and make what is displayed configurable --- apps/run/ChangeLog | 1 + apps/run/README.md | 10 +++++++++- apps/run/metadata.json | 2 +- apps/run/settings.js | 26 +++++++++----------------- modules/exstats.js | 23 +++++++++++++++++++++++ 5 files changed, 43 insertions(+), 19 deletions(-) diff --git a/apps/run/ChangeLog b/apps/run/ChangeLog index 0df910367..811e3afba 100644 --- a/apps/run/ChangeLog +++ b/apps/run/ChangeLog @@ -2,3 +2,4 @@ 0.02: Set pace format to mm:ss, time format to h:mm:ss, 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 diff --git a/apps/run/README.md b/apps/run/README.md index c455f70e5..10f6bafdb 100644 --- a/apps/run/README.md +++ b/apps/run/README.md @@ -32,7 +32,7 @@ that, and then start the `Run` app. Under `Settings` -> `App` -> `Run` you can change settings for this app. -* `Pace` is the distance that pace should be shown over - 1km, 1 mile, 1/2 Marathon or 1 Maraton +* `Pace` is the distance that pace should be shown over - 1km, 1 mile, 1/2 Marathon or 1 Marathon * `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. If you set it to `-` nothing will be displayed, so you can display only 4 boxes of information 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. * Allow this app to trigger the `Recorder` app on and off directly. * Keep a log of each run's stats (distance/steps/etc) + +## Development + +This app uses the [`exstats` module](/modules/exstats.js). When uploaded via the +app loader, the module is automatically included in the app's source. However +when developing via the IDE the module won't get pulled in by default. + +There are some options to fix this easily - please check out the [modules README.md file](/modules/README.md) diff --git a/apps/run/metadata.json b/apps/run/metadata.json index 4d5e85778..2fd4497f6 100644 --- a/apps/run/metadata.json +++ b/apps/run/metadata.json @@ -1,6 +1,6 @@ { "id": "run", "name": "Run", - "version":"0.03", + "version":"0.04", "description": "Displays distance, time, steps, cadence, pace and more for runners.", "icon": "app.png", "tags": "run,running,fitness,outdoors,gps", diff --git a/apps/run/settings.js b/apps/run/settings.js index 82735df15..91a8b4333 100644 --- a/apps/run/settings.js +++ b/apps/run/settings.js @@ -17,7 +17,7 @@ B6 : "caden", paceLength : 1000 }, storage.readJSON(SETTINGS_FILE, 1) || {}); - function save() { + function saveSettings() { storage.write(SETTINGS_FILE, settings) } @@ -28,31 +28,23 @@ format: v => statsList[v].name, onchange: v => { settings[boxID] = statsIDs[v]; - save(); + saveSettings(); }, } } - var paceNames = ["1000m","1 mile","1/2 Mthn", "Marathon",]; - var paceAmts = [1000,1609,21098,42195]; - E.showMenu({ + var menu = { '': { 'title': 'Run' }, - '< Back': back, - 'Pace': { - min :0, max: paceNames.length-1, - value: Math.max(paceAmts.indexOf(settings.paceLength),0), - format: v => paceNames[v], - onchange: v => { - settings.paceLength = paceAmts[v]; - print(settings); - save(); - }, - }, + '< Back': back + }; + ExStats.appendMenuItems(menu, settings, saveSettings); + Object.assign(menu,{ 'Box 1': getBoxChooser("B1"), 'Box 2': getBoxChooser("B2"), 'Box 3': getBoxChooser("B3"), 'Box 4': getBoxChooser("B4"), 'Box 5': getBoxChooser("B5"), 'Box 6': getBoxChooser("B6"), - }) + }); + E.showMenu(menu); }) diff --git a/modules/exstats.js b/modules/exstats.js index 7e4dd6573..dfeee9042 100644 --- a/modules/exstats.js +++ b/modules/exstats.js @@ -1,5 +1,8 @@ +/* Copyright (c) 2022 Bangle.js contibutors. See the file LICENSE for copying permission. */ /* Exercise Stats module +Take a look at README.md for hints on developing with this library. + Usage ----- @@ -39,6 +42,12 @@ var exs = ExStats.getStats(["dist", "time", "pacea","bpm","step","caden"], optio stop : function, // call to stop exercise } +/// Or you can display a menu where the settings can be configured - these are passed as the 'options' argument of getStats + +var menu = { ... }; +ExStats.appendMenuItems(menu, settings, saveSettingsFunction); +E.showMenu(menu); + */ var state = { active : false, // are we working or not? @@ -237,3 +246,17 @@ exports.getStats = function(statIDs, options) { } }; }; + +exports.appendMenuItems = function(menu, settings, saveSettings) { + var paceNames = ["1000m","1 mile","1/2 Mthn", "Marathon",]; + var paceAmts = [1000,1609,21098,42195]; + menu['Pace'] = { + min :0, max: paceNames.length-1, + value: Math.max(paceAmts.indexOf(settings.paceLength),0), + format: v => paceNames[v], + onchange: v => { + settings.paceLength = paceAmts[v]; + saveSettings(); + }, + }; +};