Beispiel #1
0
// Update the keyboard and joystick inputs
void Input::Update ()
{
    // Update native keyboard state
    ReadKeyboard();

    // Read the joysticks, if present
    if (pdidJoystick1) ReadJoystick(0, pdidJoystick1);
    if (pdidJoystick2) ReadJoystick(1, pdidJoystick2);

    // Update the SAM keyboard matrix from the current key state (including joystick movement)
    Keyboard::Update();
}
Beispiel #2
0
/**
  * @brief  Reset Chrono to zero.
  * @param  None.
  * @retval None.
  */
void Time_ResetMenu(void)
{
  LCD_SetCursorPos(LCD_LINE1, 0);
  LCD_Print(" Reset Chrono ? ");
  LCD_SetCursorPos(LCD_LINE2, 0);
  LCD_Print("<No        Yes>");

  /* Endless loop */
  while (1)
  {
    /* Check which key is pressed */
    Key = ReadJoystick();

    /* If "RIGHT" pushbutton is pressed */
    if (Key == JOY_RIGHT)
    {
      Time_Reset();

      Time_Pause();

      Restore_LastDisplay() ;
      /* Exit */
      return ;
    }

    /* If "LEFT" pushbutton is pressed */
    if (Key == JOY_LEFT)
    {
      Restore_LastDisplay() ;
      /* Exit */
      return ;
    }

  }
}
void loop()
{ 
  
  int test;

  cursordelay ++;
  ReadJoystick();  
 
  
  if (cursordelay > CURSORDELAY)
  {
    cursorstate = !cursorstate;
    cursordelay = 0;
  }
  
  for (int i=0;i<8;i++)
  {
    for (int j=0;j<8;j++)
    {
       if ((tilerow==3) && (i==7))
       {
        picture[2][i][j] = true;
       } 
       else if ((tilecol==3) && (j==7))
       {  
         picture[2][i][j] = true;
       }
       else
         picture[2][i][j] = !blnMaze[i+((tilerow-1)*7)][j+((tilecol-1)*7)];   
    }
    
  }  
   
  if ((tilerow == 3) && (tilecol == 3))
    picture[1][5][5] = true;
  
  else
    picture[1][5][5] = false;
  
  SendData();  
  
   
}
Beispiel #4
0
/**
  * @brief  Parse Saved Times.
  * @param  None
  * @retval None
  */
void SavedTime_Erase(void)
{
  if ( SaveId != 0)
  {


    LCD_SetCursorPos(LCD_LINE1, 0);
    LCD_Print("Erase Records ?");
    LCD_SetCursorPos(LCD_LINE2, 0);
    LCD_Print("<No        Yes>");

    /* Endless loop */
    while (1)
    {
      /* Check which key is pressed */
      Key = ReadJoystick();

      /* If "RIGHT" pushbutton is pressed */
      if (Key == JOY_RIGHT)
      {
        SaveId = 0;
        Restore_LastDisplay() ;
        /* Exit */
        return ;
      }

      /* If "LEFT" pushbutton is pressed */
      if (Key == JOY_LEFT)
      {
        Restore_LastDisplay() ;
        /* Exit */
        return ;
      }

    }
  }
}
Beispiel #5
0
/**
  * @brief  Parse Saved Times.
  * @param  None
  * @retval None
  */
