예제 #1
0
JNIEXPORT jlong JNICALL Java_rtrk_pnrs_clockgame_Game_incrementTime
  (JNIEnv *env, jclass jc, jlong time, jlong add) {
      return (jlong) incrementTime(time, add);
  }
예제 #2
0
파일: avr.c 프로젝트: ellenmliu/CS145
void setDateTime(void)
{
	// keep track of LCD pos
	int row, col;
	row = 0;
	col = 2;
	// number is the number entered
	int number;
	// counter to keep track of how many digits entered
	int counter = 0;
	// number to keep track of the number so far
	int userInput = 0;
	char buf[1]; 
	do 
	{
		while(col < 10 || row != 1)
		{
			pos_lcd(row, col);
			number = get_key();
			if(isValidKey(number))
			{
				sprintf(buf, "%i", number);
				put_str_lcd(buf);
				wait_avr(400);

				if(col >= 11 && row == 0)
				{
					row++;
					col = 2;
				}
				else if(col <= 11)
				{
					col++;
					if(col == 4 || col == 7)
						col++;
				}
					
				counter++;
				if(counter%2 == 0 && counter != 6)
					userInput += number;
				else if(counter == 5)
					userInput = 1000*number;
				else if(counter == 6)
					userInput += 100*number;
				else if(counter == 7)
					userInput += 10*number;
				else 
					userInput = 10*number;
			
			}
			if(counter == 2)
				Month = userInput;
			else if(counter == 4)
				Day = userInput;
			else if(counter == 8)
				Year = userInput;
			else if(counter == 10)
				Hour = userInput;
			else if(counter == 12)
				Minutes = userInput;
			else if(counter == 14)
				Seconds = userInput;
		}
		if(!isValidDate(Day, Month, Year))
		{
			clr_lcd();
			sprintf(buf, "%s", "invalid date");
			put_str_lcd(buf);
			wait_avr(2000);
			row = 0;
			col = 2;

			// counter to keep track of how many digits entered
			counter = 0;
			// number to keep track of the number so far
			userInput = 0;
			resetLCD();
		}
	}while(!isValidDate(Day, Month, Year));


	while(1)
	{
		wait_avr(1000);
		incrementTime();
		pos_lcd(0, 2);
		sprintf(buf, "%02i/%02i/%02i", Month, Day, Year);
		put_str_lcd(buf);
		pos_lcd(1, 2);
		sprintf(buf, "%02i:%02i:%02i", Hour, Minutes, Seconds);
		put_str_lcd(buf);
	}	
}
예제 #3
0
void stop_watch_main(void){
#else
void main(void){
#endif
   STATE state = START_STATE;
   initStopWatch();
   TIMER3_RUN(FALSE);
   ClearScreen();
   Print(0,5,"--STOP WATCH--",1);

   Rectangle(2 , 4 , 108 , 7);

   while(!stopApplication()){
      switch (state)
      {
                case START_STATE:
                {
                        t.h = t.m = t.s = 0;
                        overflow = 0;
                        printTime();
                        if(LanguageSel == 1)
                        {
                                Print6(2,10," OK for START    ",1);
                        }
                        else
                        {
                                Print(2,8,"按OK键开始:",1);
                        }
                        if(ScanKey() == K_OK)
                        {
                                while(ScanKey() != 0xff);
                                halWait(5);
                                TIMER3_RUN(TRUE);
                                state = RUN_STATE;
                                if(LanguageSel == 1)
                                {
                                        Print6(2,10," OK for STOP   ",1);
                                }
                                else
                                {
                                        Print(2,8,"按OK键停止:",1);
                                }

                        }
                }break;

                case RUN_STATE:
                {
                        INT_GLOBAL_ENABLE(INT_OFF);

                        if(overflow > 0 && overflow < 0x09)
                        {
                                GLED = LED_ON;
                        }
                        else if(overflow > (UINT16)1000)
                        {
                                //overflow = 0;
                                overflow -= 1000;

                                incrementTime();
                                printTime();
                        }
                        else
                        {
                                GLED = LED_OFF;
                        }
                        if(ScanKey() == K_OK)
                        {
                                while(ScanKey() != 0xff);
                                halWait(5);
                                TIMER3_RUN(FALSE);
                                state = STOP_STATE;
                                GLED = LED_OFF;
                        }

                        INT_GLOBAL_ENABLE(INT_ON);
                }break;
                case STOP_STATE:
                {
                        printTime();
                        if(LanguageSel == 1)
                        {
                                Print6(2,10," Total time is:",1);
                        }
                        else
                        {
                                Print(2,8,"总计时间为:",1);
                        }
                        if(ScanKey() == K_OK)
                        {
                                while(ScanKey() != 0xff);
                                halWait(5);
                                state = START_STATE;
                        }
                }break;
                default:
                break;
        }
   }
   while(ScanKey() != 0xff);
   halWait(5);
   INT_GLOBAL_ENABLE(INT_OFF);
   return;
}