Try and fix issues that causes `exstats` not to be usable without `notify:{...}` defined.

pull/3384/head
Gordon Williams 2024-05-09 12:09:56 +01:00
parent 265b3284e1
commit 89ea6d0045
1 changed files with 32 additions and 42 deletions

View File

@ -49,8 +49,26 @@ var menu = { ... };
ExStats.appendMenuItems(menu, settings, saveSettingsFunction);
E.showMenu(menu);
'options' can also include:
options = {
paceLength : meters to measure pace over
notify: {
dist: {
increment: 0 to not notify on distance milestones, otherwise the number of meters to notify after, repeating
},
step: {
increment: 0 to not notify on step milestones, otherwise the number of steps to notify after, repeating
},
time: {
increment: 0 to not notify on time milestones, otherwise the number of milliseconds to notify after, repeating
}
}
}
// Additionally, if your app makes use of the stat notifications, you can display additional menu
// settings for configuring when to notify (note the added line in the example below)W
// settings for configuring when to notify (note the added line in the example below)
var menu = { ... };
ExStats.appendMenuItems(menu, settings, saveSettingsFunction);
@ -76,21 +94,7 @@ var state = {
// BPM // beats per minute
// BPMage // how many seconds was BPM set?
// maxBPM // The highest BPM reached while active
// Notifies: 0 for disabled, otherwise how often to notify in meters, seconds, or steps
notify: {
dist: {
increment: 0,
next: 0,
},
steps: {
increment: 0,
next: 0,
},
time: {
increment: 0,
next: 0,
},
},
// notify: { }, // Notifies: 0 for disabled, otherwise how often to notify in meters, seconds, or steps
};
// list of active stats (indexed by ID)
var stats = {};
@ -209,27 +213,16 @@ exports.getList = function() {
return l;
};
/** Instantiate the given list of statistic IDs (see comments at top)
options = {
paceLength : meters to measure pace over
notify: {
dist: {
increment: 0 to not notify on distance milestones, otherwise the number of meters to notify after, repeating
},
step: {
increment: 0 to not notify on step milestones, otherwise the number of steps to notify after, repeating
},
time: {
increment: 0 to not notify on time milestones, otherwise the number of milliseconds to notify after, repeating
}
}
}
*/
exports.getStats = function(statIDs, options) {
options = options||{};
options.paceLength = options.paceLength||1000;
options.notify.dist.increment = (options.notify && options.notify.dist && options.notify.dist.increment)||0;
options.notify.step.increment = (options.notify && options.notify.step && options.notify.step.increment)||0;
options.notify.time.increment = (options.notify && options.notify.time && options.notify.time.increment)||0;
if (!options.notify) options.notify = {};
["dist","step","time"].forEach(stat => {
if (!options.notify[stat]) options.notify[stat] = {};
options.notify[stat].increment = options.notify[stat].increment||0;
});
state.notify = options.notify;
var needGPS,needHRM,needBaro;
// ======================
if (statIDs.includes("time")) {
@ -361,15 +354,12 @@ exports.getStats = function(statIDs, options) {
state.alt = undefined; // barometer altitude (meters)
state.alti = 0; // integer ver of state.alt (to avoid repeated 'changed' notifications)
state.notify = options.notify;
if (options.notify.dist.increment > 0) {
state.notify.dist.next = state.distance + options.notify.dist.increment;
}
if (options.notify.step.increment > 0) {
state.notify.step.next = state.startSteps + options.notify.step.increment;
}
if (options.notify.time.increment > 0) {
state.notify.time.next = state.startTime + options.notify.time.increment;
}
if (state.notify.dist.increment > 0)
state.notify.dist.next = state.distance + state.notify.dist.increment;
if (state.notify.step.increment > 0)
state.notify.step.next = state.startSteps + state.notify.step.increment;
if (state.notify.time.increment > 0)
state.notify.time.next = state.startTime + state.notify.time.increment;
}
if (!state.active) reset(); // we might already be active
return {