wired behavior on lap end

consider the below data fields:
1.
field created by "build for device wizard"
function compute(info) {
if(info has :elapsedDistance ) {

if(info.elapsedDistance != 0 && info.elapsedDistance != null && mElapsedDistance != info.elapsedDistance) {
mElapsedDistance = info.elapsedDistance;
// Handling lap counter.
mLapNumber++;
}
}
}
function onUpdate(dc)
{
dc.setColor(Gfx.COLOR_BLACK, Gfx.COLOR_WHITE);
dc.clear();


//!Handling data.
var lapString;
// Construct the lap string.
var mElapsedDistanceString = mElapsedDistance.format("%d") + "";

mDataX = dc.getWidth() / 2;
mDataY = dc.getHeight() / 2 + mDataYAdjust;
// Draw the lap number
dc.drawText(mDataX, mDataY, mDataFont, mElapsedDistanceString, (Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER));



//! Handling Lable.
// Center the field label
mLabelX = dc.getWidth()/2;

// Draw the field label.
dc.drawText(mLabelX, mLabelY, mLabelFont, mLabelString, Gfx.TEXT_JUSTIFY_CENTER);

}


2.
field created by "export wizard" and downloaded from the app store
function compute(info) {
if(info.elapsedDistance != 0 && info.elapsedDistance != null && mElapsedDistance != info.elapsedDistance) {
mElapsedDistance = info.elapsedDistance;
// Handling lap counter.
mLapNumber++;
if(mLapNumber % mLapNumberNotify == mLapNumberNotify - 1)
{
vibeData =
[
new Attention.VibeProfile(50, 2000), // On for a second
new Attention.VibeProfile(0, 1000), // Off for a second
new Attention.VibeProfile(50, 2000),
new Attention.VibeProfile(0, 1000),
];
Attention.vibrate(vibeData);
}
}
}
}

function onUpdate(dc)
{
// Timer events are supported so update the view with the
dc.setColor(Gfx.COLOR_BLACK, Gfx.COLOR_WHITE);
dc.clear();


//!Handling data.
var lapString;
// Construct the lap string.
lapString = mLapNumber.format("%d") + "";

mDataX = dc.getWidth() / 2;
mDataY = dc.getHeight() / 2 + mDataYAdjust;
// Draw the lap number
dc.drawText(mDataX, mDataY, mDataFont, lapString, (Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER));



//! Handling Lable.
// Center the field label
mLabelX = dc.getWidth()/2;

// Draw the field label.
dc.drawText(mLabelX, mLabelY, mLabelFont, mLabelString, Gfx.TEXT_JUSTIFY_CENTER);
}


Both fields are used
after 20th lap (25m each lap):
1st field shows 500
2nd field shows 19

can anyone help me figure out whats going on?

thanks Avner
  • You didn't say exactly what you're expecting to see, but looking at the code fragments, looks like the first field is supposed to display the elapsed distance, while the second one is supposed to display the number of laps you've already completed (I’m assuming mLapNumber is initialized to 0).

    So I'm guessing you're expecting to see 500 for the first field (so it's working properly) and 20 for the second field (not working properly).

    What is mLapNumber initialized to? For the second field, what do you see before the first lap? After the 1st, 5th and 10th? Do they match what you expect to see? If not, what's the difference?
  • yes, they are both initialized to 0
    the problem happens at lap 20, before that both fields show corresponding numbers, i.e 1&25 4&100 10&250
  • Former Member
    Former Member
    The swimming detection software in our devices probably has some quirks due to the complexity of the operation it is attempting to perform. I am not extremely familiar with this feature, so I cannot speak to what is possible. I would certainly not be surprised if it was possible for it to delay detection of a lap and add two at the same time.

    The best recommendation I can provide here is to modify the software to either use a setting to configure the pool length, or automatically detect this by computing the amount the distance minimally increases (in this case it may have gone up in a step of 25 18 times, and a step of 50 once). Saving the minimal step, and dividing the distance by this step size should keep the lap count in sync with the distance regardless of the behavior the swimming detection software outputs.