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