Example #1
0
osStatus Thread::terminate() {
    return osThreadTerminate(_tid);
}
void osDeleteTask(OsTask *task)
{
   //Delete the specified task
   osThreadTerminate((osThreadId) task);
}
Example #3
0
/*----------------------------------------------------------------------------
  Thread 1 'command': command processor
 *---------------------------------------------------------------------------*/
void command (void const *argument) {
  int i;

  printf (menu);                              /* display command menu        */
  while (1) {                                 /* endless loop                */
    printf ("\r\nCommand: ");                 /* display prompt              */
    #ifdef __USE_FFLUSH
    fflush (stdout); 
    #endif
    getline (cmdline, sizeof (cmdline));      /* get command line input      */

    for (i = 0; cmdline[i] != 0; i++) {       /* convert to uppercase        */
      cmdline[i] = (char) toupper((int)cmdline[i]);
    }

    for (i = 0; cmdline[i] == ' '; i++);      /* skip blanks                 */

    switch (cmdline[i]) {                     /* proceed to command function */
      case 'D':                               /* Display Time Command        */
        printf ("Start Time: %02d:%02d:%02d    "
                "End Time: %02d:%02d:%02d\r\n",
                 stime.hour, stime.min, stime.sec,
                 etime.hour, etime.min, etime.sec);
        printf ("                        type ESC to abort\r");
        #ifdef __USE_FFLUSH
        fflush (stdout);
        #endif

        tid_getesc = osThreadCreate(osThread(get_escape), NULL);
                                              /* ESC check in display loop   */
        escape = false;                       /* clear escape flag           */
        display_time = true;                  /* set display time flag       */
        osSignalClear(tid_command, 0x0003);
                                              /* clear pending signals       */
        while (!escape) {                     /* while no ESC enteRED        */
          printf ("Clock Time: %02d:%02d:%02d\r",   /* display time          */
                   ctime.hour, ctime.min, ctime.sec);
          #ifdef __USE_FFLUSH
          fflush (stdout);
          #endif
          osSignalWait(0, osWaitForever);     /* wait for time change or ESC */
        }

        osThreadTerminate(tid_getesc);        /* terminate 'get_escape'      */
        display_time = false;                 /* clear display time flag     */
        printf ("\r\n\r\n");
        break;

      case 'T':                               /* Set Time Command            */
        if (readtime (&cmdline[i+1])) {       /* read time input and         */
          ctime.hour = rtime.hour;            /* store in 'ctime'            */
          ctime.min  = rtime.min;
          ctime.sec  = rtime.sec;
        }
        break;

      case 'E':                               /* Set End Time Command        */
        if (readtime (&cmdline[i+1]))  {      /* read time input and         */
          etime.hour = rtime.hour;              /* store in 'end'              */
          etime.min  = rtime.min;
          etime.sec  = rtime.sec;
        }
        break;

      case 'S':                               /* Set Start Time Command      */
        if (readtime (&cmdline[i+1]))  {      /* read time input and         */
          stime.hour = rtime.hour;            /* store in 'start'            */
          stime.min  = rtime.min;
          stime.sec  = rtime.sec;
        }
        break;

      default:                                /* Error Handling              */
        printf (menu);                        /* display command menu        */
        break;
    }   
  }
}
Example #4
0
	void mode_change_thread(void const * argument){
		wirelessTransmit_TX(motor_init);
		keypad_column_init();		
		osDelay(100);
		
		/*read column*/
		int8_t key_column = readKeyColumn();
		keypad_row_init();
		
		/*read row*/
		int8_t key_row = readKeyRow();
		
		mode = read_keypad(key_column, key_row);
			
		while(1){
			mode = read_keypad(key_column, key_row);
				while(mode == 'e'){
						wirelessTransmit_TX(motor_init);
						keypad_column_init();		
						osDelay(100);
						
						/*read column*/
						int8_t key_column = readKeyColumn();
						keypad_row_init();
						
						/*read row*/
						int8_t key_row = readKeyRow();
						
						mode = read_keypad(key_column, key_row);
				}
				if (mode == 'A'){
				printf (">>>>>>>>Entering Mode_1 Real Time Tilting<<<<<<<<\n");
				char mode1[7] = "Mode 1";
				LCD_clear_display();
				LCD_DISPLAY_UPDATE_POS(0x80, mode1);
				wirelessTransmit_TX(mode_A);
				
				tilt_thread = osThreadCreate(osThread(tilt_detection_thread),NULL);
				tilt_transmit_thread = osThreadCreate(osThread(transmitTiltAngles),NULL);
							
				uint8_t readreg=read_Status_Register(WIRELESS_STATUS_VERSION);
				
					mode_selection = 1;
					
			}else if (mode == 'B'){
				printf (">>>>>>>>Entering Mode_2 Movement Sequence Input<<<<<<<<\n");
				wirelessTransmit_TX(mode_B);
//				printf ("A: positive sign(must be entered). B: negative sign. C: terminate input\n");
//				printf ("IMPORTANT: To input <30,-60,10> <-45,65,8>...<20,-30,5> You shall enter the key as following:\n");
//				printf ("A30B60A10B45A65A08...A20B30A05C\n");
				
				keypad_thread = osThreadCreate(osThread(keypad), NULL);
				
				
				mode_selection = 2;
				
				
			}else if (mode == 'C'){
				printf (">>>>>>>>Entering Mode_3 Record and Play Option<<<<<<<<\n");
				wirelessTransmit_TX(mode_C);
				mode_selection = 3;
				
			}
			
			osSignalWait(SIGNAL_MODE_CHANGE, osWaitForever);
			if(mode_selection == 1 ){
				osThreadTerminate(tilt_transmit_thread);
				osThreadTerminate(tilt_thread);
			}
			else if(mode_selection == 2){
				osThreadTerminate(keypad_thread);
			}
			else{
			
			}
			
			mode_selection=0;
		}
}
void AppPong()
{					
	switch(appPongState)
	{
		case Normal:			

			// Increment ball's position
			new_ball_X += ballVelocityX;
			new_ball_Y += ballVelocityY;
			// Check if the ball is colliding with the left paddle
			if (new_ball_X < (new_paddle0_X + paddleW) )
			{
				// Check if ball is within paddle's height
				if ((new_ball_Y > new_paddle0_Y) && (new_ball_Y < new_paddle0_Y + paddleH))
				{
					new_ball_X += ball_rad;  // Move ball over one to the right
					ballVelocityX = -ballVelocityX; // Change velocity
					Beep();
				}
			}
			// Check if the ball hit the right paddle
			if (new_ball_X + ball_rad > new_paddle1_X)
			{
				// Check if ball is within paddle's height
				if ((new_ball_Y > new_paddle1_Y) && (new_ball_Y < new_paddle1_Y + paddleH))
				{
					new_ball_X -= ball_rad;  // Move ball over one to the left
					ballVelocityX = -ballVelocityX; // change velocity
					Beep();
				}
			}
			// Check if the ball hit the top or bottom
			if ((new_ball_Y <= borderWidth) || (new_ball_Y >= (GLCD_HEIGHT - ball_rad - 1)))
			{
				// Change up/down velocity direction
				ballVelocityY = -ballVelocityY;
				Beep();
			}

			if(AUTOMATIC_CONTROL)
			{
				//Automatic Control
				new_paddle0_Y = new_ball_Y-paddleH/2; // Invincible paddle0					
			}
			else
			{
				//Controlled by potentiometer
				ADC_StartConversion();
				new_paddle0_Y = map(ADC_GetValue(),0,4096,0,GLCD_HEIGHT);
			}
			
			// Automatic control
			new_paddle1_Y = new_ball_Y-paddleH/2; // Invincible paddle1		

			// Check if paddle0 is not out of the frame
			if(new_paddle0_Y  < borderWidth) { // Top Frame
				new_paddle0_Y = borderWidth;
			}
			if(new_paddle0_Y + paddleH > GLCD_HEIGHT - borderWidth) { // Bottom Frame
				new_paddle0_Y = GLCD_HEIGHT - borderWidth - paddleH;
			}
			
			// Check if paddle1 is not out of the frame
			if(new_paddle1_Y  < borderWidth) { // Top Frame
				new_paddle1_Y = borderWidth;
			}
			if(new_paddle1_Y + paddleH > GLCD_HEIGHT - borderWidth) { // Bottom Frame
				new_paddle1_Y = GLCD_HEIGHT - borderWidth - paddleH;
			}

			joyMsk = Joystick_GetState();   // Show joystick arrows               
				if (joy ^ joyMsk)                
					{
						joy = joyMsk;

						if(joy & JOYSTICK_LEFT)
						{
							if(ballVelocityX > 0)
							{
								ballVelocityX--;
							}
							else
							{
								ballVelocityX++;
							}
							
							if(ballVelocityY > 0)
							{
								ballVelocityY--;
							}
							else
							{
								ballVelocityY++;
							}
						}
						if(joy & JOYSTICK_RIGHT)
						{
							if(ballVelocityX > 0)
							{
								ballVelocityX++;
							}
							else
							{
								ballVelocityX--;
							}
							
							if(ballVelocityY > 0)
							{
								ballVelocityY++;
							}
							else
							{
								ballVelocityY--;
							}
						}
						if(joy & JOYSTICK_CENTER)
						{
							
						}
						if(joy & JOYSTICK_UP)
						{						
							GLCD_SetForegroundColor(BackgroundColor);
							GLCD_DrawRectangle(old_ball_X, old_ball_Y, ball_rad, ball_rad);
							GLCD_SetForegroundColor(BallForegroundColor);
							ball_rad++;
						}
						if(joy & JOYSTICK_DOWN)
						{
							GLCD_SetForegroundColor(BackgroundColor);
							GLCD_DrawRectangle(old_ball_X, old_ball_Y, ball_rad, ball_rad);
							GLCD_SetForegroundColor(BallForegroundColor);
							ball_rad--;
						}	
				}
				
			if(new_ball_X > GLCD_WIDTH)
			{
				score0++;
				appPongState = Lose;
			}		
			
			if(new_ball_X < 0)
			{
				score1++;
				appPongState = Lose;
			}
			
			// Draw the Pong Field					
			
			//STATIC OBJECTS
			// Draw an outline of the screen:
			GLCD_SetForegroundColor(ForegroundColor);
			GLCD_DrawRectangle(0, 0, GLCD_WIDTH - 1, GLCD_HEIGHT - 1);
			// Draw the center line
			GLCD_DrawRectangle(GLCD_WIDTH/2 - 1, 0, borderWidth, GLCD_HEIGHT);	
			
			//MOVING OBJECTS		
			GLCD_SetForegroundColor(BackgroundColor);
			// Erase the Paddles:
			GLCD_DrawRectangle(old_paddle0_X, old_paddle0_Y, paddleW, paddleH);
			GLCD_DrawRectangle(old_paddle1_X, old_paddle1_Y, paddleW, paddleH);
			// Erase the ball:
			GLCD_DrawRectangle(old_ball_X, old_ball_Y, ball_rad, ball_rad);
			
			old_paddle0_X = new_paddle0_X;
			old_paddle0_Y = new_paddle0_Y;
			old_paddle1_X = new_paddle1_X;
			old_paddle1_Y = new_paddle1_Y;
			old_ball_X = new_ball_X;
			old_ball_Y = new_ball_Y;
			
			// Draw the Paddles:
			GLCD_SetForegroundColor(LeftPaddleForegroundColor);
			GLCD_DrawRectangle(new_paddle0_X, new_paddle0_Y, paddleW, paddleH);
			
			GLCD_SetForegroundColor(RightPaddleForegroundColor);					
			GLCD_DrawRectangle(new_paddle1_X, new_paddle1_Y, paddleW, paddleH);
			// Draw the ball:
			GLCD_SetForegroundColor(BallForegroundColor);	
			GLCD_DrawRectangle(new_ball_X, new_ball_Y, ball_rad, ball_rad);
			
			sprintf (str_score0, "%1u", score0); //takes the numeric value and convert it to a char with the %1u format (1 unit unsigned)
			sprintf (str_score1, "%1u", score1);
			str_score0[sizeof(str_score0)-1] = '\0'; //indicate end of string
			str_score1[sizeof(str_score1)-1] = '\0';
			GLCD_SetForegroundColor(LeftPaddleForegroundColor);
			GLCD_DrawString(5, 5, str_score0);
			GLCD_SetForegroundColor(RightPaddleForegroundColor);
			GLCD_DrawString((GLCD_WIDTH/2)+5, 5,  str_score1);
		
			break;
			
		case Lose:
			if(score0 >= SCORE_MAX_PONG || score1 >= SCORE_MAX_PONG)
			{
				appPongState = GameOver;
				break;
			}

			InitializeAppPong();
			break;
			
		case GameOver:
			GLCD_SetFont            (&GLCD_Font_16x24);
			if(score0 > score1)
			{
				GLCD_SetForegroundColor(GLCD_COLOR_BLUE);
				GLCD_DrawString((((GLCD_WIDTH/2)-(16*6))/2), GLCD_HEIGHT/2, "WIN !");
				GLCD_SetForegroundColor(GLCD_COLOR_GREEN);
				GLCD_DrawString((((GLCD_WIDTH/2)-(16*6))/2) + (GLCD_WIDTH/2), GLCD_HEIGHT/2, "LOSE !");
			}
			else
			{
				GLCD_SetForegroundColor(GLCD_COLOR_GREEN);
				GLCD_DrawString((((GLCD_WIDTH/2)-(16*6))/2) + (GLCD_WIDTH/2), GLCD_HEIGHT/2, "WIN !");
				GLCD_SetForegroundColor(GLCD_COLOR_BLUE);
				GLCD_DrawString((((GLCD_WIDTH/2)-(16*6))/2), GLCD_HEIGHT/2,  "LOSE !");
			}			
			
			score0 = 0;
			score1 = 0;
			osDelay(2000);
			menuChoice = InitMenu;

			osThreadTerminate (idThreadBeep);
			break;
	}	
			
}
void AppShooter()
{
	  while (!stopShooter) {

		joyMsk = Joystick_GetState();
		btnMsk = Buttons_GetState();

		if (timerTick_01 > 2)
		{
			if (ballTimer != 0) { ballTimer--; }
			if ( ((btnMsk & 1) != 0) && (ballTimer == 0) )
			{
				ballTimer = 8;
				newBall = true;
			}
			
			if (joyMsk != 0)
			{
				osMutexWait(planeVar_mutex_id, osWaitForever);
				// RIGHT
				if ((plane_x < GLCD_WIDTH - 10) && ((joyMsk & 2) != 0))
				{
					plane_x += 10;
				}
				// LEFT
				if ((plane_x > 0) && ((joyMsk & 1) != 0))
				{
					plane_x -= 10;
				}
				// UP
				if ((plane_y > 20) && ((joyMsk & 8) != 0))
				{
					plane_y -= 10;
				}
				// DOWN
				if ((plane_y < GLCD_HEIGHT - 10) && ((joyMsk & 16) != 0))
				{
					plane_y += 10;
				}
				osMutexRelease(planeVar_mutex_id);
			}
			timerTick_01 = 0;
			S_MoveBall(newBall);
			newBall = false;
		}	
		
		if ( timerTick_02 > 12 )
		{
			S_MoveObjects ();
			timerTick_02 = 0;
			
		}
  }

	osThreadTerminate (idThreadPlane);
	osDelay(500);
	
	if (playerScore > machineScore) {
		GLCD_SetForegroundColor (GLCD_COLOR_GREEN);
		GLCD_DrawString ((GLCD_WIDTH-16*9)/2, GLCD_HEIGHT/2-16, "YOU WIN !");
	} else {
		GLCD_SetForegroundColor (GLCD_COLOR_RED);
		GLCD_DrawString ((GLCD_WIDTH-16*11)/2, GLCD_HEIGHT/2-16, "YOU LOSE !");
	}
	osDelay(2000);
	
}
void ThreadAPI_Exit(int res)
{
  osThreadTerminate(listTaskRTOSHandle[(res)].threadId);
}