Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Prob with delay timer

Reply
Thread Tools

Prob with delay timer

 
 
lynology
Guest
Posts: n/a
 
      08-02-2004
My program takes in a key pressed value from the main routine and
based on the key pressed, it selects the command to be executed. The
problem I have is in creating a delay timer so that a message appears
on my screen for only one second. The condensed code is as follows:

#include <sys\timeb.h>
#define DELAY_1SEC 1000 // in millisec

void Scan_Menu_Keys(int key_press)
{ switch(key_press){
case 1: Execute1stCommand(); break;
case 2: Start_Timer();
while (!Timer_Expired(DELAY_1SEC))
strcpy(CG_ScreenKeyboard.Screen, "Display Message");
Clear_Screen();
break;
default: break;
}
}

void Start_Timer(){
ftime(&start_time); // ftime is function defined in sys\timeb
}

int Timer_Expired(){
ftime(&current_time);
time_diff = (int) (1000.0*(current_time.time - start_time.time) +
(current_time.millitm - start_time.millitm));
return (time_diff >= DELAY_1SEC);
}

The problem I ran into was that the timer would wait for one second
before displaying the message "Display Message". Effectively, that
meant the message never displayed because when it got out of the 1
second delay loop, the screen was cleared. I would love to get
suggestions on why this delay loop is not be executing the command
within the loop and any alternative methods to achieving the same
results.

Thanks in advance!

LYN
 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      08-02-2004

"lynology" <> wrote in message
news: om...
> My program takes in a key pressed value from the main routine and
> based on the key pressed, it selects the command to be executed. The
> problem I have is in creating a delay timer so that a message appears
> on my screen for only one second. The condensed code is as follows:
>
> #include <sys\timeb.h>
> #define DELAY_1SEC 1000 // in millisec
>
> void Scan_Menu_Keys(int key_press)
> { switch(key_press){
> case 1: Execute1stCommand(); break;
> case 2: Start_Timer();
> while (!Timer_Expired(DELAY_1SEC))
> strcpy(CG_ScreenKeyboard.Screen, "Display Message");
> Clear_Screen();
> break;
> default: break;
> }
> }
>
> void Start_Timer(){
> ftime(&start_time); // ftime is function defined in sys\timeb
> }
>
> int Timer_Expired(){
> ftime(&current_time);
> time_diff = (int) (1000.0*(current_time.time - start_time.time) +
> (current_time.millitm - start_time.millitm));
> return (time_diff >= DELAY_1SEC);
> }


Think about the above function. What happens if (say)

current_time.time = 1000000
current_time.millitm = 10

start_time.time = 999999
start_time.millitm = 100

I can't answer that question because you are using non-standard C++ (ftime),
but your method of working out the difference between two times may be
incorrect (I think it depends on whether millitm is a signed or unsigned).

john


 
Reply With Quote
 
 
 
 
Ralph D. Ungermann
Guest
Posts: n/a
 
      08-02-2004
lynology wrote:
> The
> problem I have is in creating a delay timer so that a message appears
> on my screen for only one second.



> case 2: Start_Timer();
> while (!Timer_Expired(DELAY_1SEC))
> strcpy(CG_ScreenKeyboard.Screen, "Display Message");
> Clear_Screen();


Timer_Expired() is called with one argument. Whether this compiles,
depends on a previous declaration (which you `condensed out'). But
surely, it won't link with your definition below.

> I would love to get
> suggestions on why this delay loop is not be executing the command
> within the loop


Presumimng, that the while-condition is true for exactly one second,
there will be many, many strcpy() executions in this time (depending on
your CPU speed). But I can't see a single _output_ statement. Is there
some hidden magic in writing to CG_ScreenKeyboard.Screen?

> and any alternative methods to achieving the same
> results.


Please consult the documentation of CG_ScreenKeyboard. This is not a
standard C++ class, so I'm afraid, that nobody here can help you.


Ralph

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Audio prob that's more than a sound card prob LineOut Computer Support 3 04-19-2008 02:30 PM
Calculating propagation delay & transmission delay Stone Cisco 1 09-27-2006 06:26 PM
Timer with variable delay crash.test.dummy Java 1 07-06-2006 03:35 PM
timer to delay execution of event Jason Shohet ASP .Net 8 12-21-2004 03:20 PM
Printer prob and also networking prob Gareth not NLL or anybody else. Computer Support 2 01-02-2004 07:48 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57