comparison render_sdl.c @ 2679:69c1093f8726

Ignore devices with 3-axes and no buttons since these are generally not gamepads/joysticks but accelerometers or gyros
author Michael Pavone <pavone@retrodev.com>
date Wed, 26 Mar 2025 01:17:04 -0700
parents 1f6503bcb1d5
children da2e06c42d16
comparison
equal deleted inserted replaced
2678:844ca8377b45 2679:69c1093f8726
944 handle_joy_dpad(lock_joystick_index(render_find_joystick_index(event->jhat.which), -1), event->jhat.hat, event->jhat.value); 944 handle_joy_dpad(lock_joystick_index(render_find_joystick_index(event->jhat.which), -1), event->jhat.hat, event->jhat.value);
945 break; 945 break;
946 case SDL_JOYAXISMOTION: 946 case SDL_JOYAXISMOTION:
947 handle_joy_axis(lock_joystick_index(render_find_joystick_index(event->jaxis.which), -1), event->jaxis.axis, event->jaxis.value); 947 handle_joy_axis(lock_joystick_index(render_find_joystick_index(event->jaxis.which), -1), event->jaxis.axis, event->jaxis.value);
948 break; 948 break;
949 case SDL_JOYDEVICEADDED: 949 case SDL_JOYDEVICEADDED: {
950 if (event->jdevice.which < MAX_JOYSTICKS) { 950 int index = lowest_unused_joystick_index();
951 int index = lowest_unused_joystick_index(); 951 if (index >= 0) {
952 if (index >= 0) { 952 SDL_Joystick * joy = SDL_JoystickOpen(event->jdevice.which);
953 SDL_Joystick * joy = joysticks[index] = SDL_JoystickOpen(event->jdevice.which); 953 if (SDL_JoystickNumAxes(joy) == 3 && SDL_JoystickNumButtons(joy) == 0) {
954 joystick_sdl_index[index] = event->jdevice.which; 954 //probably just an acclerometer or gyro
955 joystick_index_locked[index] = 0; 955 SDL_JoystickClose(joy);
956 if (gc_events_enabled) { 956 break;
957 controllers[index] = SDL_GameControllerOpen(event->jdevice.which); 957 }
958 } 958 joysticks[index] = joy;
959 if (joy) { 959 joystick_sdl_index[index] = event->jdevice.which;
960 debug_message("Joystick %d added: %s\n", index, SDL_JoystickName(joy)); 960 joystick_index_locked[index] = 0;
961 debug_message("\tNum Axes: %d\n\tNum Buttons: %d\n\tNum Hats: %d\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy)); 961 if (gc_events_enabled) {
962 handle_joy_added(index); 962 controllers[index] = SDL_GameControllerOpen(event->jdevice.which);
963 } 963 }
964 if (joy) {
965 debug_message("Joystick %d added: %s\n", index, SDL_JoystickName(joy));
966 debug_message("\tNum Axes: %d\n\tNum Buttons: %d\n\tNum Hats: %d\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy));
967 handle_joy_added(index);
964 } 968 }
965 } 969 }
966 break; 970 break;
971 }
967 case SDL_JOYDEVICEREMOVED: { 972 case SDL_JOYDEVICEREMOVED: {
968 int index = render_find_joystick_index(event->jdevice.which); 973 int index = render_find_joystick_index(event->jdevice.which);
969 if (index >= 0) { 974 if (index >= 0) {
970 SDL_JoystickClose(joysticks[index]); 975 SDL_JoystickClose(joysticks[index]);
971 joysticks[index] = NULL; 976 joysticks[index] = NULL;