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(¤t_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