1
0
Fork 0

btadv: minimum confidence level for HRM

master
Rob Pilling 2023-02-11 08:40:06 +00:00
parent cd7723eb53
commit 2d1a3cec8f
3 changed files with 32 additions and 6 deletions

View File

@ -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) {

View File

@ -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<typeof acc>) => acc = newAcc;
const onPressure = (newBar: NonNull<typeof bar>) => bar = newBar;
const onGPS = (newGps: NonNull<typeof gps>) => gps = newGps;
const onHRM = (newHrm: NonNull<typeof hrm>) => {
if (newHrm.confidence >= HRM_MIN_CONFIDENCE)
hrm = newHrm;
hrmAny = newHrm;
};
const onMag = (newMag: NonNull<typeof mag>) => mag = newMag;
const hook = (enable: boolean) => {
// need to disable for perf reasons, when buttons are shown

View File

@ -11,3 +11,5 @@ interface IArguments {
type Exclude<T, U> = T extends U ? never : T;
type ReturnType<T> = T extends (...args: any[]) => infer R ? R : never;
type NonNull<T> = Exclude<T, undefined | null>;