From 5507eb04be552a801699f388ff72a8b552e7acd0 Mon Sep 17 00:00:00 2001 From: Markus Deibel Date: Sun, 29 Mar 2020 09:20:26 +0200 Subject: [PATCH] Only buzz on high confidence --- apps.json | 2 +- apps/wohrm/ChangeLog | 1 + apps/wohrm/app.js | 44 ++++++++++++++++++++++++++++++++------------ 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/apps.json b/apps.json index e5b0ab15e..93fa75524 100644 --- a/apps.json +++ b/apps.json @@ -816,7 +816,7 @@ { "id": "wohrm", "name": "Workout HRM", "icon": "app.png", - "version":"0.03", + "version":"0.04", "description": "Workout heart rate monitor notifies you with a buzz if your heart rate goes above or below the set limits.", "tags": "hrm,workout", "type": "app", diff --git a/apps/wohrm/ChangeLog b/apps/wohrm/ChangeLog index 36c08b9fd..f836f6f71 100644 --- a/apps/wohrm/ChangeLog +++ b/apps/wohrm/ChangeLog @@ -1,3 +1,4 @@ +0.04: Only buzz on high confidence (>85%) 0.03: Optimized rendering for the background 0.02: Adapted to new App code layout 0.01: Only tested on the emulator. diff --git a/apps/wohrm/app.js b/apps/wohrm/app.js index ec048c8a1..2e147251c 100644 --- a/apps/wohrm/app.js +++ b/apps/wohrm/app.js @@ -4,6 +4,10 @@ const Setter = { UPPER: 'upper', LOWER: 'lower' }; + +const Confidence = { + NONE +} const shortBuzzTimeInMs = 50; const longBuzzTimeInMs = 200; @@ -18,8 +22,8 @@ let limitSetter = Setter.NONE; let currentHeartRate = 0; let hrConfidence = -1; -let hrOrConfidenceChanged = true; - +let hrChanged = true; +let confidenceChanged = true; let setterHighlightTimeout; @@ -76,7 +80,7 @@ function renderLowerLimitBackground() { function drawTrainingHeartRate() { //Only redraw if the display is on if (Bangle.isLCDOn()) { - renderButtonIcons(); + renderUpperLimit(); @@ -108,7 +112,7 @@ function renderUpperLimit() { } function renderCurrentHeartRate() { - if(!hrOrConfidenceChanged) { return; } + if(!hrChanged) { return; } g.setColor(255,255,255); g.fillRect(45, 110, 165, 150); @@ -120,6 +124,8 @@ function renderCurrentHeartRate() { //Reset alignment to defaults g.setFontAlign(-1, -1, 0); + + hrChanged = false; } function renderLowerLimit() { @@ -140,7 +146,7 @@ function renderLowerLimit() { } function renderConfidenceBars(){ - if(!hrOrConfidenceChanged) { return; } + if(!confidenceChanged) { return; } if(hrConfidence >= 85){ g.setColor(0, 255, 0); @@ -154,6 +160,8 @@ function renderConfidenceBars(){ g.fillRect(45, 110, 55, 150); g.fillRect(165, 110, 175, 150); + + confidenceChanged = false; } function renderButtonIcons() { @@ -176,24 +184,33 @@ function renderButtonIcons() { function buzz() { + // Do not buzz if not confident + if(hrConfidence < 85) { return; } + if(currentHeartRate > upperLimit) { Bangle.buzz(shortBuzzTimeInMs); - setTimeout(() => { Bangle.buzz(shortBuzzTimeInMs); }, shortBuzzTimeInMs); - setTimeout(() => { Bangle.buzz(shortBuzzTimeInMs); }, shortBuzzTimeInMs); + setTimeout(() => { Bangle.buzz(shortBuzzTimeInMs); }, shortBuzzTimeInMs+10); + setTimeout(() => { Bangle.buzz(shortBuzzTimeInMs); }, shortBuzzTimeInMs+10); } if(currentHeartRate < lowerLimit) { Bangle.buzz(longBuzzTimeInMs); - setTimeout(() => { Bangle.buzz(longBuzzTimeInMs); }, longBuzzTimeInMs); + setTimeout(() => { Bangle.buzz(longBuzzTimeInMs); }, longBuzzTimeInMs+10); } } function onHrm(hrm){ - hrOrConfidenceChanged = (currentHeartRate !== hrm.bpm || hrConfidence !== hrm.confidence); - currentHeartRate = hrm.bpm; - hrConfidence = hrm.confidence; + if(currentHeartRate !== hrm.bpm){ + currentHeartRate = hrm.bpm; + hrChanged = true; + } + + if(hrConfidence !== hrm.confidence) { + hrConfidence = hrm.confidence; + confidenceChanged = true; + } } function setLimitSetterToLower() { @@ -284,6 +301,7 @@ Bangle.on('lcdPower', (on) => { g.clear(); if (on) { Bangle.drawWidgets(); + renderButtonIcons(); // call your app function here renderLowerLimitBackground(); renderUpperLimitBackground(); @@ -307,7 +325,9 @@ Bangle.loadWidgets(); Bangle.drawWidgets(); //drawTrainingHeartRate(); -// refesh every sec +renderButtonIcons(); renderLowerLimitBackground(); renderUpperLimitBackground(); + +// refesh every sec setInterval(drawTrainingHeartRate, 1000);