11-16-2020 08:41 - edited 11-16-2020 08:45
11-16-2020 08:41 - edited 11-16-2020 08:45
Hi,
I've been using some code from this watch face (https://github.com/Fitbit/sdk-moment/blob/master/app/simple/hrm.js), to get the heart-zone indication. It is working, but my clockface was declined due to it displaying 'NULL' when I start up my watchface. Apparently it has to be '--', but I cannot seem to find the problem. I tried changing many things in the code, but no success so far.
Hope someone can help me
/*
Returns the Heart Rate BPM, with off-wrist detection.
Callback raised to update your UI.
*/
import { me } from "appbit";
import { display } from "display";
import { HeartRateSensor } from "heart-rate";
import { user } from "user-profile";
let hrm, watchID, hrmCallback;
let lastReading = 0;
let heartRate;
export function initialize(callback) {
if (me.permissions.granted("access_heart_rate") && me.permissions.granted("access_user_profile")) {
hrmCallback = callback;
hrm = new HeartRateSensor();
setupEvents();
start();
lastReading = hrm.timestamp;
} else {
console.log("Denied Heart Rate or User Profile permissions");
callback({
bpm: "???",
zone: "denied",
restingHeartRate: "???"
});
}
}
function getReading() {
if (hrm.timestamp === lastReading) {
heartRate = "--";
} else {
heartRate = hrm.heartRate;
}
lastReading = hrm.timestamp;
hrmCallback({
bpm: heartRate,
zone: user.heartRateZone(hrm.heartRate || 0),
restingHeartRate: user.restingHeartRate
});
}
function setupEvents() {
display.addEventListener("change", function() {
if (display.on) {
start();
} else {
stop();
}
});
}
function start() {
if (!watchID) {
hrm.start();
getReading();
watchID = setInterval(getReading, 1000);
}
}
function stop() {
hrm.stop();
clearInterval(watchID);
watchID = null;
}
11-17-2020 09:26
11-17-2020 09:26
Within your index.gui you can set the default text for the element to "--", and have it be changed by your code on startup. You may also want to test scenarios where the watch is suddenly taken off the hand when screen is on.