diff --git a/apps/hrmdataexport/README.md b/apps/hrmdataexport/README.md new file mode 100644 index 000000000..122b7f21e --- /dev/null +++ b/apps/hrmdataexport/README.md @@ -0,0 +1,7 @@ +Extract hrm raw signal data to CSV file +======================================= + +Simple app that will run the heart rate monitor for a defined period of time you set at the start. The max time value is 60 minutes but you can increase this just by changing the value in the app's script code if you wanted to - be mindful that your log file can get large and there are storage limitations if you start trying to log beyond this max. + +The hrm sensor is sampled @50Hz and this app does not do any processing on it, the array is written as-is. There is an example Python script that can process this signal, smooth it and also extract a myriad of heart rate variability metrics using the hrvanalysis library: +https://github.com/jabituyaben/BangleJS-HRM-Signal-Processing \ No newline at end of file diff --git a/apps/hrmdataexport/app-icon.js b/apps/hrmdataexport/app-icon.js new file mode 100644 index 000000000..356be780a --- /dev/null +++ b/apps/hrmdataexport/app-icon.js @@ -0,0 +1,2 @@ +E.toArrayBuffer(atob("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/AA/AAAD/4H/wAAP/8P/8AAf/+f/+AA/A//B/AA+AP8A/AB8AH4B/gB4ADwD/gDwABgH3wDwAAAPjwDwAAAfDwDwDAA+DwDwHgB8DwDwHwD4DwB4D4HwHgB4B8PgHgB8A+fAPgA8Af+APAA+AP8AfAAfAH4A+AAPgDwB8AAPwBgD8AAH4AAH4AAD4AAHwAAB+AAfgAAA/AA/AAAAfgB+AAAAPwD8AAAAH4H4AAAAD8PwAAAAB+fgAAAAA//AAAAAAf+AAAAAAP8AAAAAADwAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")) +} \ No newline at end of file diff --git a/apps/hrmdataexport/app-icon.png b/apps/hrmdataexport/app-icon.png new file mode 100644 index 000000000..6ad50930b Binary files /dev/null and b/apps/hrmdataexport/app-icon.png differ diff --git a/apps/hrmdataexport/app.js b/apps/hrmdataexport/app.js new file mode 100644 index 000000000..e75eb5e44 --- /dev/null +++ b/apps/hrmdataexport/app.js @@ -0,0 +1,97 @@ +var counter = 1; +var logging_started; +var interval; +var value; + +var file = require("Storage").open("hrm_log.csv", "w"); +file.write(""); + +file = require("Storage").open("hrm_log.csv", "a"); + +function update_timer() { + g.clear(); + g.setColor("#00ff7f"); + g.setFont("6x8", 4); + g.setFontAlign(0, 0); // center font + + g.drawString(counter, 120, 120); + g.setFont("6x8", 2); + g.setFontAlign(-1, -1); + g.drawString("-", 220, 200); + g.drawString("+", 220, 40); + g.drawString("GO", 210, 120); + + g.setColor("#ffffff"); + g.setFontAlign(0, 0); // center font + g.drawString("Timer (minutes)", 120, 90); + + g.setFont("6x8", 4); // bitmap font, 8x magnified + + if (!logging_started) + g.flip(); +} + +function btn1Pressed() { + if (!logging_started) { + if (counter < 60) + counter += 1; + else + counter = 1; + update_timer(); + } +} + +function btn3Pressed() { + if (!logging_started) { + if (counter > 1) + counter -= 1; + else + counter = 60; + update_timer(); + } +} + +function btn2Pressed() { + launchtime = 0 | getTime(); + file.write(launchtime + "," + "\n"); + logging_started = true; + counter = counter * 60; + interval = setInterval(countDown, 1000); + Bangle.setHRMPower(1); +} + +function fmtMSS(e) { + var m = Math.floor(e % 3600 / 60).toString().padStart(2, '0'), + s = Math.floor(e % 60).toString().padStart(2, '0'); + return m + ':' + s; +} + +function countDown() { + g.clear(); + counter--; + if (counter == 0) { + Bangle.setHRMPower(0); + clearInterval(interval); + g.drawString("Finished", g.getWidth() / 2, g.getHeight() / 2); + Bangle.buzz(500, 1); + } + else + g.drawString(fmtMSS(counter), g.getWidth() / 2, g.getHeight() / 2); +} + +update_timer(); + +setWatch(btn1Pressed, BTN1, { repeat: true }); +setWatch(btn2Pressed, BTN2, { repeat: true }); +setWatch(btn3Pressed, BTN3, { repeat: true }); + +Bangle.on('HRM', function (hrm) { + for (let i = 0; i < hrm.raw.length; i++) { + value = hrm.raw[i]; + if (value < -2) + value = -2; + if (value > 6) + value = 6; + file.write(value + "," + "\n"); + } +}); \ No newline at end of file