Try and fix issues that causes `exstats` not to be usable without `notify:{...}` defined.
parent
265b3284e1
commit
89ea6d0045
|
|
@ -49,8 +49,26 @@ var menu = { ... };
|
||||||
ExStats.appendMenuItems(menu, settings, saveSettingsFunction);
|
ExStats.appendMenuItems(menu, settings, saveSettingsFunction);
|
||||||
E.showMenu(menu);
|
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
|
// 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 = { ... };
|
var menu = { ... };
|
||||||
ExStats.appendMenuItems(menu, settings, saveSettingsFunction);
|
ExStats.appendMenuItems(menu, settings, saveSettingsFunction);
|
||||||
|
|
@ -76,21 +94,7 @@ var state = {
|
||||||
// BPM // beats per minute
|
// BPM // beats per minute
|
||||||
// BPMage // how many seconds was BPM set?
|
// BPMage // how many seconds was BPM set?
|
||||||
// maxBPM // The highest BPM reached while active
|
// maxBPM // The highest BPM reached while active
|
||||||
// Notifies: 0 for disabled, otherwise how often to notify in meters, seconds, or steps
|
// notify: { }, // 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,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
// list of active stats (indexed by ID)
|
// list of active stats (indexed by ID)
|
||||||
var stats = {};
|
var stats = {};
|
||||||
|
|
@ -209,27 +213,16 @@ exports.getList = function() {
|
||||||
return l;
|
return l;
|
||||||
};
|
};
|
||||||
/** Instantiate the given list of statistic IDs (see comments at top)
|
/** 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) {
|
exports.getStats = function(statIDs, options) {
|
||||||
options = options||{};
|
options = options||{};
|
||||||
options.paceLength = options.paceLength||1000;
|
options.paceLength = options.paceLength||1000;
|
||||||
options.notify.dist.increment = (options.notify && options.notify.dist && options.notify.dist.increment)||0;
|
if (!options.notify) options.notify = {};
|
||||||
options.notify.step.increment = (options.notify && options.notify.step && options.notify.step.increment)||0;
|
["dist","step","time"].forEach(stat => {
|
||||||
options.notify.time.increment = (options.notify && options.notify.time && options.notify.time.increment)||0;
|
if (!options.notify[stat]) options.notify[stat] = {};
|
||||||
|
options.notify[stat].increment = options.notify[stat].increment||0;
|
||||||
|
});
|
||||||
|
state.notify = options.notify;
|
||||||
var needGPS,needHRM,needBaro;
|
var needGPS,needHRM,needBaro;
|
||||||
// ======================
|
// ======================
|
||||||
if (statIDs.includes("time")) {
|
if (statIDs.includes("time")) {
|
||||||
|
|
@ -361,15 +354,12 @@ exports.getStats = function(statIDs, options) {
|
||||||
state.alt = undefined; // barometer altitude (meters)
|
state.alt = undefined; // barometer altitude (meters)
|
||||||
state.alti = 0; // integer ver of state.alt (to avoid repeated 'changed' notifications)
|
state.alti = 0; // integer ver of state.alt (to avoid repeated 'changed' notifications)
|
||||||
state.notify = options.notify;
|
state.notify = options.notify;
|
||||||
if (options.notify.dist.increment > 0) {
|
if (state.notify.dist.increment > 0)
|
||||||
state.notify.dist.next = state.distance + options.notify.dist.increment;
|
state.notify.dist.next = state.distance + state.notify.dist.increment;
|
||||||
}
|
if (state.notify.step.increment > 0)
|
||||||
if (options.notify.step.increment > 0) {
|
state.notify.step.next = state.startSteps + state.notify.step.increment;
|
||||||
state.notify.step.next = state.startSteps + options.notify.step.increment;
|
if (state.notify.time.increment > 0)
|
||||||
}
|
state.notify.time.next = state.startTime + state.notify.time.increment;
|
||||||
if (options.notify.time.increment > 0) {
|
|
||||||
state.notify.time.next = state.startTime + options.notify.time.increment;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!state.active) reset(); // we might already be active
|
if (!state.active) reset(); // we might already be active
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue