Merge pull request #1982 from halemmerich/hrm

HRM raw graph autoscaling
pull/1999/head^2
Gordon Williams 2022-06-27 11:00:26 +01:00 committed by GitHub
commit a9a6efc987
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 11 deletions

View File

@ -7,3 +7,4 @@
0.07: Update scaling for new firmware
0.08: Don't force backlight on/watch unlocked on Bangle 2
0.09: Grey out BPM until confidence is over 50%
0.10: Autoscale raw graph to maximum value seen

View File

@ -4,7 +4,7 @@ if (process.env.HWVERSION == 1) {
}
Bangle.setHRMPower(1);
var hrmInfo, hrmOffset = 0;
var hrmInfo = {}, hrmOffset = 0;
var hrmInterval;
var btm = g.getHeight()-1;
var lastHrmPt = []; // last xy coords we draw a line to
@ -29,19 +29,34 @@ function onHRM(h) {
hrmInterval = setInterval(readHRM,41);
}, 40);
}
updateHrm();
}
Bangle.on('HRM', onHRM);
function updateHrm(){
var px = g.getWidth()/2;
g.setFontAlign(0,0);
g.setFontAlign(0,-1);
g.clearRect(0,24,g.getWidth(),80);
g.setFont("6x8").drawString("Confidence "+hrmInfo.confidence+"%", px, 75);
var str = hrmInfo.bpm;
g.setFont("6x8").drawString("Confidence "+(hrmInfo.confidence || "--")+"%", px, 70);
updateScale();
g.setFontAlign(0,0);
var str = hrmInfo.bpm || "--";
g.setFontVector(40).setColor(hrmInfo.confidence > 50 ? g.theme.fg : "#888").drawString(str,px,45);
px += g.stringWidth(str)/2;
g.setFont("6x8").setColor(g.theme.fg);
g.drawString("BPM",px+15,45);
}
Bangle.on('HRM', onHRM);
function updateScale(){
g.setFontAlign(-1,-1);
g.clearRect(2,70,40,78);
g.setFont("6x8").drawString(scale, 2, 70);
}
var rawMax = 0;
var scale = 2000;
var MID = (g.getHeight()+80)/2;
/* On newer (2v10) firmwares we can subscribe to get
HRM events as they happen */
@ -49,19 +64,27 @@ Bangle.on('HRM-raw', function(v) {
h=v;
hrmOffset++;
if (hrmOffset>g.getWidth()) {
hrmOffset=0;
let thousands = Math.round(rawMax / 1000) * 1000;
if (thousands > scale) scale = thousands;
g.clearRect(0,80,g.getWidth(),g.getHeight());
updateScale();
hrmOffset=0;
lastHrmPt = [-100,0];
}
y = E.clip(btm-(8+v.filt/2000),btm-16,btm);
if (rawMax < v.raw) {
rawMax = v.raw;
}
y = E.clip(btm-(8+v.filt/3000),btm-24,btm);
g.setColor(1,0,0).fillRect(hrmOffset,btm, hrmOffset, y);
y = E.clip(btm - (v.raw/45),84,btm);
y = E.clip(btm - (v.raw/scale*84),84,btm);
g.setColor(g.theme.fg).drawLine(lastHrmPt[0],lastHrmPt[1],hrmOffset, y);
lastHrmPt = [hrmOffset, y];
if (counter !==undefined) {
counter = undefined;
g.clearRect(0,24,g.getWidth(),g.getHeight());
updateHrm();
}
});
@ -76,7 +99,8 @@ function countDown() {
g.clear();
Bangle.loadWidgets();
Bangle.drawWidgets();
g.reset().setFont("6x8",2).setFontAlign(0,0);
g.setColor(g.theme.fg);
g.reset().setFont("6x8",2).setFontAlign(0,-1);
g.drawString("Please wait...",g.getWidth()/2,g.getHeight()/2 - 16);
countDown();

View File

@ -1,7 +1,7 @@
{
"id": "hrm",
"name": "Heart Rate Monitor",
"version": "0.09",
"version": "0.10",
"description": "Measure your heart rate and see live sensor data",
"icon": "heartrate.png",
"tags": "health",