Only buzz on high confidence

master
Markus Deibel 2020-03-29 09:20:26 +02:00
parent 7774b095b9
commit 5507eb04be
3 changed files with 34 additions and 13 deletions

View File

@ -816,7 +816,7 @@
{ "id": "wohrm", { "id": "wohrm",
"name": "Workout HRM", "name": "Workout HRM",
"icon": "app.png", "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.", "description": "Workout heart rate monitor notifies you with a buzz if your heart rate goes above or below the set limits.",
"tags": "hrm,workout", "tags": "hrm,workout",
"type": "app", "type": "app",

View File

@ -1,3 +1,4 @@
0.04: Only buzz on high confidence (>85%)
0.03: Optimized rendering for the background 0.03: Optimized rendering for the background
0.02: Adapted to new App code layout 0.02: Adapted to new App code layout
0.01: Only tested on the emulator. 0.01: Only tested on the emulator.

View File

@ -4,6 +4,10 @@ const Setter = {
UPPER: 'upper', UPPER: 'upper',
LOWER: 'lower' LOWER: 'lower'
}; };
const Confidence = {
NONE
}
const shortBuzzTimeInMs = 50; const shortBuzzTimeInMs = 50;
const longBuzzTimeInMs = 200; const longBuzzTimeInMs = 200;
@ -18,8 +22,8 @@ let limitSetter = Setter.NONE;
let currentHeartRate = 0; let currentHeartRate = 0;
let hrConfidence = -1; let hrConfidence = -1;
let hrOrConfidenceChanged = true; let hrChanged = true;
let confidenceChanged = true;
let setterHighlightTimeout; let setterHighlightTimeout;
@ -76,7 +80,7 @@ function renderLowerLimitBackground() {
function drawTrainingHeartRate() { function drawTrainingHeartRate() {
//Only redraw if the display is on //Only redraw if the display is on
if (Bangle.isLCDOn()) { if (Bangle.isLCDOn()) {
renderButtonIcons();
renderUpperLimit(); renderUpperLimit();
@ -108,7 +112,7 @@ function renderUpperLimit() {
} }
function renderCurrentHeartRate() { function renderCurrentHeartRate() {
if(!hrOrConfidenceChanged) { return; } if(!hrChanged) { return; }
g.setColor(255,255,255); g.setColor(255,255,255);
g.fillRect(45, 110, 165, 150); g.fillRect(45, 110, 165, 150);
@ -120,6 +124,8 @@ function renderCurrentHeartRate() {
//Reset alignment to defaults //Reset alignment to defaults
g.setFontAlign(-1, -1, 0); g.setFontAlign(-1, -1, 0);
hrChanged = false;
} }
function renderLowerLimit() { function renderLowerLimit() {
@ -140,7 +146,7 @@ function renderLowerLimit() {
} }
function renderConfidenceBars(){ function renderConfidenceBars(){
if(!hrOrConfidenceChanged) { return; } if(!confidenceChanged) { return; }
if(hrConfidence >= 85){ if(hrConfidence >= 85){
g.setColor(0, 255, 0); g.setColor(0, 255, 0);
@ -154,6 +160,8 @@ function renderConfidenceBars(){
g.fillRect(45, 110, 55, 150); g.fillRect(45, 110, 55, 150);
g.fillRect(165, 110, 175, 150); g.fillRect(165, 110, 175, 150);
confidenceChanged = false;
} }
function renderButtonIcons() { function renderButtonIcons() {
@ -176,24 +184,33 @@ function renderButtonIcons() {
function buzz() function buzz()
{ {
// Do not buzz if not confident
if(hrConfidence < 85) { return; }
if(currentHeartRate > upperLimit) if(currentHeartRate > upperLimit)
{ {
Bangle.buzz(shortBuzzTimeInMs); Bangle.buzz(shortBuzzTimeInMs);
setTimeout(() => { Bangle.buzz(shortBuzzTimeInMs); }, shortBuzzTimeInMs); setTimeout(() => { Bangle.buzz(shortBuzzTimeInMs); }, shortBuzzTimeInMs+10);
setTimeout(() => { Bangle.buzz(shortBuzzTimeInMs); }, shortBuzzTimeInMs); setTimeout(() => { Bangle.buzz(shortBuzzTimeInMs); }, shortBuzzTimeInMs+10);
} }
if(currentHeartRate < lowerLimit) if(currentHeartRate < lowerLimit)
{ {
Bangle.buzz(longBuzzTimeInMs); Bangle.buzz(longBuzzTimeInMs);
setTimeout(() => { Bangle.buzz(longBuzzTimeInMs); }, longBuzzTimeInMs); setTimeout(() => { Bangle.buzz(longBuzzTimeInMs); }, longBuzzTimeInMs+10);
} }
} }
function onHrm(hrm){ function onHrm(hrm){
hrOrConfidenceChanged = (currentHeartRate !== hrm.bpm || hrConfidence !== hrm.confidence); if(currentHeartRate !== hrm.bpm){
currentHeartRate = hrm.bpm; currentHeartRate = hrm.bpm;
hrConfidence = hrm.confidence; hrChanged = true;
}
if(hrConfidence !== hrm.confidence) {
hrConfidence = hrm.confidence;
confidenceChanged = true;
}
} }
function setLimitSetterToLower() { function setLimitSetterToLower() {
@ -284,6 +301,7 @@ Bangle.on('lcdPower', (on) => {
g.clear(); g.clear();
if (on) { if (on) {
Bangle.drawWidgets(); Bangle.drawWidgets();
renderButtonIcons();
// call your app function here // call your app function here
renderLowerLimitBackground(); renderLowerLimitBackground();
renderUpperLimitBackground(); renderUpperLimitBackground();
@ -307,7 +325,9 @@ Bangle.loadWidgets();
Bangle.drawWidgets(); Bangle.drawWidgets();
//drawTrainingHeartRate(); //drawTrainingHeartRate();
// refesh every sec renderButtonIcons();
renderLowerLimitBackground(); renderLowerLimitBackground();
renderUpperLimitBackground(); renderUpperLimitBackground();
// refesh every sec
setInterval(drawTrainingHeartRate, 1000); setInterval(drawTrainingHeartRate, 1000);