| 21 | #if !defined SDL_JOYSTICK_DISABLED && !defined SDL_HAPTIC_DISABLED |
| 22 | |
| 23 | int |
| 24 | main(int argc, char *argv[]) |
| 25 | { |
| 26 | SDL_Joystick *joystick = NULL; |
| 27 | SDL_Haptic *haptic = NULL; |
| 28 | SDL_JoystickID instance = -1; |
| 29 | SDL_bool keepGoing = SDL_TRUE; |
| 30 | int i; |
| 31 | SDL_bool enable_haptic = SDL_TRUE; |
| 32 | Uint32 init_subsystems = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK; |
| 33 | |
| 34 | for (i = 1; i < argc; ++i) { |
| 35 | if (SDL_strcasecmp(argv[i], "--nohaptic") == 0) { |
| 36 | enable_haptic = SDL_FALSE; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | if(enable_haptic) { |
| 41 | init_subsystems |= SDL_INIT_HAPTIC; |
| 42 | } |
| 43 | |
| 44 | /* Enable standard application logging */ |
| 45 | SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); |
| 46 | |
| 47 | SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); |
| 48 | |
| 49 | /* Initialize SDL (Note: video is required to start event loop) */ |
| 50 | if (SDL_Init(init_subsystems) < 0) { |
| 51 | SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); |
| 52 | exit(1); |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | //SDL_CreateWindow("Dummy", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 128, 128, 0); |
| 57 | */ |
| 58 | |
| 59 | SDL_Log("There are %d joysticks at startup\n", SDL_NumJoysticks()); |
| 60 | if (enable_haptic) |
| 61 | SDL_Log("There are %d haptic devices at startup\n", SDL_NumHaptics()); |
| 62 | |
| 63 | while(keepGoing) |
| 64 | { |
| 65 | SDL_Event event; |
| 66 | while(SDL_PollEvent(&event)) |
| 67 | { |
| 68 | switch(event.type) |
| 69 | { |
| 70 | case SDL_QUIT: |
| 71 | keepGoing = SDL_FALSE; |
| 72 | break; |
| 73 | case SDL_JOYDEVICEADDED: |
| 74 | if (joystick != NULL) |
| 75 | { |
| 76 | SDL_Log("Only one joystick supported by this test\n"); |
| 77 | } |
| 78 | else |
| 79 | { |
| 80 | joystick = SDL_JoystickOpen(event.jdevice.which); |
nothing calls this directly
no test coverage detected