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));
}
}
}




  • hi,
    i might be wrong, but i can guess what might be the reason why.
    connectiq supports three kind of ant+ messages: data, record and session.
    in pool swim activities, the watch generates one additional message: "length". the watch triggers this message everytime a the swimmer finishes a full length.

    and this is the problem:
    - connect iq cannot generate length messages
    - on the other hand, connect iq requests to interact with record messages during a pool swim activity are ignored by the watch. this is just not implemented. probably because the important messages are the length files. everything else is calculated out of the information contained in the length message.

    there has been some discussion already in this forum regarding the pool swim fit files problematic.

    for instance, this guy tried to add a data field writing HR to a pool swim activity. with connectiq it should be straight forward: read hr, write it into the file using the fit contributor. but in the end it just doesn't work. HR is visible during the activity, but the hr is not written into the file.
    https://forums.garmin.com/forum/deve...47#post1103947

    this is the opposite problem to yours. you don't want to write data into a record message. you are trying to read back data available in a record message. but this is not implemented by connectiq.

    PS: just for verification, you might change the activity type to open water swim. I bet your code will work in the simulator. although of course it will not work in an indoor pool.

    PS2: i have just remembered this thread of mine, a similar issue related to pool swim activities. in my case it is not a data field, but an app. :) https://forums.garmin.com/forum/developers/connect-iq/143318-
  • thanks @danielp27
    it is very helpful
    seems that the documentation is even worst than i thought


    @Brian.ConnectIQ
    Is there anyone who actually knows the code can have a look and let me know how this can be resolved!?
  • Former Member
    Former Member over 7 years ago
    I will try to look into this soon. The FIT Length messages should definitely be parsed by the file simulation in the Connect IQ Simulator. I will test that out with your sample file and see if I can determine the issue.

    You are also not seeing the Info.elapsedDistance accumulate when doing a swimming workout on device? I would not expect an issue there, and will see if I can reproduce the issue.
  • @Brian.ConnectIQ
    thanks
    looking forward for your answer
  • Former Member
    Former Member over 7 years ago
    Avner,

    I was incorrect about the file parsing. I have looked closer at the file parsing, and only the stroke type and swolf values are extracted from the length message. I've created a ticket to improve the parser to accumulate distance from the length messages. Unfortunately your only option at this time would be to simulate data directly within your application.

    I confirmed that the elapsedDistance member of the Activity.Info class does track the distance of the swim activity in data fields, and increases by the length of the pool each time a length is detected. I did this test on a Forerunner 935. I cannot see any reason the code you posted earlier in the thread would not work on device. Which device are you using?
  • thanks
    I am using Vivoactive HR
    I am assuming you have access to private apps,
    you can see my app here
  • Former Member
    Former Member over 7 years ago
    I tested on vivoactive HR, and confirmed that elapsed distance is functioning properly in swimming activities on that device.

    I would recommend constructing a very simple test case, and building up your implementation from there. For testing I created a datafield that only displayed elapsedDistance to confirm it increments by the pool length when each length is registered.
  • thanks @Brian.ConnectIQ
    got it to work
    however its not working very well and leads me to this issue
    lease advise