Back

Stopwatch Plugin

In order to use Stopwatch functions plugin, you must first load the plugin at the top of your script using the LoadPlugin method like this:

// Load the Stopwatch plugin
app.LoadPlugin( "Stopwatch" );
  Copy  

Then you can create an instance of the plugin object when you need it like this:

 plg = app.CreateStopwatch( );
 Copy 

Version Information
You can get the plugin version by calling GetVersion( ) for program use or toast display the version by calling ShowVersion( )

Methods:

GetVersion( ) - returns string

 - returns version string

ShowVersion( )

 - toast display the version number

Example:

Example - Get / Show Version

app.LoadPlugin("Stopwatch");

function OnStart( ) {
 lay=app.CreateLayout("Linear","VCenter,FillXY");

 // make buttons on screen
 btn = app.CreateButton("Get Version",0.3,-1,'gray');
 btn.SetTextSize(18);
 btn.SetOnTouch(btnGetVer);
 lay.AddChild(btn);

 btn = app.CreateButton("Show Version",0.3,-1,'gray');
 btn.SetTextSize(18);
 btn.SetOnTouch(btnShowVer);
 lay.AddChild(btn);

 btn = app.CreateButton("Exit",0.3,-1,'gray');
 btn.SetTextSize(18);
 btn.SetOnTouch(btnExit);
 lay.AddChild(btn);

 app.AddLayout(lay);
}

function btnGetVer( ) {
 plg = app.CreateStopwatch( );
 app.ShowPopup( 'Stopwatch version '+plg.GetVersion( ), 'bottom,short' );

}

function btnShowVer( ) {
 plg = app.CreateStopwatch( );
 plg.ShowVersion();
}

function btnExit( ) { app.Exit( ); }
  Copy   Copy All    Run   

You must issue a Start( ) function to start the timer when an action is complete a Stop( ) function should be declared.


To compare the time passed between two points of time. The Time( option ) function takes an optional "milli" option that provides time accuracy to the milliseconds.

Example:

Example - Stopwatch

app.LoadPlugin("Stopwatch");

//called when the application is started.
function OnStart( ) {
 lay = app.CreateLayout("Linear","VCenter,FillXY");

 // create screen buttons
 btn1 = app.CreateButton("Start",0.5,-1,'gray');
 btn1.SetTextSize( 18 );
 btn1.SetOnTouch( StartClock );

 btn2 = app.CreateButton("Elapse Time",0.5,-1,'gray');
 btn2.SetTextSize( 18 );
 btn2.SetOnTouch( StopClock );

 btn3 = app.CreateButton("Exit",0.5,-1,'gray');
 btn3.SetTextSize( 18 );
 btn3.SetOnTouch( Exit );

 // layout the screen
 lay.AddChild( btn1 );
 lay.AddChild( btn2 );
 lay.AddChild( btn3 );
 app.AddLayout( lay );

 plg_sw = app.CreateStopwatch( );
}

// start the clock
function StartClock( ) {
 plg_sw.Start( );
 app.ShowPopup('Starting the clock','bottom');
}

// stop the clock
function StopClock( ) {
 plg_sw.Stop( );
 app.ShowPopup('Time Elapsed: '+plg_sw.Time('milli'),'bottom');
}

// exit the app
function Exit( ) {
 app.Exit();
}

Copy All  Run 

The following methods are available on the Stopwatch object:

Start( )

 - Start the timer

Stop( )

 - Stop the timer

Time( option ) - returns string

option (optional) - option milli for accuracy to the milliseconds

 - handles milliseconds, seconds, minutes, hours, days of time since started

 - returns a time formatted string of days, hours, mins, secs, milliseconds

This DS Code plugin was written by Nelson Tengkiat, it is free to use in your projects. A credit line if used would be nice :)