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.