From 2d1a3cec8f5c92fa47fe0671e5689c4261148a00 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sat, 11 Feb 2023 08:40:06 +0000 Subject: [PATCH] btadv: minimum confidence level for HRM --- apps/btadv/app.js | 13 ++++++++++++- apps/btadv/app.ts | 23 ++++++++++++++++++----- typescript/types/other.d.ts | 2 ++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/apps/btadv/app.js b/apps/btadv/app.js index ddc6ba98d..623f777c6 100644 --- a/apps/btadv/app.js +++ b/apps/btadv/app.js @@ -13,11 +13,13 @@ var __assign = (this && this.__assign) || function () { var Layout = require("Layout"); Bangle.loadWidgets(); Bangle.drawWidgets(); +var HRM_MIN_CONFIDENCE = 75; var services = ["0x180d", "0x181a", "0x1819"]; var acc; var bar; var gps; var hrm; +var hrmAny; var mag; var btnsShown = false; var prevBtnsShown = undefined; @@ -126,6 +128,11 @@ var drawInfo = function (force) { y += g.getFontHeight(); drawn = true; } + else if (hrmAny) { + g.drawString("~".concat(hrmAny.bpm, " BPM (").concat(hrmAny.confidence, "%)"), mid, y); + y += g.getFontHeight(); + drawn = true; + } if (mag) { g.drawString("".concat(mag.x, " ").concat(mag.y, " ").concat(mag.z), mid, y); y += g.getFontHeight(); @@ -330,7 +337,11 @@ var updateServices = function () { var onAccel = function (newAcc) { return acc = newAcc; }; var onPressure = function (newBar) { return bar = newBar; }; var onGPS = function (newGps) { return gps = newGps; }; -var onHRM = function (newHrm) { return hrm = newHrm; }; +var onHRM = function (newHrm) { + if (newHrm.confidence >= HRM_MIN_CONFIDENCE) + hrm = newHrm; + hrmAny = newHrm; +}; var onMag = function (newMag) { return mag = newMag; }; var hook = function (enable) { if (enable) { diff --git a/apps/btadv/app.ts b/apps/btadv/app.ts index 4c87c504e..1acea4710 100644 --- a/apps/btadv/app.ts +++ b/apps/btadv/app.ts @@ -13,6 +13,8 @@ const enum Intervals { type Hrm = { bpm: number, confidence: number }; +const HRM_MIN_CONFIDENCE = 75; + // https://github.com/sputnikdev/bluetooth-gatt-parser/blob/master/src/main/resources/gatt/ const enum BleServ { // org.bluetooth.service.heart_rate @@ -82,6 +84,7 @@ let acc: undefined | AccelData; let bar: undefined | PressureData; let gps: undefined | GPSFix; let hrm: undefined | Hrm; +let hrmAny: undefined | Hrm; let mag: undefined | CompassData; let btnsShown = false; let prevBtnsShown: boolean | undefined = undefined; @@ -275,6 +278,12 @@ const drawInfo = (force?: true) => { y += g.getFontHeight(); drawn = true; + } else if (hrmAny) { + g.drawString(`~${hrmAny.bpm} BPM (${hrmAny.confidence}%)`, mid, y); + y += g.getFontHeight(); + + drawn = true; + } if (mag) { @@ -586,11 +595,15 @@ const updateServices = () => { NRF.updateServices(newAdvert); }; -const onAccel = (newAcc: typeof acc) => acc = newAcc; -const onPressure = (newBar: typeof bar) => bar = newBar; -const onGPS = (newGps: typeof gps) => gps = newGps; -const onHRM = (newHrm: typeof hrm) => hrm = newHrm; -const onMag = (newMag: typeof mag) => mag = newMag; +const onAccel = (newAcc: NonNull) => acc = newAcc; +const onPressure = (newBar: NonNull) => bar = newBar; +const onGPS = (newGps: NonNull) => gps = newGps; +const onHRM = (newHrm: NonNull) => { + if (newHrm.confidence >= HRM_MIN_CONFIDENCE) + hrm = newHrm; + hrmAny = newHrm; +}; +const onMag = (newMag: NonNull) => mag = newMag; const hook = (enable: boolean) => { // need to disable for perf reasons, when buttons are shown diff --git a/typescript/types/other.d.ts b/typescript/types/other.d.ts index 8f0d07855..9839286fa 100644 --- a/typescript/types/other.d.ts +++ b/typescript/types/other.d.ts @@ -11,3 +11,5 @@ interface IArguments { type Exclude = T extends U ? never : T; type ReturnType = T extends (...args: any[]) => infer R ? R : never; + +type NonNull = Exclude;