test/testrumble.c
changeset 7639 9406b7dd2f2d
parent 7517 965d57022c01
child 8149 681eb46b8ac4
     1.1 --- a/test/testrumble.c	Mon Aug 12 22:00:21 2013 -0700
     1.2 +++ b/test/testrumble.c	Wed Aug 14 23:30:10 2013 -0700
     1.3 @@ -26,7 +26,6 @@
     1.4   * includes
     1.5   */
     1.6  #include <stdlib.h>
     1.7 -#include <stdio.h>              /* printf */
     1.8  #include <string.h>             /* strstr */
     1.9  #include <ctype.h>              /* isdigit */
    1.10  
    1.11 @@ -51,12 +50,15 @@
    1.12      char *name;
    1.13      int index;
    1.14  
    1.15 +	/* Enable standard application logging */
    1.16 +    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
    1.17 +
    1.18      name = NULL;
    1.19      index = -1;
    1.20      if (argc > 1) {
    1.21          name = argv[1];
    1.22          if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) {
    1.23 -            printf("USAGE: %s [device]\n"
    1.24 +            SDL_Log("USAGE: %s [device]\n"
    1.25                     "If device is a two-digit number it'll use it as an index, otherwise\n"
    1.26                     "it'll use it as if it were part of the device's name.\n",
    1.27                     argv[0]);
    1.28 @@ -73,7 +75,7 @@
    1.29      /* Initialize the force feedbackness */
    1.30      SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK |
    1.31               SDL_INIT_HAPTIC);
    1.32 -    printf("%d Haptic devices detected.\n", SDL_NumHaptics());
    1.33 +    SDL_Log("%d Haptic devices detected.\n", SDL_NumHaptics());
    1.34      if (SDL_NumHaptics() > 0) {
    1.35          /* We'll just use index or the first force feedback device found */
    1.36          if (name == NULL) {
    1.37 @@ -87,7 +89,7 @@
    1.38              }
    1.39  
    1.40              if (i >= SDL_NumHaptics()) {
    1.41 -                printf("Unable to find device matching '%s', aborting.\n",
    1.42 +                SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n",
    1.43                         name);
    1.44                  return 1;
    1.45              }
    1.46 @@ -95,13 +97,13 @@
    1.47  
    1.48          haptic = SDL_HapticOpen(i);
    1.49          if (haptic == NULL) {
    1.50 -            printf("Unable to create the haptic device: %s\n",
    1.51 +            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n",
    1.52                     SDL_GetError());
    1.53              return 1;
    1.54          }
    1.55 -        printf("Device: %s\n", SDL_HapticName(i));
    1.56 +        SDL_Log("Device: %s\n", SDL_HapticName(i));
    1.57      } else {
    1.58 -        printf("No Haptic devices found!\n");
    1.59 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n");
    1.60          return 1;
    1.61      }
    1.62  
    1.63 @@ -109,25 +111,25 @@
    1.64      SDL_ClearError();
    1.65  
    1.66      if (SDL_HapticRumbleSupported(haptic) == SDL_FALSE) {
    1.67 -        printf("\nRumble not supported!\n");
    1.68 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Rumble not supported!\n");
    1.69          return 1;
    1.70      }
    1.71      if (SDL_HapticRumbleInit(haptic) != 0) {
    1.72 -        printf("\nFailed to initialize rumble: %s\n", SDL_GetError());
    1.73 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to initialize rumble: %s\n", SDL_GetError());
    1.74          return 1;
    1.75      }
    1.76 -    printf("Playing 2 second rumble at 0.5 magnitude.\n");
    1.77 +    SDL_Log("Playing 2 second rumble at 0.5 magnitude.\n");
    1.78      if (SDL_HapticRumblePlay(haptic, 0.5, 5000) != 0) {
    1.79 -       printf("\nFailed to play rumble: %s\n", SDL_GetError() );
    1.80 +       SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError() );
    1.81         return 1;
    1.82      }
    1.83      SDL_Delay(2000);
    1.84 -    printf("Stopping rumble.\n");
    1.85 +    SDL_Log("Stopping rumble.\n");
    1.86      SDL_HapticRumbleStop(haptic);
    1.87      SDL_Delay(2000);
    1.88 -    printf("Playing 2 second rumble at 0.3 magnitude.\n");
    1.89 +    SDL_Log("Playing 2 second rumble at 0.3 magnitude.\n");
    1.90      if (SDL_HapticRumblePlay(haptic, 0.3f, 5000) != 0) {
    1.91 -       printf("\nFailed to play rumble: %s\n", SDL_GetError() );
    1.92 +       SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError() );
    1.93         return 1;
    1.94      }
    1.95      SDL_Delay(2000);
    1.96 @@ -145,7 +147,7 @@
    1.97  int
    1.98  main(int argc, char *argv[])
    1.99  {
   1.100 -    fprintf(stderr, "SDL compiled without Haptic support.\n");
   1.101 +    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Haptic support.\n");
   1.102      exit(1);
   1.103  }
   1.104