Add maxbpm as a tracked stat in exstats.

pull/1651/head
Salim Blume 2022-04-02 20:54:23 -05:00
parent 172df0dc27
commit fff5ddef67
1 changed files with 16 additions and 0 deletions

View File

@ -15,6 +15,7 @@ print(ExStats.getList());
{name: "Distance", id:"dist"}, {name: "Distance", id:"dist"},
{name: "Steps", id:"step"}, {name: "Steps", id:"step"},
{name: "Heart (BPM)", id:"bpm"}, {name: "Heart (BPM)", id:"bpm"},
{name: "Max BPM", id:"maxbpm"},
{name: "Pace (avr)", id:"pacea"}, {name: "Pace (avr)", id:"pacea"},
{name: "Pace (current)", id:"pacec"}, {name: "Pace (current)", id:"pacec"},
{name: "Cadence", id:"caden"}, {name: "Cadence", id:"caden"},
@ -72,6 +73,7 @@ var state = {
// cadence // steps per minute adjusted if <1 minute // cadence // steps per minute adjusted if <1 minute
// 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
// Notifies: 0 for disabled, otherwise how often to notify in meters, seconds, or steps // Notifies: 0 for disabled, otherwise how often to notify in meters, seconds, or steps
notify: { notify: {
dist: { dist: {
@ -159,6 +161,10 @@ Bangle.on("HRM", function(h) {
if (h.confidence>=60) { if (h.confidence>=60) {
state.BPM = h.bpm; state.BPM = h.bpm;
state.BPMage = 0; state.BPMage = 0;
if (state.maxBPM < h.bpm) {
state.maxBPM = h.bpm;
if (stats["maxbpm"]) stats["maxbpm"].emit("changed",stats["maxbpm"]);
}
if (stats["bpm"]) stats["bpm"].emit("changed",stats["bpm"]); if (stats["bpm"]) stats["bpm"].emit("changed",stats["bpm"]);
} }
}); });
@ -170,6 +176,7 @@ exports.getList = function() {
{name: "Distance", id:"dist"}, {name: "Distance", id:"dist"},
{name: "Steps", id:"step"}, {name: "Steps", id:"step"},
{name: "Heart (BPM)", id:"bpm"}, {name: "Heart (BPM)", id:"bpm"},
{name: "Max BPM", id:"maxbpm"},
{name: "Pace (avg)", id:"pacea"}, {name: "Pace (avg)", id:"pacea"},
{name: "Pace (curr)", id:"pacec"}, {name: "Pace (curr)", id:"pacec"},
{name: "Speed", id:"speed"}, {name: "Speed", id:"speed"},
@ -230,6 +237,14 @@ exports.getStats = function(statIDs, options) {
getString : function() { return state.BPM||"--" }, getString : function() { return state.BPM||"--" },
}; };
} }
if (statIDs.includes("bpm")) {
needHRM = true;
stats["maxbpm"]={
title : "Max BPM",
getValue : function() { return state.maxBPM; },
getString : function() { return state.maxBPM||"--" },
};
}
if (statIDs.includes("pacea")) { if (statIDs.includes("pacea")) {
needGPS = true; needGPS = true;
stats["pacea"]={ stats["pacea"]={
@ -299,6 +314,7 @@ exports.getStats = function(statIDs, options) {
state.curSpeed = 0; state.curSpeed = 0;
state.BPM = 0; state.BPM = 0;
state.BPMage = 0; state.BPMage = 0;
state.maxBPM = 0;
state.notify = options.notify; state.notify = options.notify;
if (options.notify.dist.increment > 0) { if (options.notify.dist.increment > 0) {
state.notify.dist.next = state.distance + options.notify.dist.increment; state.notify.dist.next = state.distance + options.notify.dist.increment;