53
/* Enable standard application logging */
54
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
58
60
if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) {
59
printf("USAGE: %s [device]\n"
61
SDL_Log("USAGE: %s [device]\n"
60
62
"If device is a two-digit number it'll use it as an index, otherwise\n"
61
63
"it'll use it as if it were part of the device's name.\n",
73
75
/* Initialize the force feedbackness */
74
76
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK |
76
printf("%d Haptic devices detected.\n", SDL_NumHaptics());
78
SDL_Log("%d Haptic devices detected.\n", SDL_NumHaptics());
77
79
if (SDL_NumHaptics() > 0) {
78
80
/* We'll just use index or the first force feedback device found */
79
81
if (name == NULL) {
89
91
if (i >= SDL_NumHaptics()) {
90
printf("Unable to find device matching '%s', aborting.\n",
92
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n",
96
98
haptic = SDL_HapticOpen(i);
97
99
if (haptic == NULL) {
98
printf("Unable to create the haptic device: %s\n",
100
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n",
102
printf("Device: %s\n", SDL_HapticName(i));
104
SDL_Log("Device: %s\n", SDL_HapticName(i));
104
printf("No Haptic devices found!\n");
106
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n");
109
111
SDL_ClearError();
111
113
if (SDL_HapticRumbleSupported(haptic) == SDL_FALSE) {
112
printf("\nRumble not supported!\n");
114
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Rumble not supported!\n");
115
117
if (SDL_HapticRumbleInit(haptic) != 0) {
116
printf("\nFailed to initialize rumble: %s\n", SDL_GetError());
118
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to initialize rumble: %s\n", SDL_GetError());
119
printf("Playing 2 second rumble at 0.5 magnitude.\n");
121
SDL_Log("Playing 2 second rumble at 0.5 magnitude.\n");
120
122
if (SDL_HapticRumblePlay(haptic, 0.5, 5000) != 0) {
121
printf("\nFailed to play rumble: %s\n", SDL_GetError() );
123
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError() );
125
printf("Stopping rumble.\n");
127
SDL_Log("Stopping rumble.\n");
126
128
SDL_HapticRumbleStop(haptic);
128
printf("Playing 2 second rumble at 0.3 magnitude.\n");
130
SDL_Log("Playing 2 second rumble at 0.3 magnitude.\n");
129
131
if (SDL_HapticRumblePlay(haptic, 0.3f, 5000) != 0) {
130
printf("\nFailed to play rumble: %s\n", SDL_GetError() );
132
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError() );
146
148
main(int argc, char *argv[])
148
fprintf(stderr, "SDL compiled without Haptic support.\n");
150
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Haptic support.\n");