Heart Rate Zones

Hi all,

For anyone interested in implementing HR zones, I coded the following:

// Create vars
var valueHr = null;
var valueHrZone = null;

// Read user profile & store in vars
var userProfile = Toybox.UserProfile.getProfile();
var userAge = Time.Gregorian.info(Time.now()).year-userProfile.birthYear;
var restHr = userProfile.restingHeartRate;
var maxHr = 221-userAge;

// Store Strava HR upper zone limits in array
var hrRanges = [restHr,0.59*maxHr,0.77*maxHr,0.87*maxHr,0.97*maxHr,maxHr];

function compute(info) {
// Get current HR zone info
if (info.currentHeartRate){
valueHr = info.currentHeartRate;
for(var i=0; i<hrRanges.size();i++){
if(valueHr > hrRanges&& valueHr < hrRanges[i+1]){
valueHrZone = (i+1)+((valueHr-hrRanges)/(hrRanges[i+1]-hrRanges));
}
else if (valueHr < hrRanges[0]){
valueHrZone = 0.0;
}
else if (valueHr > hrRanges[5]){
valueHrZone = 5+((valueHr-hrRanges[4])/(hrRanges[5]-hrRanges[4]));
}
}
}
else{
valueHrZone = 0.0;
}
}[/CODE]

On a related note: I'm getting and setting all my metrics this way in the function "compute(info)" (using if-else statements). Is this good coding practice or is there some better way of handling this?

Cheers,
Lorenzo
  • IMHO - doing these MaxHR-Age is really too basic. But alas - that's as far as what's possible for now.
  • Thanks for your feedback

    Another question: how to I go about debugging these error messages?

    @PC = 0x100003CB
    @PC = 0x100006F2
    TVM ERROR:
    Unexpected Type Error
    Failed invoking <symbol>

    @PC = 0x100003CB
    @PC = 0x100006F2
    TVM ERROR:
    Unexpected Type Error
    Failed invoking <symbol>
  • Thanks for your feedback

    Another question: how to I go about debugging these error messages?

    @PC = 0x100003CB
    @PC = 0x100006F2
    TVM ERROR:
    Unexpected Type Error
    Failed invoking <symbol>

    @PC = 0x100003CB
    @PC = 0x100006F2
    TVM ERROR:
    Unexpected Type Error
    Failed invoking <symbol>


    Are you running a debug version of your .prg? If this is CIQ_LOG.txt, you'll get more detail if you are not running a debug version,

    <appname>.prg.debug.xml (in the bin directory) will help
  • Are you running a debug version of your .prg? If this is CIQ_LOG.txt, you'll get more detail if you are not running a debug version,

    <appname>.prg.debug.xml (in the bin directory) will help

    This is from the CIQ_LOG.txt off of my Fenix (side-loaded), not running a debug version.

    Strangely, I don't see any error messages in the log when running through the simulator.
  • Run a debug version and CIQ_LOG.txt will give you more info. There are difference between real devices and the simulator. And even between different FW versions on real device.
  • Run a debug version and CIQ_LOG.txt will give you more info. There are difference between real devices and the simulator. And even between different FW versions on real device.

    God, it's really hard to find decent info on these matters. Do you know where I can find info on how to make a debug build?

    Thanks in advance
  • From Eclipse, click ConnectIQ > Build Project for Device.
  • Or just set up a run>"run configuration" in Eclipse with project and device, and the .prg will be in the "bin" directory for the project, along with the <name>.prg.debug.xml I mentioned.

    It shows how to do it in the "Monkey C Programmers Guide" that comes with the SDK.
  • Or just set up a run>"run configuration" in Eclipse with project and device, and the .prg will be in the "bin" directory for the project, along with the <name>.prg.debug.xml I mentioned.

    It shows how to do it in the "Monkey C Programmers Guide" that comes with the SDK.

    Alright, I got that going. The XML contains a PCtoLineNum which I'm guessing I have to use to find out what lines are causing a problem. I'm also guessing that these entries from the CIQ_LOG are somehow connected:
    @PC = 0x100003CB
    @PC = 0x100006F2


    I'm not sure how to connect the two though.. Help is much appreciated!
  • If you can reproduce this on the device, the easiest thing to do is to sideload the debug version of the .prg to the watch. CIQ_LOG.txt will then have more info in it.