Adds controllermap utility to test suite.
authorGabriel Jacobo <gabomdq@gmail.com>
Mon, 02 Dec 2013 19:35:04 -0300
changeset 804374fcbf6987ba
parent 8042 7863121cb7d5
child 8044 e84427ef8244
Adds controllermap utility to test suite.
src/joystick/SDL_gamecontrollerdb.h
test/Makefile.in
test/README
test/axis.bmp
test/button.bmp
test/controllermap.bmp
test/controllermap.c
test/testgamecontroller.c
     1.1 --- a/src/joystick/SDL_gamecontrollerdb.h	Mon Dec 02 19:34:08 2013 -0300
     1.2 +++ b/src/joystick/SDL_gamecontrollerdb.h	Mon Dec 02 19:35:04 2013 -0300
     1.3 @@ -26,6 +26,8 @@
     1.4     The easiest way to generate a new mapping is to start Steam in Big Picture
     1.5     mode, configure your joystick and then look in config/config.vdf in your
     1.6     Steam installation directory for the "SDL_GamepadBind" entry.
     1.7 +   
     1.8 +   Alternatively, you can use the app located in test/controllermap
     1.9   */
    1.10  static const char *s_ControllerMappings [] =
    1.11  {
     2.1 --- a/test/Makefile.in	Mon Dec 02 19:34:08 2013 -0300
     2.2 +++ b/test/Makefile.in	Mon Dec 02 19:35:04 2013 -0300
     2.3 @@ -55,7 +55,8 @@
     2.4  	torturethread$(EXE) \
     2.5  	testrendercopyex$(EXE) \
     2.6  	testmessage$(EXE) \
     2.7 -
     2.8 +	controllermap$(EXE) \
     2.9 +	
    2.10  all: Makefile $(TARGETS)
    2.11  
    2.12  Makefile: $(srcdir)/Makefile.in
    2.13 @@ -238,6 +239,10 @@
    2.14  testmessage$(EXE): $(srcdir)/testmessage.c
    2.15  	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
    2.16  
    2.17 +controllermap$(EXE): $(srcdir)/controllermap.c
    2.18 +	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
    2.19 +
    2.20 +
    2.21  clean:
    2.22  	rm -f $(TARGETS)
    2.23  
     3.1 --- a/test/README	Mon Dec 02 19:34:08 2013 -0300
     3.2 +++ b/test/README	Mon Dec 02 19:35:04 2013 -0300
     3.3 @@ -25,3 +25,6 @@
     3.4  	testver		Check the version and dynamic loading and endianness
     3.5  	testwm2		Test window manager -- title, icon, events
     3.6  	torturethread	Simple test for thread creation/destruction
     3.7 +	controllermap   Useful to generate Game Controller API compatible maps
     3.8 +
     3.9 +
     4.1 Binary file test/axis.bmp has changed
     5.1 Binary file test/button.bmp has changed
     6.1 Binary file test/controllermap.bmp has changed
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/controllermap.c	Mon Dec 02 19:35:04 2013 -0300
     7.3 @@ -0,0 +1,432 @@
     7.4 +/*
     7.5 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     7.6 +
     7.7 +  This software is provided 'as-is', without any express or implied
     7.8 +  warranty.  In no event will the authors be held liable for any damages
     7.9 +  arising from the use of this software.
    7.10 +
    7.11 +  Permission is granted to anyone to use this software for any purpose,
    7.12 +  including commercial applications, and to alter it and redistribute it
    7.13 +  freely.
    7.14 +*/
    7.15 +
    7.16 +/* Game controller mapping generator */
    7.17 +/* Gabriel Jacobo <gabomdq@gmail.com> */
    7.18 +
    7.19 +#include <stdio.h>
    7.20 +#include <stdlib.h>
    7.21 +#include <string.h>
    7.22 +
    7.23 +#include "SDL.h"
    7.24 +
    7.25 +#ifndef SDL_JOYSTICK_DISABLED
    7.26 +
    7.27 +#ifdef __IPHONEOS__
    7.28 +#define SCREEN_WIDTH    320
    7.29 +#define SCREEN_HEIGHT   480
    7.30 +#else
    7.31 +#define SCREEN_WIDTH    512
    7.32 +#define SCREEN_HEIGHT   317
    7.33 +#endif
    7.34 +
    7.35 +#define MAP_WIDTH 512
    7.36 +#define MAP_HEIGHT 317
    7.37 +
    7.38 +#define MARKER_BUTTON 1
    7.39 +#define MARKER_AXIS 2
    7.40 +
    7.41 +typedef struct MappingStep
    7.42 +{
    7.43 +    int x, y;
    7.44 +    double angle;
    7.45 +    int marker;
    7.46 +    char *field;
    7.47 +    int axis, button, hat, hat_value;
    7.48 +    char mapping[4096];
    7.49 +}MappingStep;
    7.50 +
    7.51 +
    7.52 +SDL_Texture *
    7.53 +LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
    7.54 +{
    7.55 +    SDL_Surface *temp;
    7.56 +    SDL_Texture *texture;
    7.57 +
    7.58 +    /* Load the sprite image */
    7.59 +    temp = SDL_LoadBMP(file);
    7.60 +    if (temp == NULL) {
    7.61 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
    7.62 +        return NULL;
    7.63 +    }
    7.64 +
    7.65 +    /* Set transparent pixel as the pixel at (0,0) */
    7.66 +    if (transparent) {
    7.67 +        if (temp->format->palette) {
    7.68 +            SDL_SetColorKey(temp, SDL_TRUE, *(Uint8 *) temp->pixels);
    7.69 +        } else {
    7.70 +            switch (temp->format->BitsPerPixel) {
    7.71 +            case 15:
    7.72 +                SDL_SetColorKey(temp, SDL_TRUE,
    7.73 +                                (*(Uint16 *) temp->pixels) & 0x00007FFF);
    7.74 +                break;
    7.75 +            case 16:
    7.76 +                SDL_SetColorKey(temp, SDL_TRUE, *(Uint16 *) temp->pixels);
    7.77 +                break;
    7.78 +            case 24:
    7.79 +                SDL_SetColorKey(temp, SDL_TRUE,
    7.80 +                                (*(Uint32 *) temp->pixels) & 0x00FFFFFF);
    7.81 +                break;
    7.82 +            case 32:
    7.83 +                SDL_SetColorKey(temp, SDL_TRUE, *(Uint32 *) temp->pixels);
    7.84 +                break;
    7.85 +            }
    7.86 +        }
    7.87 +    }
    7.88 +
    7.89 +    /* Create textures from the image */
    7.90 +    texture = SDL_CreateTextureFromSurface(renderer, temp);
    7.91 +    if (!texture) {
    7.92 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
    7.93 +        SDL_FreeSurface(temp);
    7.94 +        return NULL;
    7.95 +    }
    7.96 +    SDL_FreeSurface(temp);
    7.97 +
    7.98 +    /* We're ready to roll. :) */
    7.99 +    return texture;
   7.100 +}
   7.101 +
   7.102 +static void
   7.103 +DrawRect(SDL_Renderer *r, const int x, const int y, const int w, const int h)
   7.104 +{
   7.105 +    const SDL_Rect area = { x, y, w, h };
   7.106 +    SDL_RenderFillRect(r, &area);
   7.107 +}
   7.108 +
   7.109 +static SDL_bool
   7.110 +WatchJoystick(SDL_Joystick * joystick)
   7.111 +{
   7.112 +    SDL_Window *window = NULL;
   7.113 +    SDL_Renderer *screen = NULL;
   7.114 +    SDL_Texture *target, *background, *button, *axis, *marker;
   7.115 +    const char *name = NULL;
   7.116 +    SDL_bool retval = SDL_FALSE;
   7.117 +    SDL_bool done = SDL_FALSE, next=SDL_FALSE;
   7.118 +    SDL_Event event;
   7.119 +    SDL_Rect dst;
   7.120 +    int i, s, _s;
   7.121 +    Uint8 alpha=200, alpha_step = -1;
   7.122 +    Uint32 alpha_ticks;
   7.123 +    char mapping[4096], temp[4096];
   7.124 +    MappingStep *step;
   7.125 +    MappingStep steps[] = {
   7.126 +        {342, 132,  0.0,  MARKER_BUTTON, "x", -1, -1, -1, -1, ""},
   7.127 +        {387, 167,  0.0,  MARKER_BUTTON, "a", -1, -1, -1, -1, ""},
   7.128 +        {431, 132,  0.0,  MARKER_BUTTON, "b", -1, -1, -1, -1, ""},
   7.129 +        {389, 101,  0.0,  MARKER_BUTTON, "y", -1, -1, -1, -1, ""},
   7.130 +        {174, 132,  0.0,  MARKER_BUTTON, "back", -1, -1, -1, -1, ""},
   7.131 +        {233, 132,  0.0,  MARKER_BUTTON, "guide", -1, -1, -1, -1, ""},
   7.132 +        {289, 132,  0.0,  MARKER_BUTTON, "start", -1, -1, -1, -1, ""},        
   7.133 +        {116, 217,  0.0,  MARKER_BUTTON, "dpleft", -1, -1, -1, -1, ""},
   7.134 +        {154, 249,  0.0,  MARKER_BUTTON, "dpdown", -1, -1, -1, -1, ""},
   7.135 +        {186, 217,  0.0,  MARKER_BUTTON, "dpright", -1, -1, -1, -1, ""},
   7.136 +        {154, 188,  0.0,  MARKER_BUTTON, "dpup", -1, -1, -1, -1, ""},
   7.137 +        {77,  40,   0.0,  MARKER_BUTTON, "leftshoulder", -1, -1, -1, -1, ""},
   7.138 +        {91, 0,    0.0,  MARKER_BUTTON, "lefttrigger", -1, -1, -1, -1, ""},
   7.139 +        {396, 36,   0.0,  MARKER_BUTTON, "rightshoulder", -1, -1, -1, -1, ""},
   7.140 +        {375, 0,    0.0,  MARKER_BUTTON, "righttrigger", -1, -1, -1, -1, ""},
   7.141 +        {75,  154,  0.0,  MARKER_BUTTON, "leftstick", -1, -1, -1, -1, ""},
   7.142 +        {305, 230,  0.0,  MARKER_BUTTON, "rightstick", -1, -1, -1, -1, ""},
   7.143 +        {75,  154,  0.0,  MARKER_AXIS,   "leftx", -1, -1, -1, -1, ""},
   7.144 +        {75,  154,  90.0, MARKER_AXIS,   "lefty", -1, -1, -1, -1, ""},        
   7.145 +        {305, 230,  0.0,  MARKER_AXIS,   "rightx", -1, -1, -1, -1, ""},
   7.146 +        {305, 230,  90.0, MARKER_AXIS,   "righty", -1, -1, -1, -1, ""},
   7.147 +    };
   7.148 +
   7.149 +    /* Create a window to display joystick axis position */
   7.150 +    window = SDL_CreateWindow("Joystick Test", SDL_WINDOWPOS_CENTERED,
   7.151 +                              SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
   7.152 +                              SCREEN_HEIGHT, 0);
   7.153 +    if (window == NULL) {
   7.154 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
   7.155 +        return SDL_FALSE;
   7.156 +    }
   7.157 +
   7.158 +    screen = SDL_CreateRenderer(window, -1, 0);
   7.159 +    if (screen == NULL) {
   7.160 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
   7.161 +        SDL_DestroyWindow(window);
   7.162 +        return SDL_FALSE;
   7.163 +    }
   7.164 +    
   7.165 +    target = SDL_CreateTexture(screen, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_TARGET, MAP_WIDTH, MAP_HEIGHT);
   7.166 +    background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
   7.167 +    button = LoadTexture(screen, "button.bmp", SDL_TRUE);
   7.168 +    axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);
   7.169 +    SDL_RaiseWindow(window);
   7.170 +
   7.171 +    /* Print info about the joystick we are watching */
   7.172 +    name = SDL_JoystickName(joystick);
   7.173 +    SDL_Log("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick),
   7.174 +           name ? name : "Unknown Joystick");
   7.175 +    SDL_Log("Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
   7.176 +           SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
   7.177 +           SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
   7.178 +    
   7.179 +    SDL_Log("\n\n\
   7.180 +    ====================================================================================\n\
   7.181 +    Press the buttons on your controller when indicated\n\
   7.182 +    (Your controller may look different than the picture)\n\
   7.183 +    If you want to correct a mistake, press backspace or the back button on your device\n\
   7.184 +    To exit, press ESC\n\
   7.185 +    ====================================================================================\n");
   7.186 +    
   7.187 +    /* Initialize mapping with GUID and name */
   7.188 +    SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, SDL_arraysize(temp));
   7.189 +    SDL_snprintf(mapping, SDL_arraysize(mapping), "%s,%s,platform:%s,",
   7.190 +        temp, name ? name : "Unknown Joystick", SDL_GetPlatform());
   7.191 +
   7.192 +    /* Loop, getting joystick events! */
   7.193 +    for(s=0; s<SDL_arraysize(steps) && !done;) {
   7.194 +        /* blank screen, set up for drawing this frame. */
   7.195 +        step = &steps[s];
   7.196 +        SDL_strlcpy(step->mapping, mapping, SDL_arraysize(step->mapping));
   7.197 +        step->axis = -1;
   7.198 +        step->button = -1;
   7.199 +        step->hat = -1;
   7.200 +        step->hat_value = -1;
   7.201 +        SDL_SetClipboardText("TESTING TESTING 123");
   7.202 +        
   7.203 +        switch(step->marker) {
   7.204 +            case MARKER_AXIS:
   7.205 +                marker = axis;
   7.206 +                break;
   7.207 +            case MARKER_BUTTON:
   7.208 +                marker = button;
   7.209 +                break;
   7.210 +            default:
   7.211 +                break;
   7.212 +        }
   7.213 +        
   7.214 +        dst.x = step->x;
   7.215 +        dst.y = step->y;
   7.216 +        SDL_QueryTexture(marker, NULL, NULL, &dst.w, &dst.h);
   7.217 +        next=SDL_FALSE;
   7.218 +        
   7.219 +        while (!done && !next) {
   7.220 +            if (SDL_GetTicks() - alpha_ticks > 5) {
   7.221 +                alpha_ticks = SDL_GetTicks();
   7.222 +                alpha += alpha_step;
   7.223 +                if (alpha == 255) {
   7.224 +                    alpha_step = -1;
   7.225 +                }
   7.226 +                if (alpha < 128) {
   7.227 +                    alpha_step = 1;
   7.228 +                }
   7.229 +            }
   7.230 +            
   7.231 +            SDL_SetRenderTarget(screen, target);
   7.232 +            SDL_RenderCopy(screen, background, NULL, NULL);
   7.233 +            SDL_SetTextureAlphaMod(marker, alpha);
   7.234 +            SDL_SetTextureColorMod(marker, 10, 255, 21);
   7.235 +            SDL_RenderCopyEx(screen, marker, NULL, &dst, step->angle, NULL, 0);
   7.236 +            SDL_SetRenderTarget(screen, NULL);
   7.237 +            SDL_RenderCopy(screen, target, NULL, NULL);
   7.238 +            SDL_RenderPresent(screen);
   7.239 +            
   7.240 +            if (SDL_PollEvent(&event)) {
   7.241 +                switch (event.type) {
   7.242 +                case SDL_JOYAXISMOTION:
   7.243 +                    if (event.jaxis.value > 20000 || event.jaxis.value < -20000) {
   7.244 +                        for (_s = 0; _s < s; _s++) {
   7.245 +                            if (steps[_s].axis == event.jaxis.axis) {
   7.246 +                                break;
   7.247 +                            }
   7.248 +                        }
   7.249 +                        if (_s == s) {
   7.250 +                            step->axis = event.jaxis.axis;
   7.251 +                            SDL_strlcat(mapping, step->field, SDL_arraysize(mapping));
   7.252 +                            SDL_snprintf(temp, SDL_arraysize(temp), ":a%u,", event.jaxis.axis);
   7.253 +                            SDL_strlcat(mapping, temp, SDL_arraysize(mapping));
   7.254 +                            s++;
   7.255 +                            next=SDL_TRUE;
   7.256 +                        }
   7.257 +                    }
   7.258 +                    
   7.259 +                    break;
   7.260 +                case SDL_JOYHATMOTION:
   7.261 +                        for (_s = 0; _s < s; _s++) {
   7.262 +                            if (steps[_s].hat == event.jhat.hat && steps[_s].hat_value == event.jhat.value) {
   7.263 +                                break;
   7.264 +                            }
   7.265 +                        }
   7.266 +                        if (_s == s) {
   7.267 +                            step->hat = event.jhat.hat;
   7.268 +                            step->hat_value = event.jhat.value;
   7.269 +                            SDL_strlcat(mapping, step->field, SDL_arraysize(mapping));
   7.270 +                            SDL_snprintf(temp, SDL_arraysize(temp), ":h%u.%u,", event.jhat.hat, event.jhat.value );
   7.271 +                            SDL_strlcat(mapping, temp, SDL_arraysize(mapping));
   7.272 +                            s++;
   7.273 +                            next=SDL_TRUE;
   7.274 +                        }
   7.275 +                    break;
   7.276 +                case SDL_JOYBALLMOTION:
   7.277 +                    break;
   7.278 +                case SDL_JOYBUTTONUP:
   7.279 +                    for (_s = 0; _s < s; _s++) {
   7.280 +                        if (steps[_s].button == event.jbutton.button) {
   7.281 +                            break;
   7.282 +                        }
   7.283 +                    }
   7.284 +                    if (_s == s) {
   7.285 +                        step->button = event.jbutton.button;
   7.286 +                        SDL_strlcat(mapping, step->field, SDL_arraysize(mapping));
   7.287 +                        SDL_snprintf(temp, SDL_arraysize(temp), ":b%u,", event.jbutton.button);
   7.288 +                        SDL_strlcat(mapping, temp, SDL_arraysize(mapping));
   7.289 +                        s++;
   7.290 +                        next=SDL_TRUE;
   7.291 +                    }
   7.292 +                    break;
   7.293 +                case SDL_KEYDOWN:
   7.294 +                    if (event.key.keysym.sym == SDLK_BACKSPACE || event.key.keysym.sym == SDLK_AC_BACK) {
   7.295 +                        /* Undo! */
   7.296 +                        if (s > 0) {
   7.297 +                            SDL_strlcpy(mapping, step->mapping, SDL_arraysize(step->mapping));
   7.298 +                            s--;
   7.299 +                            next = SDL_TRUE;
   7.300 +                        }
   7.301 +                        break;
   7.302 +                    }
   7.303 +                    if ((event.key.keysym.sym != SDLK_ESCAPE)) {
   7.304 +                        break;
   7.305 +                    }
   7.306 +                    /* Fall through to signal quit */
   7.307 +                case SDL_FINGERDOWN:
   7.308 +                case SDL_MOUSEBUTTONDOWN:
   7.309 +                case SDL_QUIT:
   7.310 +                    done = SDL_TRUE;
   7.311 +                    break;
   7.312 +                default:
   7.313 +                    break;
   7.314 +                }
   7.315 +            }
   7.316 +        }
   7.317 +
   7.318 +    }
   7.319 +
   7.320 +    if (s == SDL_arraysize(steps) ) {
   7.321 +        SDL_Log("Mapping:\n\n%s\n\n", mapping);
   7.322 +        /* Print to stdout as well so the user can cat the output somewhere */
   7.323 +        printf("%s\n", mapping);
   7.324 +    }
   7.325 +    
   7.326 +    while(SDL_PollEvent(&event)) {};
   7.327 +    
   7.328 +    SDL_DestroyRenderer(screen);
   7.329 +    SDL_DestroyWindow(window);
   7.330 +    return retval;
   7.331 +}
   7.332 +
   7.333 +int
   7.334 +main(int argc, char *argv[])
   7.335 +{
   7.336 +    const char *name;
   7.337 +    int i;
   7.338 +    SDL_Joystick *joystick;
   7.339 +
   7.340 +    /* Enable standard application logging */
   7.341 +    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);	
   7.342 +
   7.343 +    /* Initialize SDL (Note: video is required to start event loop) */
   7.344 +    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
   7.345 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
   7.346 +        exit(1);
   7.347 +    }
   7.348 +
   7.349 +    /* Print information about the joysticks */
   7.350 +    SDL_Log("There are %d joysticks attached\n", SDL_NumJoysticks());
   7.351 +    for (i = 0; i < SDL_NumJoysticks(); ++i) {
   7.352 +        name = SDL_JoystickNameForIndex(i);
   7.353 +        SDL_Log("Joystick %d: %s\n", i, name ? name : "Unknown Joystick");
   7.354 +        joystick = SDL_JoystickOpen(i);
   7.355 +        if (joystick == NULL) {
   7.356 +            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_JoystickOpen(%d) failed: %s\n", i,
   7.357 +                    SDL_GetError());
   7.358 +        } else {
   7.359 +            char guid[64];
   7.360 +            SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick),
   7.361 +                                      guid, sizeof (guid));
   7.362 +            SDL_Log("       axes: %d\n", SDL_JoystickNumAxes(joystick));
   7.363 +            SDL_Log("      balls: %d\n", SDL_JoystickNumBalls(joystick));
   7.364 +            SDL_Log("       hats: %d\n", SDL_JoystickNumHats(joystick));
   7.365 +            SDL_Log("    buttons: %d\n", SDL_JoystickNumButtons(joystick));
   7.366 +            SDL_Log("instance id: %d\n", SDL_JoystickInstanceID(joystick));
   7.367 +            SDL_Log("       guid: %s\n", guid);
   7.368 +            SDL_JoystickClose(joystick);
   7.369 +        }
   7.370 +    }
   7.371 +
   7.372 +#ifdef ANDROID
   7.373 +    if (SDL_NumJoysticks() > 0) {
   7.374 +#else
   7.375 +    if (argv[1]) {
   7.376 +#endif
   7.377 +        SDL_bool reportederror = SDL_FALSE;
   7.378 +        SDL_bool keepGoing = SDL_TRUE;
   7.379 +        SDL_Event event;
   7.380 +#ifdef ANDROID
   7.381 +        joystick = SDL_JoystickOpen(0);
   7.382 +#else
   7.383 +        joystick = SDL_JoystickOpen(atoi(argv[1]));
   7.384 +#endif
   7.385 +        while ( keepGoing ) {
   7.386 +            if (joystick == NULL) {
   7.387 +                if ( !reportederror ) {
   7.388 +                    SDL_Log("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError());
   7.389 +                    keepGoing = SDL_FALSE;
   7.390 +                    reportederror = SDL_TRUE;
   7.391 +                }
   7.392 +            } else {
   7.393 +                reportederror = SDL_FALSE;
   7.394 +                keepGoing = WatchJoystick(joystick);
   7.395 +                SDL_JoystickClose(joystick);
   7.396 +            }
   7.397 +
   7.398 +            joystick = NULL;
   7.399 +            if (keepGoing) {
   7.400 +                SDL_Log("Waiting for attach\n");
   7.401 +            }
   7.402 +            while (keepGoing) {
   7.403 +                SDL_WaitEvent(&event);
   7.404 +                if ((event.type == SDL_QUIT) || (event.type == SDL_FINGERDOWN)
   7.405 +                    || (event.type == SDL_MOUSEBUTTONDOWN)) {
   7.406 +                    keepGoing = SDL_FALSE;
   7.407 +                } else if (event.type == SDL_JOYDEVICEADDED) {
   7.408 +                    joystick = SDL_JoystickOpen(atoi(argv[1]));
   7.409 +                    break;
   7.410 +                }
   7.411 +            }
   7.412 +        }
   7.413 +    }
   7.414 +    else {
   7.415 +        SDL_Log("\n\nUsage: ./controllermap number\nFor example: ./controllermap 0\nOr: ./controllermap 0 >> gamecontrollerdb.txt");
   7.416 +    }
   7.417 +    SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
   7.418 +
   7.419 +#ifdef ANDROID
   7.420 +    exit(0);
   7.421 +#else
   7.422 +    return 0;
   7.423 +#endif
   7.424 +}
   7.425 +
   7.426 +#else
   7.427 +
   7.428 +int
   7.429 +main(int argc, char *argv[])
   7.430 +{
   7.431 +    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Joystick support.\n");
   7.432 +    exit(1);
   7.433 +}
   7.434 +
   7.435 +#endif
     8.1 --- a/test/testgamecontroller.c	Mon Dec 02 19:34:08 2013 -0300
     8.2 +++ b/test/testgamecontroller.c	Mon Dec 02 19:35:04 2013 -0300
     8.3 @@ -225,6 +225,8 @@
     8.4          SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
     8.5          return 1;
     8.6      }
     8.7 +    
     8.8 +    SDL_GameControllerAddMappingsFromFile("gamecontrollerdb.txt");
     8.9  
    8.10      /* Print information about the controller */
    8.11      for (i = 0; i < SDL_NumJoysticks(); ++i) {