22 #ifndef SDL_JOYSTICK_DISABLED
25 #define SCREEN_WIDTH 320
26 #define SCREEN_HEIGHT 480
28 #define SCREEN_WIDTH 512
29 #define SCREEN_HEIGHT 320
32 #define MARKER_BUTTON 1
50 #define BINDING_COUNT (SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_MAX)
219 for (iIndex = 0; iIndex <
s_nNumAxes; ++iIndex) {
247 return (minA <= minB && maxA >= maxB);
251 return SDL_memcmp(pBindingA, pBindingB,
sizeof(*pBindingA)) == 0;
263 for (iIndex = 0; iIndex <
SDL_arraysize(s_arrBindings); ++iIndex) {
264 pCurrent = &s_arrBindings[iIndex];
283 #ifdef DEBUG_CONTROLLERMAP
301 pCurrent = &s_arrBindings[iCurrentElement];
311 if (bNativeDPad && bCurrentDPad) {
318 if (bNativeAxis == bCurrentAxis &&
326 *pCurrent = *pBinding;
372 if (window ==
NULL) {
378 if (screen ==
NULL) {
395 name ? name :
"Unknown Joystick");
396 SDL_Log(
"Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
401 ====================================================================================\n\
402 Press the buttons on your controller when indicated\n\
403 (Your controller may look different than the picture)\n\
404 If you want to correct a mistake, press backspace or the back button on your device\n\
405 To skip a button, press SPACE or click/touch the screen\n\
406 To exit, press ESC\n\
407 ====================================================================================\n");
413 for (iIndex = 0; iIndex <
s_nNumAxes; ++iIndex) {
414 AxisState *pAxisState = &s_arrAxisState[iIndex];
460 switch (event.
type) {
468 AxisState *pAxisState = &s_arrAxisState[
event.jaxis.axis];
469 int nValue =
event.jaxis.value;
470 int nCurrentDistance, nFarthestDistance;
478 if (nCurrentDistance > nFarthestDistance) {
483 #ifdef DEBUG_CONTROLLERMAP
484 SDL_Log(
"AXIS %d nValue %d nCurrentDistance %d nFarthestDistance %d\n", event.
jaxis.
axis, nValue, nCurrentDistance, nFarthestDistance);
486 if (nFarthestDistance >= 16000) {
492 binding.
value.
axis.axis =
event.jaxis.axis;
505 #ifdef DEBUG_CONTROLLERMAP
510 binding.
value.
hat.hat =
event.jhat.hat;
511 binding.
value.
hat.hat_mask =
event.jhat.value;
523 #ifdef DEBUG_CONTROLLERMAP
572 char trimmed_name[128];
582 trimmed_name[
SDL_strlen(trimmed_name) - 1] =
'\0';
597 for (iIndex = 0; iIndex <
SDL_arraysize(s_arrBindings); ++iIndex) {
607 const char *pszAxisName;
660 pszElement[0] =
'\0';
691 SDL_Log(
"Mapping:\n\n%s\n\n", mapping);
693 printf(
"%s\n", mapping);
697 s_arrAxisState =
NULL;
708 SDL_Joystick *joystick;
723 SDL_Log(
"Joystick %d: %s\n", i, name ? name :
"Unknown Joystick");
725 if (joystick ==
NULL) {
731 guid,
sizeof (guid));
752 device = atoi(argv[1]);
755 if (joystick ==
NULL) {
763 SDL_Log(
"\n\nUsage: ./controllermap number\nFor example: ./controllermap 0\nOr: ./controllermap 0 >> gamecontrollerdb.txt");
773 main(
int argc,
char *argv[])