Help with Heart Rate on Watch Face

What is the best method to show the heart rate on a watch face? Can someone point me in the right direction?

I have selected the User Profile plus written the following code onto the view.mc file.

function onUpdate(dc) {

View.onUpdate(dc);

var actInfo  = Act.getActivityInfo();

var devStat = System.getDeviceSettings();

var heartRate = 0;

if (ActivityMonitor has :getHeartRateHistory) {

  var hrHist =  ActivityMonitor.getHeartRateHistory(1, true);

  heartRate = hrHist.next().heartRate;

} else {

  heartRate = null;

}

  • No worries.

    If the simulator says "null" then the device will say "null".

    It's impossible for anyone to say why your code is continuing to display "null" without looking at your exact code. I can say that this will happen in two cases:

    1) When the value you are displaying is (originally) the null value, as null will be converted to the literal string "null"

    2) When the value you are displaying is (originally) the literal string "null"

    It seems very likely that 1) is the case and not 2). (None of the values from the Connect IQ API are going to be the literal string "null").

    In the code I provided, you'll note that if heartRate is null, it will be changed to "--" before it's displayed, so it doesn't seem possible for the user to see "null" unless there's something else going on in your code

    If you want the user to see nothing, use the empty string ("") instead of ("--").

  • I was able to fix the display to read hr or not if "null". Thank you much!

    Now I have to figure out how to keep the heart bitmap from bouncing from device to device, if thats possible. if you have any guidance to stop the bouncing it'll be appreciated.

    This is the code I am currently using:

    heart = Ui.loadResource(Rez.Drawables.heart);

    dc.drawBitmap(dw/1-b_width, dh / 11, heart);