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




  • I should also point out that this code works in the simulator when clicking the buttons
    however
    when tested on my vivoactive hr the counter does not increase and there is no vibration
  • Are you using a programmed workout for swimming? There's a known issue where lap events are not called in CIQ for workouts. People have been complaining for quite some time, but nobody's sure when it'll be fixed.
    https://forums.garmin.com/forum/developers/connect-iq/connect-iq-bug-reports/148687-?367741-ontimerlap()-not-called-when-using-workout-system=

    Also, slightly off-topic, but I have an app that can already do pretty much what you want (assuming you're not using workouts), in case you don't want to go to the trouble of submitting your app to the store or sideloading.

    https://apps.garmin.com/en-US/apps/deb4b872-48be-409c-b91a-9b8485d2fc80
    AppBuilder lets you create a simple datafield that displays almost any numerical data you want, based on a math formula you enter, and it also supports vibration alerts.

    In your case, you could use this formula, which would cause the watch to vibrate after every 4 laps, and display the current zero-based lap number:
    al ert(lapcount neq 0 and lapcount mod 4 eq 0, 3); lapcount

    (Because the forum is acting up, you need to remove the space between "al" and "ert")

    The "3" in the second parameter of alert specifies that you want vibe alerts only and not tones.
  • thanks
    may ask, if the onTimerLap doesnt work, how did you set it up to vibrate on lap end?
  • No problem. Sorry, I wasn't clear: my app does the same thing as your app - it uses onTimerLap(). So the example I gave would work/fail in all the same cases as your app, assuming there isn't some weird bug in the code you posted. The code you posted looks fine to me, though.

    onTimerLap() works, just not for workouts. I haven't tried laps in pool swimming, though.
  • Former Member
    Former Member over 7 years ago
    Note that pool laps, timer laps, and workout steps are all different events in the system. We are working on adding an API callback that will report the workout step event. I've created a ticket to investigate the pool lap event to determine if it is possible to add a callback for that event.
  • thats understood,
    however,
    your documentation specify differently
    onTimerLap ? Object

    A lap event has occurred.

    This method is called when a lap is added to the current activity. A notification is triggered after the lap record has been written to the FIT file.


    and with no release date or any other time frame it has no meaning
  • FlowState,
    thanks for the answer
  • Former Member
    Former Member over 7 years ago
    I am sorry the documentation is unclear. This is an unfortunate result of an overlap in terminology. With respect device functionality, pool lap accumulation is not related to laps that are added using the lap key, or Auto-Lap behavior in other sports. These are fundamentally different things, and it would not make sense to trigger a onTimerLap event when pool lengths are completed. I will make a request to improve this documentation.
  • Former Member
    Former Member over 7 years ago
    Avner

    I looked at the pool case a bit today, and realized you should be able to detect pool length accumulation on the device during a pool swim by monitoring the activity distance. This value should increase at the same time the valid length detection occurs. I'm not sure it would make sense to add an additional callback to the system for this event.
  • ok, i'll try that
    how do i get the length of the pool i configured in the swim app?