test/controllermap.c
changeset 8078 ef59ad725ac5
parent 8077 05bbcc1056e6
child 8149 681eb46b8ac4
equal deleted inserted replaced
8077:05bbcc1056e6 8078:ef59ad725ac5
   384     if (argv[1]) {
   384     if (argv[1]) {
   385 #endif
   385 #endif
   386         SDL_bool reportederror = SDL_FALSE;
   386         SDL_bool reportederror = SDL_FALSE;
   387         SDL_bool keepGoing = SDL_TRUE;
   387         SDL_bool keepGoing = SDL_TRUE;
   388         SDL_Event event;
   388         SDL_Event event;
       
   389         int device;
   389 #ifdef ANDROID
   390 #ifdef ANDROID
   390         joystick = SDL_JoystickOpen(0);
   391         device = 0;
   391 #else
   392 #else
   392         joystick = SDL_JoystickOpen(atoi(argv[1]));
   393         device = atoi(argv[1]);
   393 #endif
   394 #endif
       
   395         joystick = SDL_JoystickOpen(device);
       
   396 
   394         while ( keepGoing ) {
   397         while ( keepGoing ) {
   395             if (joystick == NULL) {
   398             if (joystick == NULL) {
   396                 if ( !reportederror ) {
   399                 if ( !reportederror ) {
   397                     SDL_Log("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError());
   400                     SDL_Log("Couldn't open joystick %d: %s\n", device, SDL_GetError());
   398                     keepGoing = SDL_FALSE;
   401                     keepGoing = SDL_FALSE;
   399                     reportederror = SDL_TRUE;
   402                     reportederror = SDL_TRUE;
   400                 }
   403                 }
   401             } else {
   404             } else {
   402                 reportederror = SDL_FALSE;
   405                 reportederror = SDL_FALSE;
   412                 SDL_WaitEvent(&event);
   415                 SDL_WaitEvent(&event);
   413                 if ((event.type == SDL_QUIT) || (event.type == SDL_FINGERDOWN)
   416                 if ((event.type == SDL_QUIT) || (event.type == SDL_FINGERDOWN)
   414                     || (event.type == SDL_MOUSEBUTTONDOWN)) {
   417                     || (event.type == SDL_MOUSEBUTTONDOWN)) {
   415                     keepGoing = SDL_FALSE;
   418                     keepGoing = SDL_FALSE;
   416                 } else if (event.type == SDL_JOYDEVICEADDED) {
   419                 } else if (event.type == SDL_JOYDEVICEADDED) {
   417                     joystick = SDL_JoystickOpen(atoi(argv[1]));
   420                     joystick = SDL_JoystickOpen(device);
   418                     break;
   421                     break;
   419                 }
   422                 }
   420             }
   423             }
   421         }
   424         }
   422     }
   425     }