simple current heart rate for vivoactive hr

anyone have some simple example code, just the current heartrate will due.

tia
  • You can't get the real-time HR, but what you can do is get the newest reading on devices with a oHRM.

    here's a cut+paste of code that does it by getting the HR History from the ActivityMonitor

    var hrh=ActMon.getHeartRateHistory(1,true);
    var hrs=hrh.next();
    if(hrs!=null && hrs.heartRate!=ActMon.INVALID_HR_SAMPLE) {
    hr=hrs.heartRate.toString();
    }
    else {hr="--";}
    dc.drawText(centerW,85,Gfx.FONT_NUMBER_HOT,hr,Gfx.TEXT_JUSTIFY_CENTER);


    oh, you should be able to check if the watch has what's needed with:

    if(ActivityMonitor has :HeartRateIterator) {
  • then what does this refer to....

    /code
    info.currentHeartRate != null ? info.currentHeartRate : 0;
    /code
  • Sorry, I thought you were talking about a watchface, but it looks like you're talking a data field...

    "info" is passed to compute() in a DF, and it's actually Activity.Info. Yes, that will give you the HR in a DF when recording has started...

    What are you writing where you want to see the HR? Watchface, widget, watch-app or datafield?
  • oh, you should be able to check if the watch has what's needed with:

    if(ActivityMonitor has :HeartRateIterator) {


    Does this work in the simulator?
    Seems that the simulator uses a VM that represent the full spectrum of features across all devices, not the one being simulated.
    I was simulating a non-whr device and it returns true.
  • In the sim, it's always true, regardless of the device simulated, so to test it, you have to test on a real device that doesn't have it.
  • In the sim, it's always true, regardless of the device simulated, so to test it, you have to test on a real device that doesn't have it.


    Thanks for the confirmation.
  • Hermo, just to reconfirm this, I took my Simple Heart watchface and added the va as a target, and re-checked the code on a va and va-hr... It detects the oHRM correctly. (on 1.2.x VMs), and in the sim, it thinks there's a oHRM on the va in the sim...
  • We don't fully match feature-for-feature in the sim with each device, but we have a ticket open to do more of this. I know it would definitely make it easier to test device-specific items when hardware isn't readily available.