forked from Green-Sky/tomato
sdl (master post 3.1 preview) Merge commit 'e4f454091a943345938608570b104400f62fd625'
This commit is contained in:
51
external/sdl/SDL/test/testrumble.c
vendored
51
external/sdl/SDL/test/testrumble.c
vendored
@@ -39,6 +39,8 @@ int main(int argc, char **argv)
|
||||
char *name = NULL;
|
||||
int index;
|
||||
SDLTest_CommonState *state;
|
||||
SDL_HapticID *haptics;
|
||||
int num_haptics;
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, 0);
|
||||
@@ -85,37 +87,48 @@ int main(int argc, char **argv)
|
||||
/* Initialize the force feedbackness */
|
||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK |
|
||||
SDL_INIT_HAPTIC);
|
||||
SDL_Log("%d Haptic devices detected.\n", SDL_NumHaptics());
|
||||
if (SDL_NumHaptics() > 0) {
|
||||
haptics = SDL_GetHaptics(&num_haptics);
|
||||
SDL_Log("%d Haptic devices detected.\n", num_haptics);
|
||||
if (haptics) {
|
||||
if (num_haptics == 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n");
|
||||
SDL_free(haptics);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* We'll just use index or the first force feedback device found */
|
||||
if (!name) {
|
||||
i = (index != -1) ? index : 0;
|
||||
|
||||
if (i >= num_haptics) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Index out of range, aborting.\n");
|
||||
SDL_free(haptics);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/* Try to find matching device */
|
||||
else {
|
||||
for (i = 0; i < SDL_NumHaptics(); i++) {
|
||||
if (SDL_strstr(SDL_HapticName(i), name) != NULL) {
|
||||
for (i = 0; i < num_haptics; i++) {
|
||||
if (SDL_strstr(SDL_GetHapticInstanceName(haptics[i]), name) != NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= SDL_NumHaptics()) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n",
|
||||
name);
|
||||
if (i >= num_haptics) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n", name);
|
||||
SDL_free(haptics);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
haptic = SDL_HapticOpen(i);
|
||||
haptic = SDL_OpenHaptic(haptics[i]);
|
||||
if (!haptic) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n", SDL_GetError());
|
||||
SDL_free(haptics);
|
||||
return 1;
|
||||
}
|
||||
SDL_Log("Device: %s\n", SDL_HapticName(i));
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n");
|
||||
return 1;
|
||||
SDL_Log("Device: %s\n", SDL_GetHapticName(haptic));
|
||||
SDL_free(haptics);
|
||||
}
|
||||
|
||||
/* We only want force feedback errors. */
|
||||
@@ -125,21 +138,21 @@ int main(int argc, char **argv)
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Rumble not supported!\n");
|
||||
return 1;
|
||||
}
|
||||
if (SDL_HapticRumbleInit(haptic) != 0) {
|
||||
if (SDL_InitHapticRumble(haptic) != 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to initialize rumble: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
SDL_Log("Playing 2 second rumble at 0.5 magnitude.\n");
|
||||
if (SDL_HapticRumblePlay(haptic, 0.5, 5000) != 0) {
|
||||
if (SDL_PlayHapticRumble(haptic, 0.5, 5000) != 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
SDL_Delay(2000);
|
||||
SDL_Log("Stopping rumble.\n");
|
||||
SDL_HapticRumbleStop(haptic);
|
||||
SDL_StopHapticRumble(haptic);
|
||||
SDL_Delay(2000);
|
||||
SDL_Log("Playing 2 second rumble at 0.3 magnitude.\n");
|
||||
if (SDL_HapticRumblePlay(haptic, 0.3f, 5000) != 0) {
|
||||
if (SDL_PlayHapticRumble(haptic, 0.3f, 5000) != 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
@@ -147,7 +160,7 @@ int main(int argc, char **argv)
|
||||
|
||||
/* Quit */
|
||||
if (haptic) {
|
||||
SDL_HapticClose(haptic);
|
||||
SDL_CloseHaptic(haptic);
|
||||
}
|
||||
|
||||
SDL_Quit();
|
||||
|
||||
Reference in New Issue
Block a user