comparison test/testjoystick.c @ 4071:3d9040dcc47e SDL-1.2

Dump more information about each joystick in testjoytick.c
author Ryan C. Gordon <icculus@icculus.org>
date Sun, 15 Jul 2007 16:33:45 +0000
parents 5ff2c01e475e
children 0dd0ca51d941
comparison
equal deleted inserted replaced
4070:b8f2db95145e 4071:3d9040dcc47e
156 } 156 }
157 157
158 /* Print information about the joysticks */ 158 /* Print information about the joysticks */
159 printf("There are %d joysticks attached\n", SDL_NumJoysticks()); 159 printf("There are %d joysticks attached\n", SDL_NumJoysticks());
160 for ( i=0; i<SDL_NumJoysticks(); ++i ) { 160 for ( i=0; i<SDL_NumJoysticks(); ++i ) {
161 SDL_Joystick *stick = NULL;
161 name = SDL_JoystickName(i); 162 name = SDL_JoystickName(i);
162 printf("Joystick %d: %s\n",i,name ? name : "Unknown Joystick"); 163 printf("Joystick %d: %s\n",i,name ? name : "Unknown Joystick");
164 stick = SDL_JoystickOpen(i);
165 if (stick == NULL) {
166 fprintf(stderr, "SDL_JoystickOpen(%d) failed: %s\n", i, SDL_GetError());
167 } else {
168 printf(" axes: %d\n", SDL_JoystickNumAxes(stick));
169 printf(" balls: %d\n", SDL_JoystickNumBalls(stick));
170 printf(" hats: %d\n", SDL_JoystickNumHats(stick));
171 printf(" buttons: %d\n", SDL_JoystickNumButtons(stick));
172 SDL_JoystickClose(stick);
173 }
163 } 174 }
164 175
165 if ( argv[1] ) { 176 if ( argv[1] ) {
166 joystick = SDL_JoystickOpen(atoi(argv[1])); 177 joystick = SDL_JoystickOpen(atoi(argv[1]));
167 if ( joystick == NULL ) { 178 if ( joystick == NULL ) {