2

The source is very basic:

#include <SDL.h>

int main(int argc, char *argv[])
{
  if (SDL_Init(SDL_INIT_JOYSTICK))
  {
    return 1;
  }
  int num_joy, i;
  num_joy=SDL_NumJoysticks();
  printf("%d joysticks found\n", num_joy);
  for(i=0;i<num_joy;i++)
      printf("%s\n", SDL_JoystickName(i));

  SDL_Quit();
  return 0;
}

This outputs the names of connected joysticks on Ubuntu 12.04, but not on my Mavericks Mac, with SDL 1.2.15, installed from Homebrew. Running it as root makes no difference. I assuming at this point that this is just a bug in SDL, but I'd love to be shown that I'm doing something wrong here.

Source here: https://github.com/mikepurvis/joystick_sdl

mikepurvis
  • 1,568
  • 2
  • 19
  • 28
  • You probably have to install the driver manually on the Mac. For example I looked for Xbox360 controller's driver for Mac, and could only find instructions to install third party software. – gibertoni Nov 20 '14 at 22:55
  • The 360 controller is special in requiring its own driver. I'm talking about standard HID joysticks, which should almost certainly just work out of the box. – mikepurvis Nov 21 '14 at 12:49
  • 1
    Some OSes link input to a window. You might have to create a window in order to receive input events from your gamepad. – Jonny D Dec 19 '14 at 20:48
  • SDL_Init actually does briefly create a flash of a window— doesn't seem to help here. – mikepurvis Dec 20 '14 at 11:20

2 Answers2

1

You need to take a look at the following SDL2 function call:

SDL_GameControllerAddMappingsFromFile

This will read in gamepad configurations for gamepads that are not supported by SDL2 out of the box.

To get a community maintained list of controllers, please take a look at: gamecontrollerdb.txt

To create your own mappings for obscure gamepads that you may have lying around, you need to run the SDL/test/controllermap.c example. To build this example on OSX, I used:

$ gcc controllermap.c -lSDL2 -I ../include -o controllermap -L ~/lib/ -framework AudioUnit -framework Carbon -framework ForceFeedback -framework CoreAudio -framework CoreVideo -framework IOKit -framework Cocoa
Bram
  • 7,440
  • 3
  • 52
  • 94
1

This is ancient history now, but the issue turned out to be that my controller (Logitech F710) was in XInput mode instead of DirectInput mode, by the switch on top of the unit. XInput is not supported on Mac OS X.

Flipping the switch (to "D") makes the controller work as expected.

cf. http://cantonbecker.com/etcetera/2015/logitech-f710-for-os-x-macintosh-setup/

mikepurvis
  • 1,568
  • 2
  • 19
  • 28