Beginner: trying to develop data field

Former Member
Former Member
First of all, I'm new to the forums, so if I posted this not where I should, excuse me.
Now, I recently wanted to learn to make my own datafields for cycling, specifically to be used on an edge 520. My programming experience before is basic C# from university, so don't laugh at me please :)
I'm having trouble with accessing activity data when calculating avergae VAM of the previous lap. Here's the code:

using Toybox.WatchUi;
using Toybox.Math;


class LastLapVAMView extends WatchUi.SimpleDataField
{
var laptime;
var lapelevation;
var cumulativeelev;
var cumulativetime;
var result;


function initialize()
{
SimpleDataField.initialize();
label = "Last VAM";
laptime = 0;
lapelevation = 0;
cumulativetime = 0;
cumulativeelev = 0;
result = 0;
}

// The given info object contains all the current workout
// information. Calculate a value and return it in this method.
// Note that compute() and onUpdate() are asynchronous, and there is no
// guarantee that compute() will be called before onUpdate().

function onTimerLap(info)
{

//lap values as difference between current elapsed and previous total
lapelevation = info.totalAscent - cumulativeelev;
laptime = info.elapsedTime - cumulativetime;
result = lapelevation * 3600 * 1000 / laptime;
//time is measured in miliseconds, calculated to match VAM in m/h

cumulativeelev = info.totalAscent;
cumulativetime = info.elapsedTime;
//set cumulative values to current elapsed

}
function compute(info)
{

return result;
}
}


I also tried leaving onTimerLap() without parameters and use Activity.elapsedTime instead, but it didn't work. Any hints on what I'm doing wrong are greatly appreciated.
  • The data that's on the Activity info structure is passed as the "info" parameter to compute, so that's where you may want to do the calculation.

    onTimerLap() is only called when a lap is manually marked or there's an auto lap, and it doesn't take a parameter.

    If you do want to do this only on a lap, you can use Activity.getActivityInfo() within onTimerLap() to get the same thing that's passed to compute.
  • Former Member
    Former Member over 6 years ago
    The data that's on the Activity info structure is passed as the "info" parameter to compute, so that's where you may want to do the calculation.

    onTimerLap() is only called when a lap is manually marked or there's an auto lap, and it doesn't take a parameter.

    If you do want to do this only on a lap, you can use Activity.getActivityInfo() within onTimerLap() to get the same thing that's passed to compute.


    thanks, this fixed it!