void SavedTime_Parsing(void)
{
  if ( SaveId != 0)
  {
    SaveParsingId = 1;
    LCD_SetCursorPos(LCD_LINE1, 0);
    LCD_Print("< Rec. Times  >");

    SavedTime_Show(LCD_LINE2, SaveParsingId - 1);

    /* Endless loop */
    while (1)
    {
      /* Check which key is pressed */
      Key = ReadJoystick();

      /* If "RIGHT" pushbutton is pressed */
      if (Key == JOY_RIGHT)
      {
        SaveParsingId++;

        if (SaveParsingId  <= SaveId)
        {
          SavedTime_Show(LCD_LINE2, SaveParsingId - 1);
        }
        else
        {
          SaveParsingId = SaveId;
        }
      }

      /* If "LEFT" pushbutton is pressed */
      if (Key == JOY_LEFT)
      {
        SaveParsingId--;
        if (SaveParsingId >= 1 )
        {
          SavedTime_Show(LCD_LINE2, SaveParsingId - 1);
        }
        else
        {
          SaveParsingId = 1;
        }
      }

      /* If "UP" pushbutton is pressed */
      if (Key == JOY_UP)
      {
        Restore_LastDisplay() ;
        /* Exit */
        return ;
      }

    }
  }
  else
  {
    LCD_SetCursorPos(LCD_LINE1, 0);
    LCD_Print("   No Times     ");

    LCD_SetCursorPos(LCD_LINE2, 0);
    LCD_Print(" are Recorded    ");
    Delay(0x1FFFF);
    Restore_LastDisplay();
  }


}
void ReadJoysticks(void)
{
	GotJoystick = ReadJoystick();
}
Beispiel #7
0
static bool updateMoveInternal( Move *theMove, U32 &buttonMask )
{
   F32 axes[MaxJoystickAxes];
   static F32 minValues[2] = { - 0.5, -0.5 };
   static F32 maxValues[2] = { 0.5, 0.5 };
   U32 hatMask = 0;
   if(!ReadJoystick(axes, buttonMask, hatMask))
      return false;

   // All axes return -1 to 1
   // now we map the controls:

   F32 controls[4];
   controls[0] = axes[0];
   controls[1] = axes[1];

   if(controls[0] < minValues[0])
      minValues[0] = controls[0];
   if(controls[0] > maxValues[0])
      maxValues[0] = controls[0];
   if(controls[1] < minValues[1])
      minValues[1] = controls[1];
   if(controls[1] > maxValues[1])
      maxValues[1] = controls[1];

   if(controls[0] < 0)
      controls[0] = - (controls[0] / minValues[0]);
   else if(controls[0] > 0)
      controls[0] = (controls[0] / maxValues[0]);

   if(controls[1] < 0)
      controls[1] = - (controls[1] / minValues[1]);
   else if(controls[1] > 0)
      controls[1] = (controls[1] / maxValues[1]);

   // xbox control inputs are in a circle, not a square, which makes
   // diagonal movement inputs "slower"
   if(OptionsMenuUserInterface::joystickType == XBoxController ||
      OptionsMenuUserInterface::joystickType == XBoxControllerOnXBox)
   {
      Point dir(controls[0], controls[1]);
      F32 absX = fabs(dir.x);
      F32 absY = fabs(dir.y);

      // push out to the edge of the square (-1,-1 -> 1,1 )

      F32 dirLen = dir.len() * 1.25;
      if(dirLen > 1)
         dirLen = 1;

      if(absX > absY)
         dir *= F32(dirLen / absX);
      else
         dir *= F32(dirLen / absY);
      controls[0] = dir.x;
      controls[1] = dir.y;
   }
   controls[2] = axes[gShootAxisRemaps[OptionsMenuUserInterface::joystickType][0]];
   controls[3] = axes[gShootAxisRemaps[OptionsMenuUserInterface::joystickType][1]];

   for(U32 i = 0; i < 4; i++)
   {
      F32 deadZone = i < 2 ? 0.25f : 0.03125f;
      if(controls[i] < -deadZone)
         controls[i] = -(-controls[i] - deadZone) / F32(1 - deadZone);
      else if(controls[i] > deadZone)
         controls[i] = (controls[i] - deadZone) / F32(1 - deadZone);
      else
         controls[i] = 0;
   }
   if(controls[0] < 0)
   {
      theMove->left = -controls[0];
      theMove->right = 0;
   }
   else
   {
      theMove->left = 0;
      theMove->right = controls[0];
   }

   if(controls[1] < 0)
   {
      theMove->up = -controls[1];
      theMove->down = 0;
   }
   else
   {
      theMove->down = controls[1];
      theMove->up = 0;
   }

   Point p(controls[2], controls[3]);
   F32 plen = p.len();
   if(plen > 0.3)
   {
      theMove->angle = atan2(p.y, p.x);
      theMove->fire = (plen > 0.5);
   }
   else
      theMove->fire = false;

   // remap button inputs
   U32 retMask = 0;
   for(S32 i = 0; i < MaxJoystickButtons; i++)
      if(buttonMask & (1 << i))
         retMask |= gControllerButtonRemaps[OptionsMenuUserInterface::joystickType][i];
   buttonMask = retMask | hatMask;
   return true;
}
Beispiel #8
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
#ifdef USART_IrDA_TRANSMIT
  JOYState_TypeDef Key = (JOYState_TypeDef)0;
#else /* USART_IrDA_RECEIVE */
  uint8_t ReceivedData = 0;
#endif /*USART_IrDA_TRANSMIT*/

   /* USART configuration -------------------------------------------*/
  USART_Config();

#ifdef USART_IrDA_TRANSMIT
  while (1)
  {
    /* Read Key */
    while (Key == JOY_NONE)
    {
      Key = ReadJoystick();
    }

    switch (Key)
    {
      case JOY_UP:
        USART_SendData8(EVAL_COM1, JOY_UP);
        while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
        {}
        Key = JOY_NONE;
        break;
      case JOY_DOWN:
        USART_SendData8(EVAL_COM1, JOY_DOWN);
        while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
        {}
        Key = JOY_NONE;
        break;
      case JOY_LEFT:
        USART_SendData8(EVAL_COM1, JOY_LEFT);
        while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
        {}
        Key = JOY_NONE;
        break;
      case JOY_RIGHT:
        USART_SendData8(EVAL_COM1, JOY_RIGHT);
        while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
        {}
        Key = JOY_NONE;
        break;
      case JOY_SEL:
        USART_SendData8(EVAL_COM1, JOY_SEL);
        while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
        {}
        Key = JOY_NONE;
        break;
      default:
        break;
    }
  }
#else /* USART_IrDA_RECEIVE */
  /* Initialize I/Os in Output Mode for LEDs */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  /* Turn on LEDs */
  STM_EVAL_LEDOn(LED1);
  STM_EVAL_LEDOn(LED2);
  STM_EVAL_LEDOn(LED3);
  STM_EVAL_LEDOn(LED4);

  while (1)
  {
    /* Wait until a byte is received */
    while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_RXNE) == RESET)
    {}
    /* Read the received byte */
    ReceivedData = USART_ReceiveData8(EVAL_COM1);

    switch (ReceivedData)
    {
        /* LED4 toggle */
      case JOY_UP:
        STM_EVAL_LEDToggle(LED4);
        break;
        /* LED3 toggle */
      case JOY_DOWN:
        STM_EVAL_LEDToggle(LED3);
        break;
        /* LED2 toggle */
      case JOY_LEFT:
        STM_EVAL_LEDToggle(LED2);
        break;
        /* LED1 toggle */
      case JOY_RIGHT:
        STM_EVAL_LEDToggle(LED1);
        break;

      case JOY_SEL:
        STM_EVAL_LEDToggle(LED1);
        STM_EVAL_LEDToggle(LED2);
        STM_EVAL_LEDToggle(LED3);
        STM_EVAL_LEDToggle(LED4);
        break;
      default:
        break;
    }
  }
#endif /*USART_IrDA_TRANSMIT*/
}