From a152ff546ca2d7a83d8518204ee87cf0e2a82066 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Sun, 19 Mar 2023 08:26:51 +0100 Subject: [PATCH] hrmmar: bthrm compatibility - Disable when bthrm is active - Enable fft elim as default --- apps/hrmmar/ChangeLog | 3 +++ apps/hrmmar/README.md | 4 ++-- apps/hrmmar/boot.js | 12 ++++++++---- apps/hrmmar/fftelim.js | 4 ++-- apps/hrmmar/metadata.json | 2 +- apps/hrmmar/settings.js | 2 +- 6 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 apps/hrmmar/ChangeLog diff --git a/apps/hrmmar/ChangeLog b/apps/hrmmar/ChangeLog new file mode 100644 index 000000000..8c418c8fd --- /dev/null +++ b/apps/hrmmar/ChangeLog @@ -0,0 +1,3 @@ +0.01: New App +0.02: Disable when bthrm is active + Enable fft elim as default diff --git a/apps/hrmmar/README.md b/apps/hrmmar/README.md index ff90d9156..2d9612117 100644 --- a/apps/hrmmar/README.md +++ b/apps/hrmmar/README.md @@ -7,5 +7,5 @@ Measurements from the build in PPG-Sensor (Photoplethysmograph) is sensitive to * **MA removal** Select the algorithm to Remove Motion artifacts: - - None: (default) No Motion Artifact removal. - - fft elim: (*experimental*) Remove Motion Artifacts by cutting out the frequencies from the HRM frequency spectrum that are noisy in acceleration spectrum. Under motion this can report a heart rate that is closer to the real one but will fail if motion frequency and heart rate overlap. + - None: No Motion Artifact removal. + - fft elim: (default, *experimental*) Remove Motion Artifacts by cutting out the frequencies from the HRM frequency spectrum that are noisy in acceleration spectrum. Under motion this can report a heart rate that is closer to the real one but will fail if motion frequency and heart rate overlap. diff --git a/apps/hrmmar/boot.js b/apps/hrmmar/boot.js index 52d88c313..4c589bc03 100644 --- a/apps/hrmmar/boot.js +++ b/apps/hrmmar/boot.js @@ -5,8 +5,12 @@ bpm_corrected = bpm; }; + const isInternal = (hrm) => { + return !hrm.src || hrm.src === "int"; + }; + Bangle.on('HRM', (hrm) => { - if (bpm_corrected > 0) { + if (isInternal(hrm) && bpm_corrected > 0) { // replace bpm data in event hrm.bpm_orig = hrm.bpm; hrm.confidence_orig = hrm.confidence; @@ -17,16 +21,16 @@ let run = () => { const settings = Object.assign({ - mAremoval: 0 + mAremoval: 1 }, require("Storage").readJSON("hrmmar.json", true) || {}); // select motion artifact removal algorithm switch(settings.mAremoval) { case 1: - require("hrmfftelim").run(settings, updateHrm); + require("hrmfftelim").run(settings, updateHrm, isInternal); break; } - } + }; // override setHRMPower so we can run our code on HRM enable const oldSetHRMPower = Bangle.setHRMPower; diff --git a/apps/hrmmar/fftelim.js b/apps/hrmmar/fftelim.js index 98b7f33ad..f57489dda 100644 --- a/apps/hrmmar/fftelim.js +++ b/apps/hrmmar/fftelim.js @@ -1,4 +1,4 @@ -exports.run = (settings, updateHrm) => { +exports.run = (settings, updateHrm, isInternal) => { const SAMPLE_RATE = 12.5; const NUM_POINTS = 256; // fft size const ACC_PEAKS = 2; // remove this number of ACC peaks @@ -147,7 +147,7 @@ exports.run = (settings, updateHrm) => { }); Bangle.on('accel', (acc) => { - if (hrmdata !== undefined) { + if (hrmdata !== undefined && isInternal(hrmdata)) { hrmvalues[idx] = hrmdata.filt; accvalues[idx] = acc.x*1000 + acc.y*1000 + acc.z*1000; idx++; diff --git a/apps/hrmmar/metadata.json b/apps/hrmmar/metadata.json index 232ff64a7..fcb2fac5c 100644 --- a/apps/hrmmar/metadata.json +++ b/apps/hrmmar/metadata.json @@ -3,7 +3,7 @@ "name": "HRM Motion Artifacts removal", "shortName":"HRM MA removal", "icon": "app.png", - "version":"0.01", + "version":"0.02", "description": "Removes Motion Artifacts in Bangle.js's heart rate sensor data.", "type": "bootloader", "tags": "health", diff --git a/apps/hrmmar/settings.js b/apps/hrmmar/settings.js index 3c6e62c91..c391f6862 100644 --- a/apps/hrmmar/settings.js +++ b/apps/hrmmar/settings.js @@ -2,7 +2,7 @@ var FILE = "hrmmar.json"; // Load settings var settings = Object.assign({ - mAremoval: 0, + mAremoval: 1, }, require('Storage').readJSON(FILE, true) || {}); function writeSettings() {