JNIEXPORT jint JNICALL Java_at_wisch_joystick_JoystickManager_openFFJoystick (JNIEnv *env, jclass, jint joystickIndex) { SDL_Haptic* hapticDevice = SDL_HapticOpenFromJoystick(joysticks[joystickIndex]); if (hapticDevice == NULL) { // Most likely Joystick does not have FF-capabilities... return -4; } int hapticDeviceIndex = SDL_HapticIndex(hapticDevice); /* # the previous line did not work with previous versions of SDL # see http://bugzilla.libsdl.org/show_bug.cgi?id=946 # -> had to use the following workaround # (the implementation of SDL_HapticOpenFromJoystick in linux in fact does it it in the same way) */ /* int hapticDeviceIndex = -5; for (int i = 0; i < SDL_NumHaptics(); i++) { if (SDL_HapticName(i) != NULL) { if (SDL_strcmp(SDL_HapticName(i), SDL_JoystickName(joystickIndex)) == 0) { hapticDeviceIndex = i; break; } } }*/ if (hapticDeviceIndex < 0) { throwException(env, SDL_GetError()); return hapticDeviceIndex; } ffjoysticks[hapticDeviceIndex] = hapticDevice; return hapticDeviceIndex; }
bool Joystick::setVibration() { bool success = true; if (SDL_WasInit(SDL_INIT_HAPTIC) && haptic && SDL_HapticIndex(haptic) != -1) success = (SDL_HapticStopEffect(haptic, vibration.id) == 0); if (success) vibration.left = vibration.right = 0.0f; return success; }
bool Joystick::checkCreateHaptic() { if (!isConnected()) return false; if (!SDL_WasInit(SDL_INIT_HAPTIC) && SDL_InitSubSystem(SDL_INIT_HAPTIC) < 0) return false; if (haptic && SDL_HapticIndex(haptic) != -1) return true; if (haptic) { SDL_HapticClose(haptic); haptic = nullptr; } haptic = SDL_HapticOpenFromJoystick(joyhandle); vibration = Vibration(); return haptic != nullptr; }