예제 #1
0
파일: clock.c 프로젝트: danfa688/TSEA81
/* set_task: reads messages from the user interface, and 
   sets the clock, or exits the program */ 
void * set_thread(void *unused)
{
    /* message array */ 
    char message[SI_UI_MAX_MESSAGE_SIZE]; 

    /* time read from user interface */ 
    int hours, minutes, seconds; 

    /* set GUI size */ 
    si_ui_set_size(400, 200); 

    while(1)
    {
        /* read a message */ 
        si_ui_receive(message); 
        /* check if it is a set message */ 
        if (strncmp(message, "set", 3) == 0)
        {
            time_from_set_message(message, &hours, &minutes, &seconds); 
            if (time_ok(hours, minutes, seconds))
            {
                clock_set_time(hours, minutes, seconds); 
            }
            else
            {
                si_ui_show_error("Illegal value for hours, minutes or seconds"); 
            }
        }
        else if (strncmp(message, "alarm", 5) == 0)
        {
            time_from_alarm_message(message, &hours, &minutes, &seconds);
            if (time_ok(hours, minutes, seconds))
            {
                clock_set_alarm(hours, minutes, seconds); 
            }
            else
            {
                si_ui_show_error("Illegal value for hours, minutes or seconds"); 
            }
        }
        else if (strcmp(message, "reset") == 0)
        {
            clock_reset_alarm();        
        }
        /* check if it is an exit message */ 
        else if (strcmp(message, "exit") == 0)
        {
            exit(0); 
        }
        /* not a legal message */ 
        else 
        {
            si_ui_show_error("unexpected message type"); 
        }
    }
}
예제 #2
0
/* set_task: reads messages from the user interface... */ 
void set_task(void)
{
    /* message array */ 
    char message[SI_UI_MAX_MESSAGE_SIZE]; 

    /* time read from user interface */ 
    int hours = 0, minutes = 0, seconds = 0; 

    /* set GUI size */ 
    si_ui_set_size(400, 200); 

    while(1)
    {
        /* read a message */ 
        si_ui_receive(message); 
        /* check if it is a set message */ 
        if (strncmp(message, "set:", 4) == 0)
        {
            time_from_set_message(message, &hours, &minutes, &seconds); 
            if (time_ok(hours, minutes, seconds))
            {
                set_time(hours, minutes, seconds); 
            }
            else
            {
                si_ui_show_error("Illegal value for hours, minutes or seconds"); 
            }
        }
        /* check if it is an alarm message */ 
	else if (strncmp(message, "alarm:", 6) == 0)
	{
	    time_from_alarm_message(message, &hours, &minutes, &seconds);
	    if (time_ok(hours, minutes, seconds))
            {
                set_alarm(hours, minutes, seconds);
				display_alarm_time(hours,minutes,seconds);
            }
            else
            {
                si_ui_show_error("Illegal value for hours, minutes or seconds"); 
            }
	}
	/* check if it is an reset message */ 
	else if (strncmp(message, "reset", 5) == 0)
	{	
		erase_alarm_time();
		erase_alarm_text();
		reset_alarm();
	}
	/* check if it is an exit message */ 
        else if (strcmp(message, "exit") == 0)
        {
            exit(0); 
        }
        /* not a legal message */ 
        else 
        {
            si_ui_show_error("unexpected message type"); 
        }
    }
}