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
  • 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.

    Unless you're doing something else, that does not generate a debug binary for the hardware. It seems that you're deploying the debug binary build for the simulated device onto an actual device. It may work on some devices, but it won't work on all of them.
  • You need to pick the proper device in the "run config". What devices does it NOT work on? It should work on all of them - that way you are testing the same binary in the simulator and on the real device.
  • I used 'Build for Device' and side-loaded the app onto my Fenix, ran it and the CIQ_LOG output is exactly the same as what I posted before..

    Any ideas?