test/testjoystick.c
changeset 7639 9406b7dd2f2d
parent 7517 965d57022c01
child 8048 a9c5ddad50b0
     1.1 --- a/test/testjoystick.c	Mon Aug 12 22:00:21 2013 -0700
     1.2 +++ b/test/testjoystick.c	Wed Aug 14 23:30:10 2013 -0700
     1.3 @@ -52,13 +52,13 @@
     1.4                                SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
     1.5                                SCREEN_HEIGHT, 0);
     1.6      if (window == NULL) {
     1.7 -        fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
     1.8 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
     1.9          return SDL_FALSE;
    1.10      }
    1.11  
    1.12      screen = SDL_CreateRenderer(window, -1, 0);
    1.13      if (screen == NULL) {
    1.14 -        fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError());
    1.15 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
    1.16          SDL_DestroyWindow(window);
    1.17          return SDL_FALSE;
    1.18      }
    1.19 @@ -70,9 +70,9 @@
    1.20  
    1.21      /* Print info about the joystick we are watching */
    1.22      name = SDL_JoystickName(joystick);
    1.23 -    printf("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick),
    1.24 +    SDL_Log("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick),
    1.25             name ? name : "Unknown Joystick");
    1.26 -    printf("Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
    1.27 +    SDL_Log("Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
    1.28             SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
    1.29             SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
    1.30  
    1.31 @@ -85,36 +85,36 @@
    1.32          while (SDL_PollEvent(&event)) {
    1.33              switch (event.type) {
    1.34              case SDL_JOYAXISMOTION:
    1.35 -                printf("Joystick %d axis %d value: %d\n",
    1.36 +                SDL_Log("Joystick %d axis %d value: %d\n",
    1.37                         event.jaxis.which,
    1.38                         event.jaxis.axis, event.jaxis.value);
    1.39                  break;
    1.40              case SDL_JOYHATMOTION:
    1.41 -                printf("Joystick %d hat %d value:",
    1.42 +                SDL_Log("Joystick %d hat %d value:",
    1.43                         event.jhat.which, event.jhat.hat);
    1.44                  if (event.jhat.value == SDL_HAT_CENTERED)
    1.45 -                    printf(" centered");
    1.46 +                    SDL_Log(" centered");
    1.47                  if (event.jhat.value & SDL_HAT_UP)
    1.48 -                    printf(" up");
    1.49 +                    SDL_Log(" up");
    1.50                  if (event.jhat.value & SDL_HAT_RIGHT)
    1.51 -                    printf(" right");
    1.52 +                    SDL_Log(" right");
    1.53                  if (event.jhat.value & SDL_HAT_DOWN)
    1.54 -                    printf(" down");
    1.55 +                    SDL_Log(" down");
    1.56                  if (event.jhat.value & SDL_HAT_LEFT)
    1.57 -                    printf(" left");
    1.58 -                printf("\n");
    1.59 +                    SDL_Log(" left");
    1.60 +                SDL_Log("\n");
    1.61                  break;
    1.62              case SDL_JOYBALLMOTION:
    1.63 -                printf("Joystick %d ball %d delta: (%d,%d)\n",
    1.64 +                SDL_Log("Joystick %d ball %d delta: (%d,%d)\n",
    1.65                         event.jball.which,
    1.66                         event.jball.ball, event.jball.xrel, event.jball.yrel);
    1.67                  break;
    1.68              case SDL_JOYBUTTONDOWN:
    1.69 -                printf("Joystick %d button %d down\n",
    1.70 +                SDL_Log("Joystick %d button %d down\n",
    1.71                         event.jbutton.which, event.jbutton.button);
    1.72                  break;
    1.73              case SDL_JOYBUTTONUP:
    1.74 -                printf("Joystick %d button %d up\n",
    1.75 +                SDL_Log("Joystick %d button %d up\n",
    1.76                         event.jbutton.which, event.jbutton.button);
    1.77                  break;
    1.78              case SDL_KEYDOWN:
    1.79 @@ -211,31 +211,34 @@
    1.80      int i;
    1.81      SDL_Joystick *joystick;
    1.82  
    1.83 +    /* Enable standard application logging */
    1.84 +    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);	
    1.85 +
    1.86      /* Initialize SDL (Note: video is required to start event loop) */
    1.87      if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
    1.88 -        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    1.89 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
    1.90          exit(1);
    1.91      }
    1.92  
    1.93      /* Print information about the joysticks */
    1.94 -    printf("There are %d joysticks attached\n", SDL_NumJoysticks());
    1.95 +    SDL_Log("There are %d joysticks attached\n", SDL_NumJoysticks());
    1.96      for (i = 0; i < SDL_NumJoysticks(); ++i) {
    1.97          name = SDL_JoystickNameForIndex(i);
    1.98 -        printf("Joystick %d: %s\n", i, name ? name : "Unknown Joystick");
    1.99 +        SDL_Log("Joystick %d: %s\n", i, name ? name : "Unknown Joystick");
   1.100          joystick = SDL_JoystickOpen(i);
   1.101          if (joystick == NULL) {
   1.102 -            fprintf(stderr, "SDL_JoystickOpen(%d) failed: %s\n", i,
   1.103 +            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_JoystickOpen(%d) failed: %s\n", i,
   1.104                      SDL_GetError());
   1.105          } else {
   1.106              char guid[64];
   1.107              SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick),
   1.108                                        guid, sizeof (guid));
   1.109 -            printf("       axes: %d\n", SDL_JoystickNumAxes(joystick));
   1.110 -            printf("      balls: %d\n", SDL_JoystickNumBalls(joystick));
   1.111 -            printf("       hats: %d\n", SDL_JoystickNumHats(joystick));
   1.112 -            printf("    buttons: %d\n", SDL_JoystickNumButtons(joystick));
   1.113 -            printf("instance id: %d\n", SDL_JoystickInstanceID(joystick));
   1.114 -            printf("       guid: %s\n", guid);
   1.115 +            SDL_Log("       axes: %d\n", SDL_JoystickNumAxes(joystick));
   1.116 +            SDL_Log("      balls: %d\n", SDL_JoystickNumBalls(joystick));
   1.117 +            SDL_Log("       hats: %d\n", SDL_JoystickNumHats(joystick));
   1.118 +            SDL_Log("    buttons: %d\n", SDL_JoystickNumButtons(joystick));
   1.119 +            SDL_Log("instance id: %d\n", SDL_JoystickInstanceID(joystick));
   1.120 +            SDL_Log("       guid: %s\n", guid);
   1.121              SDL_JoystickClose(joystick);
   1.122          }
   1.123      }
   1.124 @@ -256,7 +259,7 @@
   1.125          while ( keepGoing ) {
   1.126              if (joystick == NULL) {
   1.127                  if ( !reportederror ) {
   1.128 -                    printf("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError());
   1.129 +                    SDL_Log("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError());
   1.130                      keepGoing = SDL_FALSE;
   1.131                      reportederror = SDL_TRUE;
   1.132                  }
   1.133 @@ -268,7 +271,7 @@
   1.134  
   1.135              joystick = NULL;
   1.136              if (keepGoing) {
   1.137 -                printf("Waiting for attach\n");
   1.138 +                SDL_Log("Waiting for attach\n");
   1.139              }
   1.140              while (keepGoing) {
   1.141                  SDL_WaitEvent(&event);
   1.142 @@ -296,7 +299,7 @@
   1.143  int
   1.144  main(int argc, char *argv[])
   1.145  {
   1.146 -    fprintf(stderr, "SDL compiled without Joystick support.\n");
   1.147 +    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Joystick support.\n");
   1.148      exit(1);
   1.149  }
   1.150