Skip to content

Commit ab97a80

Browse files
authored
Merge pull request #4066 from ruvilonix/master
Recorder: Use average of HR readings
2 parents ba3df4f + 64c6652 commit ab97a80

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

apps/recorder/ChangeLog

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,6 @@
6161
0.47: Fix 'blip' on speed map on some recordings
6262
Ensure Battery voltage is only stored to 0.01v
6363
Add graphs for Steps+Battery
64-
0.48: Add ability to log average acceleration values
64+
0.48: Add ability to log average acceleration values
65+
0.49: Log average high confidence (>=80) HR reading for each interval, instead of logging the last
66+
reading. If none pass confidence threshold, fall back to highest low confidence reading.

apps/recorder/lib.js

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,45 @@ exports.getRecorders = function() {
6161
};
6262
},
6363
hrm:function() {
64-
var bpm = "", bpmConfidence = "", src="";
64+
const CONFIDENCE_THRESHOLD = 80;
65+
var avgBpm = 0, avgBpmConfidence = 0, src="", nAvgReadings=0, lowConfBpm=null, lowConfBpmConfidence=-1;
66+
6567
function onHRM(h) {
66-
bpmConfidence = h.confidence;
67-
bpm = h.bpm;
68+
let newBpmConfidence = h.confidence;
69+
let newBpm = h.bpm;
6870
src = h.src;
71+
72+
if (newBpmConfidence >= CONFIDENCE_THRESHOLD){
73+
nAvgReadings++;
74+
avgBpm = avgBpm + (newBpm-avgBpm)/nAvgReadings;
75+
avgBpmConfidence = avgBpmConfidence + (newBpmConfidence-avgBpmConfidence)/nAvgReadings;
76+
77+
} else if (newBpmConfidence > lowConfBpmConfidence) {
78+
lowConfBpmConfidence = newBpmConfidence;
79+
lowConfBpm = newBpm;
80+
}
6981
}
82+
7083
return {
7184
name : "HR",
7285
fields : ["Heartrate", "Confidence", "Source"],
7386
getValues : () => {
74-
var r = [bpm,bpmConfidence,src];
75-
bpm = ""; bpmConfidence = ""; src="";
87+
let r;
88+
89+
if (nAvgReadings === 0) {
90+
if (lowConfBpm === null) r = ["","",""];
91+
else r = [lowConfBpm,lowConfBpmConfidence,src];
92+
} else {
93+
r = [Math.round(avgBpm),Math.round(avgBpmConfidence),src];
94+
}
95+
96+
avgBpm = 0;
97+
avgBpmConfidence = 0;
98+
nAvgReadings=0;
99+
lowConfBpm=null;
100+
lowConfBpmConfidence=-1;
101+
src="";
102+
76103
return r;
77104
},
78105
start : () => {
@@ -384,4 +411,4 @@ exports.isRecording = function() {
384411
return !!writeSetup;
385412
};
386413

387-
exports.reload({noUpdateWidget:true});
414+
exports.reload({noUpdateWidget:true});

apps/recorder/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "recorder",
33
"name": "Recorder",
44
"shortName": "Recorder",
5-
"version": "0.48",
5+
"version": "0.49",
66
"author": "bobrippling",
77
"description": "Record GPS position, heart rate and more in the background, then download to your PC.",
88
"icon": "app.png",

0 commit comments

Comments
 (0)