Stopwatch
 
Notifications
Clear all

Stopwatch

1 Posts
1 Users
0 Reactions
557 Views
(@terrya)
Active Member
Joined: 1 year ago
Posts: 3
Topic starter  

I wanted to have a stopwatch capability for iRacing. the code is...

function myHourStopWatch(swButtonAction)
{
// STOPWATCH (HOUR TIMER)- Terry Abbott - 2023.03.18

// temporary timer variables
var swHr = 0;
var swMin = 0;
var swSec = 0;

// single button flipflop logic
// changes on JUST ONE CYCLE to 'ON' on a button press
// (button must be set up as push/release)

var swOneShot;

if (root["SwFlipFlop"]==null) { root["SwFlipFlop"]=0; }
if (root["SwOnOff"]==null) { root["SwOnOff"]=0; }

// modes: 0-stopped; 1-start/run; 2=pause; 3=reset->stopped
// Initialize the mode
if (root["TicTokMode"]==null) { root["TicTokMode"] = 0; }

// Initialize base time
if (root["swHours"]==null)
{
root["swHours"] = format($prop('DataCorePlugin.CustomExpression.CurrentDateTime'),'HH');
root["swMinutes"] = format($prop('DataCorePlugin.CustomExpression.CurrentDateTime'),'mm');
root["swSeconds"] = format($prop('DataCorePlugin.CustomExpression.CurrentDateTime'),'ss\.f');
}

// Initialize run time
if (root["swRtHours"]==null) { root["swRtHours"] = 0; }
if (root["swRtMinutes"]==null) { root["swRtMinutes"] = 0; }
if (root["swRtSeconds"]==null) { root["swRtSeconds"] = 0; }

if (root["TicTokTime"]==null) { root["TicTokTime"] = "00:00:00.0"; }

// button action logic
swOneShot = false;

if (swButtonAction != root["SwFlipFlop"])
{
if (root["SwFlipFlop"] == 0) {swOneShot = true;}
root["SwFlipFlop"] = swButtonAction;
}

// run logic
// mode change?
if (swOneShot)
{
if (root["TicTokMode"]==0)
{
root["TicTokMode"] = 1;
root["swHours"] = format($prop('DataCorePlugin.CustomExpression.CurrentDateTime'),'HH');
root["swMinutes"] = format($prop('DataCorePlugin.CustomExpression.CurrentDateTime'),'mm');
root["swSeconds"] = format($prop('DataCorePlugin.CustomExpression.CurrentDateTime'),'ss\.f');
root["swRtHours"] = root["swHours"];
root["swRtMinutes"] = root["swMinutes"];
root["swRtSeconds"] = root["swSeconds"];

root["TicTokTime"] = "00:00:00.0";
}

else if (root["TicTokMode"]==1) { root["TicTokMode"] = 2; }

else if (root["TicTokMode"]==2)
{
root["TicTokMode"] = 0;
root["TicTokTime"] = "00:00:00.0";
}
}

// while running...

if (root["TicTokMode"]==1)
{
root["swRtHours"] = format($prop('DataCorePlugin.CustomExpression.CurrentDateTime'),'HH');
root["swRtMinutes"] = format($prop('DataCorePlugin.CustomExpression.CurrentDateTime'),'mm');
root["swRtSeconds"] = format($prop('DataCorePlugin.CustomExpression.CurrentDateTime'),'ss\.f');

swHr = root["swRtHours"] - root["swHours"];
swMin = root["swRtMinutes"] - root["swMinutes"];
swSec = root["swRtSeconds"] - root["swSeconds"];

if (swSec < 0)
{
swSec = 60 + swSec;
swMin = swMin - 1;
}
if (swMin < 0)
{
swMin = 60 + swMin;
swHr = swHr - 1;
}
if (swHr < 0)
{
swHr = 24 + swHr;
}

root["TicTokTime"] = format(swHr,"00") + ":" + format(swMin,"00") + ":" + format(swSec,"00.0");
}

return root["TicTokTime"];
}

function myMinuteStopWatch(swButtonAction)
{
// STOPWATCH (MINUTE TIMER)- Terry Abbott - 2023.03.18

// temporary timer variables
var swMin = 0;
var swSec = 0;

// single button flipflop logic
// changes on JUST ONE CYCLE to 'ON' on a button press
// (button must be set up as push/release)

var swOneShot;

if (root["SwFlipFlop"]==null) { root["SwFlipFlop"]=0; }
if (root["SwOnOff"]==null) { root["SwOnOff"]=0; }

// modes: 0-stopped; 1-start/run; 2=pause; 3=reset->stopped
// Initialize the mode
if (root["TicTokMode"]==null) { root["TicTokMode"] = 0; }

// Initialize base time
if (root["swMinutes"]==null)
{
root["swMinutes"] = format($prop('DataCorePlugin.CustomExpression.CurrentDateTime'),'mm');
root["swSeconds"] = format($prop('DataCorePlugin.CustomExpression.CurrentDateTime'),'ss\.f');
}

// Initialize run time
if (root["swRtMinutes"]==null) { root["swRtMinutes"] = 0; }
if (root["swRtSeconds"]==null) { root["swRtSeconds"] = 0; }

if (root["TicTokTime"]==null) { root["TicTokTime"] = "00:00.0"; }

// button action logic
swOneShot = false;

if (swButtonAction != root["SwFlipFlop"])
{
if (root["SwFlipFlop"] == 0) {swOneShot = true;}
root["SwFlipFlop"] = swButtonAction;
}

// run logic
// mode change?
if (swOneShot)
{
if (root["TicTokMode"]==0)
{
root["TicTokMode"] = 1;
root["swMinutes"] = format($prop('DataCorePlugin.CustomExpression.CurrentDateTime'),'mm');
root["swSeconds"] = format($prop('DataCorePlugin.CustomExpression.CurrentDateTime'),'ss\.f');
root["swRtMinutes"] = root["swMinutes"];
root["swRtSeconds"] = root["swSeconds"];

root["TicTokTime"] = "00:00.0";
}

else if (root["TicTokMode"]==1) { root["TicTokMode"] = 2; }

else if (root["TicTokMode"]==2)
{
root["TicTokMode"] = 0;
root["TicTokTime"] = "00:00.0";
}
}

// while running...

if (root["TicTokMode"]==1)
{
root["swRtMinutes"] = format($prop('DataCorePlugin.CustomExpression.CurrentDateTime'),'mm');
root["swRtSeconds"] = format($prop('DataCorePlugin.CustomExpression.CurrentDateTime'),'ss\.f');

swMin = root["swRtMinutes"] - root["swMinutes"];
swSec = root["swRtSeconds"] - root["swSeconds"];

if (swSec < 0)
{
swSec = 60 + swSec;
swMin = swMin - 1;
}
if (swMin < 0)
{
swMin = 60 + swMin;
}

root["TicTokTime"] = format(swMin,"00") + ":" + format(swSec,"00.0");
}

return root["TicTokTime"];
}

 


   
Quote
Topic Tags
Share: