swimming lap vibration on lap end

Hello
For my training I would like to a vibration each time 4 laps end
i tried to build a data field with the below code
problem is that the counter is not updated and the vibration is not applies
what am i missing?



using Toybox.WatchUi as Ui;
using Toybox.Activity as Act;
using Toybox.Graphics as Gfx;
using Toybox.System as Sys;
using Toybox.Attention as Attention;

class LapCounterHapticFeedbackView extends Ui.DataField
{

hidden var mLabelString = "Laps";
hidden var mLabelFont = Gfx.FONT_SMALL;
hidden var mLabelX;
hidden var mLabelY = 5; // Does not change

hidden var mDataFont = Gfx.FONT_NUMBER_MEDIUM;
hidden var mDataX;
hidden var mDataY;
hidden var mDataYAdjust = 10; // Does not change

hidden var mLapNumber = 0;
hidden var mLapNumberNotify = 4;

//! constructor
function initialize()
{
DataField.initialize();
}

//! This is called each time a lap is created, so increment the lap number.
function onTimerLap()
{
mLapNumber++;
if(Attention has :vibrate)
{
var vibeData;
if(mLapNumber % mLapNumberNotify == 0)
{
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);
}
}



//! Display the value you computed here. This will be called
//! once a second when the data field is visible.
function onUpdate(dc)
{

// Timer events are supported so update the view with the
// current timer/lap information.
if (Ui.DataField has :onTimerLap) {
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);



// Timer events are not supported so show a message letting
// the user know that.
} else {
dc.setColor(Gfx.COLOR_BLACK, Gfx.COLOR_WHITE);
dc.clear();

var message = "Timer Events\nNot Supported";
dc.drawText(dc.getWidth()/2, dc.getHeight()/2, Gfx.FONT_MEDIUM, message, (Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER));
}
}
}




  • Former Member
    Former Member over 7 years ago
    The configured pool length is not currently available in the API, but it should not be required to detect laps. The device does not continuously accumulate distance in pool swimming mode. Distance equal to the pool length is added to the distance total each time a valid length is identified by the pool swimming mode. Comparing distance to the previous distance value in compute() should provide a not-equal result exactly once for each length of the pool covered.

    Comparing the distance to the previous value each time it changes should give you the pool length indirectly.
  • Again, this is slightly off-topic, but with the above in mind, you could implement your use case with a formula in AppBuilder such as:
    al ert(distance neq 0 and sum(distance neq prev(distance)) mod 4 eq 0, 3); sum(distance neq prev(distance))

    (remove the space between "al" and "ert").

    Here I am assuming that a swimming "lap" is 1 length. (I realize this is up for debate.) If you go with the definition that 1 lap = 2 lengths:
    al ert(distance neq 0 and sum(distance neq prev(distance)) / 2 mod 4 eq 0, 3); sum(distance neq prev(distance)) / 2

    (Not trying to step on your app development, but this might save you some time and effort.)
  • @Brian.ConnectIQ

    i assume you are relating to info.elapsedDistance
    is there a way to simulate this?
    i tried the simulator and could not make this change
  • @FlowState
    i appreciate your app being able to do this,
    however i need more that what I explain here and would like to be able to do somyself
  • Former Member
    Former Member over 7 years ago
    The simulator does not currently have any modes that simulate the elapsed distance behavior during lap swimming activities.

    Playing back a pool swimming FIT file recorded on a device may replicate the behavior, but I am not able to confirm that at this time.
  • i would like to confirm that such a fit file would be placed in the Garmis's root folder, with a name such as 2018-03-12-10-03-18.fit
    right?

    also
    is it possible to open/edit this fit file so i can see the data and analyze it?
  • Former Member
    Former Member over 7 years ago
    Activities recorded on a device should appear in the <ROOT>:\\GARMIN\ACTIVITY\ folder. I believe all devices use this directory.

    FIT files are recorded in a binary format that would be difficult to directly analyze. They can be converted to CSV format using tools provided in the FIT SDK. (https://www.thisisant.com/resources/fit)
  • i tested your answer and it simply doesnt work
    the below code was applied and mElapsedDistance & mLapNumber were not increased

    function compute(info)
    {

    if(info has :elapsedDistance )
    {

    if(info.elapsedDistance!= 0 && info.elapsedDistance != null && mElapsedDistance != info.elapsedDistance)
    {
    mElapsedDistance = info.elapsedDistance;
    // Handling lap counter.
    mLapNumber++;
    }
    }
    }


    I also tried to use the fit file in the simulator and none of the 'info' variables (other than the time) were increased

    this is really disappointing (to say the least) -
    faulty documentation and simulation, and than this
    So please
    is there anyone who actually knows the code can have a look and let me know how this can be resolved!?
    better yet
    is it possible to get the swim app source code?
    there are pretty big and annoying flaws like the algorithm that detects pool end and more
  • Former Member
    Former Member over 7 years ago
    If you can send us the sample swimming file you are attempting to simulate with, I can investigate why the simulation is not working.

    The code you posted looks correct, but there is likely an issue with simulating this activity mode.

    The swim app and other native modes are not implemented with Connect IQ.
  • 1. the code was tested in the pool and was not working,
    afterwards it was tested in the simulator and got the same results

    2. attached is a sample fit file

    3. again,
    is there anyone who actually knows the code can have a look and let me know how this can be resolved!?