From 49cf77abc60370e9cec0fa2082a1ff81fc9c2bcc Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Fri, 17 May 2019 21:49:50 -0400 Subject: Add basic heart rate display --- app/index.js | 36 +++++++++++++++++++++++++++++++-- package.json | 4 +++- resources/dates/0.png | Bin 506 -> 0 bytes resources/dates/1.png | Bin 2008 -> 0 bytes resources/dates/2.png | Bin 456 -> 0 bytes resources/dates/3.png | Bin 418 -> 0 bytes resources/dates/4.png | Bin 291 -> 0 bytes resources/dates/5.png | Bin 391 -> 0 bytes resources/dates/6.png | Bin 531 -> 0 bytes resources/dates/7.png | Bin 215 -> 0 bytes resources/dates/8.png | Bin 523 -> 0 bytes resources/dates/9.png | Bin 537 -> 0 bytes resources/dates/fri.png | Bin 3547 -> 0 bytes resources/dates/mon.png | Bin 755 -> 0 bytes resources/dates/sat.png | Bin 4152 -> 0 bytes resources/dates/sun.png | Bin 4386 -> 0 bytes resources/dates/thu.png | Bin 2905 -> 0 bytes resources/dates/tue.png | Bin 3665 -> 0 bytes resources/dates/wed.png | Bin 815 -> 0 bytes resources/icons/stat_hr_solid_24px.png | Bin 0 -> 351 bytes resources/index.gui | 12 ++++++++--- resources/quantifier/0.png | Bin 0 -> 506 bytes resources/quantifier/1.png | Bin 0 -> 2008 bytes resources/quantifier/2.png | Bin 0 -> 456 bytes resources/quantifier/3.png | Bin 0 -> 418 bytes resources/quantifier/4.png | Bin 0 -> 291 bytes resources/quantifier/5.png | Bin 0 -> 391 bytes resources/quantifier/6.png | Bin 0 -> 531 bytes resources/quantifier/7.png | Bin 0 -> 215 bytes resources/quantifier/8.png | Bin 0 -> 523 bytes resources/quantifier/9.png | Bin 0 -> 537 bytes resources/quantifier/fri.png | Bin 0 -> 3547 bytes resources/quantifier/mon.png | Bin 0 -> 755 bytes resources/quantifier/sat.png | Bin 0 -> 4152 bytes resources/quantifier/sun.png | Bin 0 -> 4386 bytes resources/quantifier/thu.png | Bin 0 -> 2905 bytes resources/quantifier/tue.png | Bin 0 -> 3665 bytes resources/quantifier/wed.png | Bin 0 -> 815 bytes 38 files changed, 46 insertions(+), 6 deletions(-) delete mode 100644 resources/dates/0.png delete mode 100644 resources/dates/1.png delete mode 100644 resources/dates/2.png delete mode 100644 resources/dates/3.png delete mode 100644 resources/dates/4.png delete mode 100644 resources/dates/5.png delete mode 100644 resources/dates/6.png delete mode 100644 resources/dates/7.png delete mode 100644 resources/dates/8.png delete mode 100644 resources/dates/9.png delete mode 100644 resources/dates/fri.png delete mode 100644 resources/dates/mon.png delete mode 100644 resources/dates/sat.png delete mode 100644 resources/dates/sun.png delete mode 100644 resources/dates/thu.png delete mode 100644 resources/dates/tue.png delete mode 100644 resources/dates/wed.png create mode 100644 resources/icons/stat_hr_solid_24px.png create mode 100644 resources/quantifier/0.png create mode 100644 resources/quantifier/1.png create mode 100644 resources/quantifier/2.png create mode 100644 resources/quantifier/3.png create mode 100644 resources/quantifier/4.png create mode 100644 resources/quantifier/5.png create mode 100644 resources/quantifier/6.png create mode 100644 resources/quantifier/7.png create mode 100644 resources/quantifier/8.png create mode 100644 resources/quantifier/9.png create mode 100644 resources/quantifier/fri.png create mode 100644 resources/quantifier/mon.png create mode 100644 resources/quantifier/sat.png create mode 100644 resources/quantifier/sun.png create mode 100644 resources/quantifier/thu.png create mode 100644 resources/quantifier/tue.png create mode 100644 resources/quantifier/wed.png diff --git a/app/index.js b/app/index.js index 6c8d4cc..cc64479 100644 --- a/app/index.js +++ b/app/index.js @@ -5,6 +5,8 @@ import * as fs from "fs"; import * as messaging from "messaging"; import { preferences } from "user-settings"; import * as util from "./utils"; +import { HeartRateSensor } from "heart-rate"; +import { display } from "display"; // const SETTINGS_TYPE = "cbor"; // const SETTINGS_FILE = "settings.cbor"; @@ -23,6 +25,11 @@ let day = document.getElementById("day"); let date1 = document.getElementById("date1"); let date2 = document.getElementById("date2"); +// Heart Rate +let hr1 = document.getElementById("hr1"); +let hr2 = document.getElementById("hr2"); +let hr3 = document.getElementById("hr3"); + clock.granularity = "seconds"; clock.ontick = evt => { @@ -50,6 +57,21 @@ clock.ontick = evt => { setMins(minute); } +if (HeartRateSensor && me.permissions.granted("access_heart_rate")) { + let hrm = new HeartRateSensor({ frequency: 1 }); + hrm.addEventListener("reading", () => { + setHeartRate(hrm.heartRate); + }); + display.addEventListener("change", () => { + display.on ? hrm.start() : hrm.stop(); + }); + hrm.start(); +} else { + hr1.style.visibility = "hidden"; + hr2.style.visibility = "hidden"; + hr3.style.visibility = "hidden"; +} + // Apply theme colors to elements function applyTheme(background, foreground) { let items = document.getElementsByClassName("background"); @@ -87,17 +109,27 @@ function setDay(val) { day.image = getDayImg(val); } +function setHeartRate(val) { + drawDateDigit(val % 10, hr3); + val = Math.floor(val / 10); + + drawDateDigit(val % 10, hr2); + val = Math.floor(val / 10); + + drawDateDigit(val % 10, hr1); +} + function drawDigit(val, place) { place.image = `numerals/${val}.png`; } function drawDateDigit(val, place) { - place.image = `dates/${val}.png` + place.image = `quantifier/${val}.png` } function getDayImg(index) { let days = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"]; - return `dates/${days[index]}.png`; + return `quantifier/${days[index]}.png`; } // Listen for the onmessage event diff --git a/package.json b/package.json index a319dc5..b7c3c18 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,9 @@ "appDisplayName": "CPU", "iconFile": "resources/icon.png", "wipeColor": "#8bc34a", - "requestedPermissions": [], + "requestedPermissions": [ + "access_heart_rate" + ], "buildTargets": [ "meson", "gemini" diff --git a/resources/dates/0.png b/resources/dates/0.png deleted file mode 100644 index 519fa91..0000000 Binary files a/resources/dates/0.png and /dev/null differ diff --git a/resources/dates/1.png b/resources/dates/1.png deleted file mode 100644 index cd072cf..0000000 Binary files a/resources/dates/1.png and /dev/null differ diff --git a/resources/dates/2.png b/resources/dates/2.png deleted file mode 100644 index 0dac9e1..0000000 Binary files a/resources/dates/2.png and /dev/null differ diff --git a/resources/dates/3.png b/resources/dates/3.png deleted file mode 100644 index 8440537..0000000 Binary files a/resources/dates/3.png and /dev/null differ diff --git a/resources/dates/4.png b/resources/dates/4.png deleted file mode 100644 index 0968921..0000000 Binary files a/resources/dates/4.png and /dev/null differ diff --git a/resources/dates/5.png b/resources/dates/5.png deleted file mode 100644 index d0bfe7d..0000000 Binary files a/resources/dates/5.png and /dev/null differ diff --git a/resources/dates/6.png b/resources/dates/6.png deleted file mode 100644 index 413d6fe..0000000 Binary files a/resources/dates/6.png and /dev/null differ diff --git a/resources/dates/7.png b/resources/dates/7.png deleted file mode 100644 index 7d0ec4d..0000000 Binary files a/resources/dates/7.png and /dev/null differ diff --git a/resources/dates/8.png b/resources/dates/8.png deleted file mode 100644 index afc1f42..0000000 Binary files a/resources/dates/8.png and /dev/null differ diff --git a/resources/dates/9.png b/resources/dates/9.png deleted file mode 100644 index d4f1aa1..0000000 Binary files a/resources/dates/9.png and /dev/null differ diff --git a/resources/dates/fri.png b/resources/dates/fri.png deleted file mode 100644 index 72747ac..0000000 Binary files a/resources/dates/fri.png and /dev/null differ diff --git a/resources/dates/mon.png b/resources/dates/mon.png deleted file mode 100644 index c86e423..0000000 Binary files a/resources/dates/mon.png and /dev/null differ diff --git a/resources/dates/sat.png b/resources/dates/sat.png deleted file mode 100644 index 870d692..0000000 Binary files a/resources/dates/sat.png and /dev/null differ diff --git a/resources/dates/sun.png b/resources/dates/sun.png deleted file mode 100644 index 7981730..0000000 Binary files a/resources/dates/sun.png and /dev/null differ diff --git a/resources/dates/thu.png b/resources/dates/thu.png deleted file mode 100644 index 32bc6be..0000000 Binary files a/resources/dates/thu.png and /dev/null differ diff --git a/resources/dates/tue.png b/resources/dates/tue.png deleted file mode 100644 index f527d0f..0000000 Binary files a/resources/dates/tue.png and /dev/null differ diff --git a/resources/dates/wed.png b/resources/dates/wed.png deleted file mode 100644 index 2860182..0000000 Binary files a/resources/dates/wed.png and /dev/null differ diff --git a/resources/icons/stat_hr_solid_24px.png b/resources/icons/stat_hr_solid_24px.png new file mode 100644 index 0000000..4b6a20f Binary files /dev/null and b/resources/icons/stat_hr_solid_24px.png differ diff --git a/resources/index.gui b/resources/index.gui index 5c83b1d..a54b30d 100644 --- a/resources/index.gui +++ b/resources/index.gui @@ -1,7 +1,7 @@ - - - + + + @@ -9,4 +9,10 @@ + + + + + + diff --git a/resources/quantifier/0.png b/resources/quantifier/0.png new file mode 100644 index 0000000..519fa91 Binary files /dev/null and b/resources/quantifier/0.png differ diff --git a/resources/quantifier/1.png b/resources/quantifier/1.png new file mode 100644 index 0000000..cd072cf Binary files /dev/null and b/resources/quantifier/1.png differ diff --git a/resources/quantifier/2.png b/resources/quantifier/2.png new file mode 100644 index 0000000..0dac9e1 Binary files /dev/null and b/resources/quantifier/2.png differ diff --git a/resources/quantifier/3.png b/resources/quantifier/3.png new file mode 100644 index 0000000..8440537 Binary files /dev/null and b/resources/quantifier/3.png differ diff --git a/resources/quantifier/4.png b/resources/quantifier/4.png new file mode 100644 index 0000000..0968921 Binary files /dev/null and b/resources/quantifier/4.png differ diff --git a/resources/quantifier/5.png b/resources/quantifier/5.png new file mode 100644 index 0000000..d0bfe7d Binary files /dev/null and b/resources/quantifier/5.png differ diff --git a/resources/quantifier/6.png b/resources/quantifier/6.png new file mode 100644 index 0000000..413d6fe Binary files /dev/null and b/resources/quantifier/6.png differ diff --git a/resources/quantifier/7.png b/resources/quantifier/7.png new file mode 100644 index 0000000..7d0ec4d Binary files /dev/null and b/resources/quantifier/7.png differ diff --git a/resources/quantifier/8.png b/resources/quantifier/8.png new file mode 100644 index 0000000..afc1f42 Binary files /dev/null and b/resources/quantifier/8.png differ diff --git a/resources/quantifier/9.png b/resources/quantifier/9.png new file mode 100644 index 0000000..d4f1aa1 Binary files /dev/null and b/resources/quantifier/9.png differ diff --git a/resources/quantifier/fri.png b/resources/quantifier/fri.png new file mode 100644 index 0000000..72747ac Binary files /dev/null and b/resources/quantifier/fri.png differ diff --git a/resources/quantifier/mon.png b/resources/quantifier/mon.png new file mode 100644 index 0000000..c86e423 Binary files /dev/null and b/resources/quantifier/mon.png differ diff --git a/resources/quantifier/sat.png b/resources/quantifier/sat.png new file mode 100644 index 0000000..870d692 Binary files /dev/null and b/resources/quantifier/sat.png differ diff --git a/resources/quantifier/sun.png b/resources/quantifier/sun.png new file mode 100644 index 0000000..7981730 Binary files /dev/null and b/resources/quantifier/sun.png differ diff --git a/resources/quantifier/thu.png b/resources/quantifier/thu.png new file mode 100644 index 0000000..32bc6be Binary files /dev/null and b/resources/quantifier/thu.png differ diff --git a/resources/quantifier/tue.png b/resources/quantifier/tue.png new file mode 100644 index 0000000..f527d0f Binary files /dev/null and b/resources/quantifier/tue.png differ diff --git a/resources/quantifier/wed.png b/resources/quantifier/wed.png new file mode 100644 index 0000000..2860182 Binary files /dev/null and b/resources/quantifier/wed.png differ -- cgit v1.2.3