Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Time/timer function (http://www.chiefdelphi.com/forums/showthread.php?t=103696)

DavisC 23-02-2012 15:58

Time/timer function
 
Hello,

I am trying to include a time/timer function so that in a while loop I can keep track of how long it has been and still being able to run other code.

Also I would like to use it so that when I press a joystick button, the button is disable for say 1 second (so that it only registers 1 press and not registering from consistent pressing).

Could demonstrate how this function works?

Thanks,
Davis

Ether 23-02-2012 16:02

Re: Time/timer function
 
Quote:

Originally Posted by DavisC (Post 1133551)
I would like to use it so that when I press a joystick button, the button is disable for say 1 second (so that it only registers 1 press and not registering from consistent pressing).

Could demonstrate how this function works?

The boolean expression

(button_is_pressed && button_was_not_pressed_in_previous_iteration)

does what you want.

It's true only in the iteration immediately after the button is pressed, and doesn't become true again until the button is released and pressed again.



DavisC 23-02-2012 17:11

Re: Time/timer function
 
Thanks, that helps a lot!

Although I am still interested in learning how to use the time/timer feature.

I'm not sure if there is a specific function that can be used as a timer, or if I have to get the time off the cRIO (if possible) and do my own math.

Thanks!

mikets 23-02-2012 17:16

Re: Time/timer function
 
I use this macro.
Code:

#define GetMsecTime()          (GetFPGATime()/1000)

DavisC 23-02-2012 20:43

Re: Time/timer function
 
So i just add the #define up with the includes and use the function wherever I need to and do the math from there.

Thanks.

mikets 23-02-2012 20:54

Re: Time/timer function
 
Quote:

Originally Posted by DavisC (Post 1133726)
So i just add the #define up with the includes and use the function wherever I need to and do the math from there.

Thanks.

That's right. Typically, it looks like this:
Code:

UINT32 startTime = GetMsecTime();
//
// Do something that you want to time.
//
printf("Elapsed time = %d msec\n", GetMsecTime() - startTime);


WizenedEE 24-02-2012 00:01

Re: Time/timer function
 
There is also a Timer class, but I don't like it much. Remember to call the Start() method if you use it.


All times are GMT -5. The time now is 17:34.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi