Ejemplo n.º 1
0
/*
 * Creates a new haptic effect.
 */
int
SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect)
{
    int i;

    /* Check for device validity. */
    if (!ValidHaptic(haptic)) {
        return -1;
    }

    /* Check to see if effect is supported */
    if (SDL_HapticEffectSupported(haptic, effect) == SDL_FALSE) {
        SDL_SetError("Haptic: Effect not supported by haptic device.");
        return -1;
    }

    /* See if there's a free slot */
    for (i = 0; i < haptic->neffects; i++) {
        if (haptic->effects[i].hweffect == NULL) {

            /* Now let the backend create the real effect */
            if (SDL_SYS_HapticNewEffect(haptic, &haptic->effects[i], effect)
                != 0) {
                return -1;      /* Backend failed to create effect */
            }

            SDL_memcpy(&haptic->effects[i].effect, effect,
                       sizeof(SDL_HapticEffect));
            return i;
        }
    }

    SDL_SetError("Haptic: Device has no free space left.");
    return -1;
}
Ejemplo n.º 2
0
/*
 * Checks to see if rumble is supported.
 */
int
SDL_HapticRumbleSupported(SDL_Haptic * haptic)
{
    SDL_HapticEffect efx;

    if (!ValidHaptic(haptic)) {
        return -1;
    }

    SDL_HapticRumbleCreate(&efx);
    return SDL_HapticEffectSupported(haptic, &efx);
}
Ejemplo n.º 3
0
static void sdl_pad_connect(unsigned id)
{
   sdl_joypad_t *pad          = (sdl_joypad_t*)&sdl_pads[id];
   bool success               = false;
   int32_t product            = 0;
   int32_t vendor             = 0;

#ifdef HAVE_SDL2
   SDL_JoystickGUID guid;
   uint16_t *guid_ptr;

   if (SDL_IsGameController(id))
   {
      pad->controller = SDL_GameControllerOpen(id);
      pad->joypad     = SDL_GameControllerGetJoystick(pad->controller);

      success = pad->joypad != NULL && pad->controller != NULL;
   }
   else
#endif
   {
      pad->joypad = SDL_JoystickOpen(id);
      success = pad->joypad != NULL;
   }

   if (!success)
   {
      RARCH_ERR("[SDL]: Couldn't open joystick #%u: %s.\n", id, SDL_GetError());

      if (pad->joypad)
         SDL_JoystickClose(pad->joypad);

      pad->joypad = NULL;

      return;
   }

#ifdef HAVE_SDL2
   guid       = SDL_JoystickGetGUID(pad->joypad);
   guid_ptr   = (uint16_t*)guid.data;
#ifdef __linux
   vendor     = guid_ptr[2];
   product    = guid_ptr[4];
#elif _WIN32
   vendor     = guid_ptr[0];
   product    = guid_ptr[1];
#endif
#endif

   if (!input_autoconfigure_connect(
         sdl_joypad_name(id),
         NULL,
         sdl_joypad.ident,
         id,
         vendor,
         product))
      input_config_set_device_name(id, sdl_joypad_name(id));

   RARCH_LOG("[SDL]: Device #%u (%04x:%04x) connected: %s.\n", id, vendor,
             product, sdl_joypad_name(id));

#ifdef HAVE_SDL2
   if (pad->controller)
   {
      /* SDL_GameController internally supports all axis/button IDs, even if
       * the controller's mapping does not have a binding for it.
       *
       * So, we can claim to support all axes/buttons, and when we try to poll
       * an unbound ID, SDL simply returns the correct unpressed value.
       *
       * Note that, in addition to 0 trackballs, we also have 0 hats. This is
       * because the d-pad is in the button list, as the last 4 enum entries.
       *
       * -flibit
       */
      pad->num_axes    = SDL_CONTROLLER_AXIS_MAX;
      pad->num_buttons = SDL_CONTROLLER_BUTTON_MAX;
      pad->num_hats    = 0;
      pad->num_balls   = 0;

      RARCH_LOG("[SDL]: Device #%u supports game controller api.\n", id);
   }
   else
   {
      pad->num_axes    = SDL_JoystickNumAxes(pad->joypad);
      pad->num_buttons = SDL_JoystickNumButtons(pad->joypad);
      pad->num_hats    = SDL_JoystickNumHats(pad->joypad);
      pad->num_balls   = SDL_JoystickNumBalls(pad->joypad);

      RARCH_LOG("[SDL]: Device #%u has: %u axes, %u buttons, %u hats and %u trackballs.\n",
                id, pad->num_axes, pad->num_buttons, pad->num_hats, pad->num_balls);
   }

   pad->haptic = g_has_haptic ? SDL_HapticOpenFromJoystick(pad->joypad) : NULL;

   if (g_has_haptic && !pad->haptic)
      RARCH_WARN("[SDL]: Couldn't open haptic device of the joypad #%u: %s\n",
                 id, SDL_GetError());

   pad->rumble_effect = -1;

   if (pad->haptic)
   {
      SDL_HapticEffect efx;
      efx.type = SDL_HAPTIC_LEFTRIGHT;
      efx.leftright.type = SDL_HAPTIC_LEFTRIGHT;
      efx.leftright.large_magnitude = efx.leftright.small_magnitude = 0x4000;
      efx.leftright.length = 5000;

      if (SDL_HapticEffectSupported(pad->haptic, &efx) == SDL_FALSE)
      {
         pad->rumble_effect = -2;
         RARCH_WARN("[SDL]: Device #%u does not support rumble.\n", id);
      }
   }
#else
   pad->num_axes    = SDL_JoystickNumAxes(pad->joypad);
   pad->num_buttons = SDL_JoystickNumButtons(pad->joypad);
   pad->num_hats    = SDL_JoystickNumHats(pad->joypad);

   RARCH_LOG("[SDL]: Device #%u has: %u axes, %u buttons, %u hats.\n",
             id, pad->num_axes, pad->num_buttons, pad->num_hats);
#endif
}
Ejemplo n.º 4
0
static void sdl_pad_connect(unsigned id)
{
   sdl_joypad_t *pad          = (sdl_joypad_t*)&sdl_pads[id];
   bool success               = false;
   int32_t product            = 0;
   int32_t vendor             = 0;
   settings_t *settings       = config_get_ptr();
   autoconfig_params_t params = {{0}};

#ifdef HAVE_SDL2
   SDL_JoystickGUID guid;
   uint16_t *guid_ptr;

   if (SDL_IsGameController(id))
   {
      pad->controller = SDL_GameControllerOpen(id);
      pad->joypad     = SDL_GameControllerGetJoystick(pad->controller);

      success = pad->joypad != NULL && pad->controller != NULL;
   }
   else
#endif
   {
      pad->joypad = SDL_JoystickOpen(id);
      success = pad->joypad != NULL;
   }

   if (!success)
   {
      RARCH_ERR("[SDL]: Couldn't open joystick #%u: %s.\n", id, SDL_GetError());

      if (pad->joypad)
         SDL_JoystickClose(pad->joypad);

      pad->joypad = NULL;

      return;
   }

   strlcpy(settings->input.device_names[id], sdl_pad_name(id), sizeof(settings->input.device_names[id]));

#ifdef HAVE_SDL2
   guid       = SDL_JoystickGetGUID(pad->joypad);
   guid_ptr   = (uint16_t*)guid.data;
#ifdef __linux
   vendor     = guid_ptr[2];
   product    = guid_ptr[4];
#elif _WIN32
   vendor     = guid_ptr[0];
   product    = guid_ptr[1];
#endif
#endif
   params.idx = id;
   strlcpy(params.name, sdl_pad_name(id), sizeof(params.name));
   params.vid = vendor;
   params.pid = product;
   strlcpy(params.driver, sdl_joypad.ident, sizeof(params.driver));

   input_config_autoconfigure_joypad(&params);

   RARCH_LOG("[SDL]: Device #%u (%04x:%04x) connected: %s.\n", id, vendor,
             product, sdl_pad_name(id));

#ifdef HAVE_SDL2

   if (pad->controller)
      RARCH_LOG("[SDL]: Device #%u supports game controller api.\n", id);

   pad->haptic = g_has_haptic ? SDL_HapticOpenFromJoystick(pad->joypad) : NULL;

   if (g_has_haptic && !pad->haptic)
      RARCH_WARN("[SDL]: Couldn't open haptic device of the joypad #%u: %s\n",
                 id, SDL_GetError());

   pad->rumble_effect = -1;

   if (pad->haptic)
   {
      SDL_HapticEffect efx;
      efx.type = SDL_HAPTIC_LEFTRIGHT;
      efx.leftright.type = SDL_HAPTIC_LEFTRIGHT;
      efx.leftright.large_magnitude = efx.leftright.small_magnitude = 0x4000;
      efx.leftright.length = 5000;

      if (SDL_HapticEffectSupported(pad->haptic, &efx) == SDL_FALSE)
      {
         pad->rumble_effect = -2;
         RARCH_WARN("[SDL]: Device #%u does not support rumble.\n", id);
      }
   }
#endif

   pad->num_axes    = SDL_JoystickNumAxes(pad->joypad);
   pad->num_buttons = SDL_JoystickNumButtons(pad->joypad);
   pad->num_hats    = SDL_JoystickNumHats(pad->joypad);

#ifdef HAVE_SDL2
   pad->num_balls   = SDL_JoystickNumBalls(pad->joypad);

   RARCH_LOG("[SDL]: Device #%u has: %u axes, %u buttons, %u hats and %u trackballs.\n",
             id, pad->num_axes, pad->num_buttons, pad->num_hats, pad->num_balls);
#else
   RARCH_LOG("[SDL]: Device #%u has: %u axes, %u buttons, %u hats.\n",
             id, pad->num_axes, pad->num_buttons, pad->num_hats);
#endif
}
Ejemplo n.º 5
0
JNIEXPORT jbooleanArray JNICALL Java_at_wisch_joystick_FFJoystick_getFFCapabilitiesNative (JNIEnv *env, jclass, jint hapticDeviceIndex) {
	int supported;
	bool capabilitiesArray[16];
	SDL_HapticEffect effect;
 
	// EFFECTS
	effect.type = SDL_HAPTIC_CONSTANT;
	supported = SDL_HapticEffectSupported(ffjoysticks[hapticDeviceIndex], &effect);
	if (supported == SDL_TRUE) {
		capabilitiesArray[0] = true;
	} else if (supported == SDL_FALSE) {
		capabilitiesArray[0] = false;
	} else {
		throwException(env, SDL_GetError());
		capabilitiesArray[0] = false;
	}
	
	effect.type = SDL_HAPTIC_SINE;
	supported = SDL_HapticEffectSupported(ffjoysticks[hapticDeviceIndex], &effect);
	if (supported == SDL_TRUE) {
		capabilitiesArray[1] = true;
	} else if (supported == SDL_FALSE) {
		capabilitiesArray[1] = false;
	} else {
		throwException(env, SDL_GetError());
		capabilitiesArray[1] = false;
	}

	effect.type = SDL_HAPTIC_SQUARE;
	supported = SDL_HapticEffectSupported(ffjoysticks[hapticDeviceIndex], &effect);
	if (supported == SDL_TRUE) {
		capabilitiesArray[2] = true;
	} else if (supported == SDL_FALSE) {
		capabilitiesArray[2] = false;
	} else {
		throwException(env, SDL_GetError());
		capabilitiesArray[2] = false;
	}

	effect.type = SDL_HAPTIC_TRIANGLE;
	supported = SDL_HapticEffectSupported(ffjoysticks[hapticDeviceIndex], &effect);
	if (supported == SDL_TRUE) {
		capabilitiesArray[3] = true;
	} else if (supported == SDL_FALSE) {
		capabilitiesArray[3] = false;
	} else {
		throwException(env, SDL_GetError());
		capabilitiesArray[3] = false;
	}

	effect.type = SDL_HAPTIC_SAWTOOTHUP;
	supported = SDL_HapticEffectSupported(ffjoysticks[hapticDeviceIndex], &effect);
	if (supported == SDL_TRUE) {
		capabilitiesArray[4] = true;
	} else if (supported == SDL_FALSE) {
		capabilitiesArray[4] = false;
	} else {
		throwException(env, SDL_GetError());
		capabilitiesArray[4] = false;
	}

	effect.type = SDL_HAPTIC_SAWTOOTHDOWN;
	supported = SDL_HapticEffectSupported(ffjoysticks[hapticDeviceIndex], &effect);
	if (supported == SDL_TRUE) {
		capabilitiesArray[5] = true;
	} else if (supported == SDL_FALSE) {
		capabilitiesArray[5] = false;
	} else {
		throwException(env, SDL_GetError());
		capabilitiesArray[5] = false;
	}

	effect.type = SDL_HAPTIC_RAMP;
	supported = SDL_HapticEffectSupported(ffjoysticks[hapticDeviceIndex], &effect);
	if (supported == SDL_TRUE) {
		capabilitiesArray[6] = true;
	} else if (supported == SDL_FALSE) {
		capabilitiesArray[6] = false;
	} else {
		throwException(env, SDL_GetError());
		capabilitiesArray[6] = false;
	}

	effect.type = SDL_HAPTIC_SPRING;
	supported = SDL_HapticEffectSupported(ffjoysticks[hapticDeviceIndex], &effect);
	if (supported == SDL_TRUE) {
		capabilitiesArray[7] = true;
	} else if (supported == SDL_FALSE) {
		capabilitiesArray[7] = false;
	} else {
		throwException(env, SDL_GetError());
		capabilitiesArray[7] = false;
	}

	effect.type = SDL_HAPTIC_DAMPER;
	supported = SDL_HapticEffectSupported(ffjoysticks[hapticDeviceIndex], &effect);
	if (supported == SDL_TRUE) {
		capabilitiesArray[8] = true;
	} else if (supported == SDL_FALSE) {
		capabilitiesArray[8] = false;
	} else {
		throwException(env, SDL_GetError());
		capabilitiesArray[8] = false;
	}

	effect.type = SDL_HAPTIC_INERTIA;
	supported = SDL_HapticEffectSupported(ffjoysticks[hapticDeviceIndex], &effect);
	if (supported == SDL_TRUE) {
		capabilitiesArray[9] = true;
	} else if (supported == SDL_FALSE) {
		capabilitiesArray[9] = false;
	} else {
		throwException(env, SDL_GetError());
		capabilitiesArray[9] = false;
	}

	effect.type = SDL_HAPTIC_FRICTION;
	supported = SDL_HapticEffectSupported(ffjoysticks[hapticDeviceIndex], &effect);
	if (supported == SDL_TRUE) {
		capabilitiesArray[10] = true;
	} else if (supported == SDL_FALSE) {
		capabilitiesArray[10] = false;
	} else {
		throwException(env, SDL_GetError());
		capabilitiesArray[10] = false;
	}

	effect.type = SDL_HAPTIC_CUSTOM;
	supported = SDL_HapticEffectSupported(ffjoysticks[hapticDeviceIndex], &effect);
	if (supported == SDL_TRUE) {
		capabilitiesArray[11] = true;
	} else if (supported == SDL_FALSE) {
		capabilitiesArray[11] = false;
	} else {
		throwException(env, SDL_GetError());
		capabilitiesArray[11] = false;
	}

	// OTHER
	// THIS IS ACTUALLY LOGICALLY WRONG (effect.type should be neither of the
	//		following 4) - because of information hiding (we cannot access the field
	//		unsigned int supported (Supported effects) in SDL_Haptic from here)
	//		we have to do it this way....

	effect.type = SDL_HAPTIC_GAIN;
	supported = SDL_HapticEffectSupported(ffjoysticks[hapticDeviceIndex], &effect);
	if (supported == SDL_TRUE) {
		capabilitiesArray[12] = true;
	} else if (supported == SDL_FALSE) {
		capabilitiesArray[12] = false;
	} else {
		throwException(env, SDL_GetError());
		capabilitiesArray[12] = false;
	}

	effect.type = SDL_HAPTIC_AUTOCENTER;
	supported = SDL_HapticEffectSupported(ffjoysticks[hapticDeviceIndex], &effect);
	if (supported == SDL_TRUE) {
		capabilitiesArray[13] = true;
	} else if (supported == SDL_FALSE) {
		capabilitiesArray[13] = false;
	} else {
		throwException(env, SDL_GetError());
		capabilitiesArray[13] = false;
	}

	effect.type = SDL_HAPTIC_STATUS;
	supported = SDL_HapticEffectSupported(ffjoysticks[hapticDeviceIndex], &effect);
	if (supported == SDL_TRUE) {
		capabilitiesArray[14] = true;
	} else if (supported == SDL_FALSE) {
		capabilitiesArray[14] = false;
	} else {
		throwException(env, SDL_GetError());
		capabilitiesArray[14] = false;
	}

	effect.type = SDL_HAPTIC_PAUSE;
	supported = SDL_HapticEffectSupported(ffjoysticks[hapticDeviceIndex], &effect);
	if (supported == SDL_TRUE) {
		capabilitiesArray[15] = true;
	} else if (supported == SDL_FALSE) {
		capabilitiesArray[15] = false;
	} else {
		throwException(env, SDL_GetError());
		capabilitiesArray[15] = false;
	}
	jbooleanArray jCapabilitiesArray = (jbooleanArray)env->NewBooleanArray(16);
	env->SetBooleanArrayRegion(jCapabilitiesArray, 0, 16, (jboolean *)capabilitiesArray);
	return (jCapabilitiesArray);

}