diff options
| author | SND\edgbla_cp <SND\edgbla_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2011-04-17 19:19:31 +0000 |
|---|---|---|
| committer | SND\edgbla_cp <SND\edgbla_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2011-04-17 19:19:31 +0000 |
| commit | ff4d794ca262ba0b383a7cdfaf95f5cfe29faeb0 (patch) | |
| tree | df59e5fa085e9f24830d2384024a0ca2837ff596 /plugins/dfinput/sdljoy.c | |
| parent | 8e692627c341577078f4b63f78201cf7e1118f93 (diff) | |
| download | pcsxr-ff4d794ca262ba0b383a7cdfaf95f5cfe29faeb0.tar.gz | |
Patch 9013 (Edomato).
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@65925 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'plugins/dfinput/sdljoy.c')
| -rw-r--r-- | plugins/dfinput/sdljoy.c | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/plugins/dfinput/sdljoy.c b/plugins/dfinput/sdljoy.c index 750f26bb..a8bd9ce8 100644 --- a/plugins/dfinput/sdljoy.c +++ b/plugins/dfinput/sdljoy.c @@ -18,6 +18,70 @@ #include "pad.h" +#if SDL_VERSION_ATLEAST(1,3,0) +static SDL_HapticEffect haptic_rumbleEffect; +#endif + +void JoyInitHaptic() +{ +#if SDL_VERSION_ATLEAST(1,3,0) + uint8_t i; + unsigned int haptic_query = 0; + for (i = 0; i < 2; i++) + { + if (g.PadState[i].JoyDev && SDL_JoystickIsHaptic(g.PadState[i].JoyDev)) + { + if (g.PadState[i].haptic != NULL) + { + SDL_HapticClose(g.PadState[i].haptic); + g.PadState[i].haptic = NULL; + } + + g.PadState[i].haptic = SDL_HapticOpenFromJoystick(g.PadState[i].JoyDev); + if (g.PadState[i].haptic == NULL) + continue; + + if (SDL_HapticRumbleSupported(g.PadState[i].haptic) == SDL_FALSE) + { + printf("\nRumble not supported\n"); + g.PadState[i].haptic = NULL; + continue; + } + + if (SDL_HapticRumbleInit(g.PadState[i].haptic) != 0) + { + printf("\nFailed to initialize rumble: %s\n", SDL_GetError()); + g.PadState[i].haptic = NULL; + continue; + } + } + } +#endif +} + +int JoyHapticRumble(int pad, uint32_t low, uint32_t high) +{ +#if SDL_VERSION_ATLEAST(1,3,0) + float mag; + + if (g.PadState[pad].haptic) { + + /* Stop the effect if it was playing. */ + SDL_HapticRumbleStop(g.PadState[pad].haptic); + + mag = ((high * 2 + low) / 6) / 127.5; + //printf("low: %d high: %d mag: %f\n", low, high, mag); + + if(SDL_HapticRumblePlay(g.PadState[pad].haptic, mag, 500) != 0) + { + printf("\nFailed to play rumble: %s\n", SDL_GetError()); + return 1; + } + } +#endif + return 0; +} + void InitSDLJoy() { uint8_t i; @@ -30,8 +94,19 @@ void InitSDLJoy() { } else { g.PadState[i].JoyDev = NULL; } +#if !SDL_VERSION_ATLEAST(1,3,0) && defined(__linux__) + g.PadState[i].VibrateDev = -1; + g.PadState[i].VibrateEffect = -1; +#endif } +#if SDL_VERSION_ATLEAST(1,3,0) + if (has_haptic) + { + JoyInitHaptic(); + } +#endif + SDL_JoystickEventState(SDL_IGNORE); InitAnalog(); @@ -43,6 +118,13 @@ void DestroySDLJoy() { if (SDL_WasInit(SDL_INIT_JOYSTICK)) { for (i = 0; i < 2; i++) { if (g.PadState[i].JoyDev != NULL) { +#if SDL_VERSION_ATLEAST(1,3,0) + if (g.PadState[i].haptic != NULL) + { + SDL_HapticClose(g.PadState[i].haptic); + g.PadState[i].haptic = NULL; + } +#endif SDL_JoystickClose(g.PadState[i].JoyDev); } } |
