C_RESULT ui_pad_reset_user_input(input_state_t* input_state)
{
  user_input = 0;
  
  input_state->ag       = 0;
  input_state->ab       = 0;
  input_state->ad       = 0;
  input_state->ah       = 0;
  input_state->l1       = 0;
  input_state->r1       = 0;
  input_state->l2       = 0;
  //input_state->r2       = 0; (To avoid angle trim done when CTRL_TRANS_LANDING =>CTRL_LANDING)
  input_state->select   = 0;
  input_state->start    = 0;

  input_state->x        = 0;
  input_state->y        = 0;
  
  ui_pad_ag(1);
  ui_pad_ag(0);
  ui_pad_ab(1);
  ui_pad_ab(0);
  ui_pad_ad(1);
  ui_pad_ad(0);
  ui_pad_ah(1);
  ui_pad_ah(0);
  ui_pad_l1(1);
  ui_pad_l1(0);
  ui_pad_r1(1);
  ui_pad_r1(0);
  ui_pad_l2(1);
  ui_pad_l2(0);
  //ui_pad_r2_pressed(input_state);
  //ui_pad_r2_released(input_state);
  ui_pad_xy_change(0, 0);
  ui_pad_yaw_trim(0);
  ui_pad_phi_trim(0);
  ui_pad_theta_trim(0);

  return custom_reset_user_input(input_state, user_input);
}
Exemplo n.º 2
0
C_RESULT update_gamepad(void)
{
  static int32_t x = 0, y = 0;
  static bool_t refresh_values = FALSE;
  ssize_t res;
  static struct js_event js_e_buffer[64];
  static int32_t start = 0;
  input_state_t* input_state;

  static int32_t theta_trim = 0;
  static int32_t phi_trim   = 0;
  static int32_t yaw_trim   = 0;


  res = read(joy_dev, js_e_buffer, sizeof(struct js_event) * 64);

  if( !res || (res < 0 && errno == EAGAIN) )
    return C_OK;

  if( res < 0 )
    return C_FAIL;

  if (res < (int) sizeof(struct js_event))// If non-complete bloc: ignored
    return C_OK;

  // Buffer d�composition in blocs (if the last is incomplete, it's ignored)
  int32_t idx = 0;
  refresh_values = FALSE;
  input_state = ardrone_tool_get_input_state();
  for (idx = 0; idx < res / sizeof(struct js_event); idx++)
  {
    if(js_e_buffer[idx].type & JS_EVENT_INIT )// If Init, the first values are ignored
    {
      break;
    }
    else if(js_e_buffer[idx].type & JS_EVENT_BUTTON )// Event Button detected
    {
      switch( js_e_buffer[idx].number )
      {
        case PAD_AG :
		ardrone_tool_set_ui_pad_ag(js_e_buffer[idx].value);
		break;
        case PAD_AB :
		ardrone_tool_set_ui_pad_ab(js_e_buffer[idx].value);
		break;
        case PAD_AD :
		ardrone_tool_set_ui_pad_ad(js_e_buffer[idx].value);
		break;
        case PAD_AH :
		ardrone_tool_set_ui_pad_ah(js_e_buffer[idx].value);
		break;
        case PAD_L1 :
		if( js_e_buffer[idx].value )
		{
			yaw_trim = 0;

			if( input_state->r2 )
			{
				yaw_trim = -1;
			}
			else
			{
				ardrone_tool_set_ui_pad_l1(1);
			}
         ui_pad_yaw_trim( yaw_trim );
		}
      else
      {
         yaw_trim = 0;
         ardrone_tool_set_ui_pad_l1(0);
         ui_pad_yaw_trim( yaw_trim );
      }
		break;
        case PAD_R1 :
		if( js_e_buffer[idx].value )
		{
			yaw_trim = 0;

			if( input_state->r2 )
			{
				yaw_trim = 1;
			}
			else
			{
				ardrone_tool_set_ui_pad_r1(1);
			}
         ui_pad_yaw_trim( yaw_trim );
		}
      else
      {
         yaw_trim = 0;
         ardrone_tool_set_ui_pad_r1(0);
         ui_pad_yaw_trim( yaw_trim );
      }
		break;
        case PAD_L2 :
		ardrone_tool_set_ui_pad_l2(js_e_buffer[idx].value);
		if( !js_e_buffer[idx].value )
		{
			ardrone_at_set_pmode( MiscVar[0] );
			ardrone_at_set_ui_misc( MiscVar[0], MiscVar[1], MiscVar[2], MiscVar[3] );
		}
		break;
        case PAD_R2 :
		ardrone_tool_set_ui_pad_r2(js_e_buffer[idx].value);
      if( !js_e_buffer[idx].value )
         ardrone_at_set_flat_trim();
		break;
        case PAD_SELECT :
		ardrone_tool_set_ui_pad_select(js_e_buffer[idx].value);
		break;
        case PAD_START :
      if( js_e_buffer[idx].value )
      {
         start ^= 1;
		   ardrone_tool_set_ui_pad_start( start );
		}
      break;
        default:
		break;
      }

    }
    else if(js_e_buffer[idx].type & JS_EVENT_AXIS )// Event Axis detected
    {
      refresh_values = TRUE;
      switch( js_e_buffer[idx].number )
      {
        case PAD_X:
          x = ( js_e_buffer[idx].value + 1 ) >> 15;
          break;
        case PAD_Y:
          y = ( js_e_buffer[idx].value + 1 ) >> 15;
          break;
        default:
          break;
      }
    }
    else
    {// TODO: default: ERROR (non-supported)
    }
  }

  if(refresh_values)// Axis values to refresh