aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGravatar Daniel Smith <rdnlsmith@gmail.com> 2019-05-17 21:49:50 -0400
committerGravatar Daniel Smith <rdnlsmith@gmail.com> 2019-05-17 21:53:34 -0400
commit49cf77abc60370e9cec0fa2082a1ff81fc9c2bcc (patch)
tree46484a3ef9aa6c5f980e9078c179e63f1af6310f /app
parent595d70975585f32e917c7a1a56a0201e28f14beb (diff)
Add basic heart rate display
Diffstat (limited to 'app')
-rw-r--r--app/index.js36
1 files changed, 34 insertions, 2 deletions
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