Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

heart rate null

ANSWERED

I have had a couple of reports that the heart rate is not displaying on the clock face i made.

They are saying they see Null or the 2 dashes i have set which is when the timestamp is the same as the previous reading. here is my code:

 

const hrm = new HeartRateSensor();
hrm.start();

hrm.onreading = function() { 
  if (hrm.timestamp === lastReading) {
    heartRate.text = "--";
  } else {
    heartRate.text = hrm.heartRate;
    let bpm = user.heartRateZone(hrm.heartRate || 0);
    let hrmi = document.getElementById("heartRateImage");

    if (bpm === "out-of-range") {
      //console.log('out of range ----');
      hrmi.href = "icons/heart_open.png";
    } else {
      //console.log('in range');
      hrmi.href = "icons/heart_solid.png";
    }
  }
  lastReading = hrm.timestamp;
}
  


//stop heart monitor if screen is off
display.onchange = function() {
  if (display.on) {
    //console.log('screen on');
      hrm.start();
      hrm.onreading();
  } else {
    //console.log('screen off');
      hrm.stop();
  }
}

I'm sure my code is pretty standard ? would it be better to not set the heart sensor as a constant ?

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

I don't think you should be calling onreading() manually. Other than that, it looks ok.

View best answer in original post

Best Answer
0 Votes
2 REPLIES 2

I don't think you should be calling onreading() manually. Other than that, it looks ok.

Best Answer
0 Votes

thanks Jon, i had that as when i was testing it on the simulator i had to manually move the heart rate up on the scale. i assume on the watch it should send a responce so will trigger the change. ill remove it and re-submit it and see if that helps the user.

 

thanks!

Best Answer
0 Votes