test/testhotplug.c
changeset 8188 47b9ab82bebf
parent 8181 3632013330ad
child 8776 29aac8b813d9
     1.1 --- a/test/testhotplug.c	Fri Feb 07 09:35:13 2014 -0500
     1.2 +++ b/test/testhotplug.c	Fri Feb 07 09:35:33 2014 -0500
     1.3 @@ -19,7 +19,7 @@
     1.4  #include "SDL.h"
     1.5  #include "SDL_haptic.h"
     1.6  
     1.7 -#ifndef SDL_JOYSTICK_DISABLED
     1.8 +#if !defined SDL_JOYSTICK_DISABLED && !defined SDL_HAPTIC_DISABLED
     1.9  
    1.10  int
    1.11  main(int argc, char *argv[])
    1.12 @@ -28,14 +28,27 @@
    1.13      SDL_Haptic *haptic = NULL;
    1.14      SDL_JoystickID instance = -1;
    1.15      SDL_bool keepGoing = SDL_TRUE;
    1.16 +    int i;
    1.17 +    SDL_bool enable_haptic = SDL_TRUE;
    1.18 +    Uint32 init_subsystems = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK;
    1.19 +    
    1.20 +    for (i = 1; i < argc; ++i) {
    1.21 +        if (SDL_strcasecmp(argv[i], "--nohaptic") == 0) {
    1.22 +            enable_haptic = SDL_FALSE;
    1.23 +        }
    1.24 +    }
    1.25  
    1.26 +    if(enable_haptic) {
    1.27 +        init_subsystems |= SDL_INIT_HAPTIC;
    1.28 +    }
    1.29 +    
    1.30      /* Enable standard application logging */
    1.31      SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);	
    1.32  
    1.33      SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
    1.34  
    1.35      /* Initialize SDL (Note: video is required to start event loop) */
    1.36 -    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) < 0) {
    1.37 +    if (SDL_Init(init_subsystems) < 0) {
    1.38          SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
    1.39          exit(1);
    1.40      }
    1.41 @@ -43,7 +56,8 @@
    1.42      //SDL_CreateWindow("Dummy", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 128, 128, 0);
    1.43  
    1.44      SDL_Log("There are %d joysticks at startup\n", SDL_NumJoysticks());
    1.45 -    SDL_Log("There are %d haptic devices at startup\n", SDL_NumHaptics());
    1.46 +    if (enable_haptic)
    1.47 +        SDL_Log("There are %d haptic devices at startup\n", SDL_NumHaptics());
    1.48  
    1.49      while(keepGoing)
    1.50      {
    1.51 @@ -65,25 +79,28 @@
    1.52                          joystick = SDL_JoystickOpen(event.jdevice.which);
    1.53                          instance = SDL_JoystickInstanceID(joystick);
    1.54                          SDL_Log("Joy Added  : %d : %s\n", event.jdevice.which, SDL_JoystickName(joystick));
    1.55 -                        if (SDL_JoystickIsHaptic(joystick))
    1.56 +                        if (enable_haptic)
    1.57                          {
    1.58 -                            haptic = SDL_HapticOpenFromJoystick(joystick);
    1.59 -                            if (haptic)
    1.60 +                            if (SDL_JoystickIsHaptic(joystick))
    1.61                              {
    1.62 -                                SDL_Log("Joy Haptic Opened\n");
    1.63 -                                if (SDL_HapticRumbleInit( haptic ) != 0)
    1.64 +                                haptic = SDL_HapticOpenFromJoystick(joystick);
    1.65 +                                if (haptic)
    1.66                                  {
    1.67 -                                    SDL_Log("Could not init Rumble!: %s\n", SDL_GetError());
    1.68 -                                    SDL_HapticClose(haptic);
    1.69 -                                    haptic = NULL;
    1.70 +                                    SDL_Log("Joy Haptic Opened\n");
    1.71 +                                    if (SDL_HapticRumbleInit( haptic ) != 0)
    1.72 +                                    {
    1.73 +                                        SDL_Log("Could not init Rumble!: %s\n", SDL_GetError());
    1.74 +                                        SDL_HapticClose(haptic);
    1.75 +                                        haptic = NULL;
    1.76 +                                    }
    1.77 +                                } else {
    1.78 +                                    SDL_Log("Joy haptic open FAILED!: %s\n", SDL_GetError());
    1.79                                  }
    1.80 -                            } else {
    1.81 -                                SDL_Log("Joy haptic open FAILED!: %s\n", SDL_GetError());
    1.82                              }
    1.83 -                        }
    1.84 -                        else
    1.85 -                        {
    1.86 -                            SDL_Log("No haptic found\n");
    1.87 +                            else
    1.88 +                            {
    1.89 +                                SDL_Log("No haptic found\n");
    1.90 +                            }
    1.91                          }
    1.92                      }
    1.93                      break;
    1.94 @@ -92,7 +109,7 @@
    1.95                      {
    1.96                          SDL_Log("Joy Removed: %d\n", event.jdevice.which);
    1.97                          instance = -1;
    1.98 -                        if(haptic)
    1.99 +                        if(enable_haptic && haptic)
   1.100                          {
   1.101                              SDL_HapticClose(haptic);
   1.102                              haptic = NULL;
   1.103 @@ -105,13 +122,14 @@
   1.104                      break;
   1.105                  case SDL_JOYAXISMOTION:
   1.106  //                    SDL_Log("Axis Move: %d\n", event.jaxis.axis);
   1.107 -                    SDL_HapticRumblePlay(haptic, 0.2, 250);
   1.108 +                    if (enable_haptic)
   1.109 +                        SDL_HapticRumblePlay(haptic, 0.25, 250);
   1.110                      break;
   1.111                  case SDL_JOYBUTTONDOWN:
   1.112                      SDL_Log("Button Press: %d\n", event.jbutton.button);
   1.113 -                    if(haptic)
   1.114 +                    if(enable_haptic && haptic)
   1.115                      {
   1.116 -                        SDL_HapticRumblePlay(haptic, 0.2, 250);
   1.117 +                        SDL_HapticRumblePlay(haptic, 0.25, 250);
   1.118                      }
   1.119  					if (event.jbutton.button == 0) {
   1.120  						SDL_Log("Exiting due to button press of button 0\n");
   1.121 @@ -125,7 +143,7 @@
   1.122          }
   1.123      }
   1.124  
   1.125 -    SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
   1.126 +    SDL_Quit();
   1.127  
   1.128      return 0;
   1.129  }
   1.130 @@ -134,7 +152,7 @@
   1.131  int
   1.132  main(int argc, char *argv[])
   1.133  {
   1.134 -    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Joystick support.\n");
   1.135 +    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Joystick and haptic support.\n");
   1.136      return 1;
   1.137  }
   1.138