engine/sdl/control.c
/*
Search for usb joysticks. Set
types, defaults and keynames.
*/
Search for usb joysticks. Set
types, defaults and keynames.
Search for usb joysticks . Set types defaults and keynames .
void joystick_scan(int scan)
{
	int i;
	int numjoyNoAcc = 0;
	if(!scan) return;
	numjoy = SDL_NumJoysticks();
	numjoyNoAcc = numjoy;
	if (scan != 2)
    {
        for(i = 0; i < numjoy; i++)
        {
            char real_joy_name[MAX_BUFFER_LEN];
            strcpy(real_joy_name,SDL_JoystickNameForIndex(i));
            if (strcmp(real_joy_name, "Android Accelerometer") == 0)
            {
                --numjoyNoAcc;
            }
        }
        if(numjoyNoAcc <= 0)
        {
            printf("No Joystick(s) Found!\n");
            return;
        }
        else
        {
            printf("\n%d joystick(s) found!\n", numjoyNoAcc);
        }
    }
	if (numjoyNoAcc > JOY_LIST_TOTAL) numjoy = JOY_LIST_TOTAL; 
	for(i = 0; i < numjoy; i++)
	{
	    int joy_idx = i;
        char real_joy_name[MAX_BUFFER_LEN];
        strcpy(real_joy_name,SDL_JoystickNameForIndex(i));
        if (strcmp(real_joy_name, "Android Accelerometer") == 0)
        {
            continue;
        }
        open_joystick(joy_idx);
        if(scan != 2)
        {
            int is_rumble_support = (joystick_haptic[i] != NULL && SDL_HapticRumbleSupported(joystick_haptic[i])) ? 1 : 0;
            char* rumble_support = (is_rumble_support) ? "yes" : "no";
            if(numjoy == 1)
            {
                printf("%s (%s) - %d axes, %d buttons, %d hat(s), rumble support: %s\n",
                        get_joystick_name(joysticks[joy_idx].Name), SDL_JoystickName(i), joysticks[joy_idx].NumAxes, joysticks[joy_idx].NumButtons, joysticks[joy_idx].NumHats, rumble_support);
            }
            else if(numjoy > 1)
            {
                if(joy_idx) printf("\n");
                printf("%d. %s (%s) - %d axes, %d buttons, %d hat(s), rumble support: %s\n", i + 1,
                        get_joystick_name(joysticks[joy_idx].Name), SDL_JoystickName(i), joysticks[joy_idx].NumAxes, joysticks[joy_idx].NumButtons, joysticks[joy_idx].NumHats, rumble_support);
            }
        }
	}
}
void joystick_scan ( int scan ) { int i ; int numjoyNoAcc = 0 ; if ( ! scan ) return ; numjoy = SDL_NumJoysticks ( ) ; numjoyNoAcc = numjoy ; if ( scan != 2 ) { for ( i = 0 ; i < numjoy ; i ++ ) { char real_joy_name [ MAX_BUFFER_LEN ] ; strcpy ( real_joy_name , SDL_JoystickNameForIndex ( i ) ) ; if ( strcmp ( real_joy_name , " " ) == 0 ) { -- numjoyNoAcc ; } } if ( numjoyNoAcc <= 0 ) { printf ( " \n " ) ; return ; } else { printf ( " \n \n " , numjoyNoAcc ) ; } } if ( numjoyNoAcc > JOY_LIST_TOTAL ) numjoy = JOY_LIST_TOTAL ; for ( i = 0 ; i < numjoy ; i ++ ) { int joy_idx = i ; char real_joy_name [ MAX_BUFFER_LEN ] ; strcpy ( real_joy_name , SDL_JoystickNameForIndex ( i ) ) ; if ( strcmp ( real_joy_name , " " ) == 0 ) { continue ; } open_joystick ( joy_idx ) ; if ( scan != 2 ) { int is_rumble_support = ( joystick_haptic [ i ] != NULL && SDL_HapticRumbleSupported ( joystick_haptic [ i ] ) ) ? 1 : 0 ; char * rumble_support = ( is_rumble_support ) ? " " : " " ; if ( numjoy == 1 ) { printf ( " \n " , get_joystick_name ( joysticks [ joy_idx ] . Name ) , SDL_JoystickName ( i ) , joysticks [ joy_idx ] . NumAxes , joysticks [ joy_idx ] . NumButtons , joysticks [ joy_idx ] . NumHats , rumble_support ) ; } else if ( numjoy > 1 ) { if ( joy_idx ) printf ( " \n " ) ; printf ( " \n " , i + 1 , get_joystick_name ( joysticks [ joy_idx ] . Name ) , SDL_JoystickName ( i ) , joysticks [ joy_idx ] . NumAxes , joysticks [ joy_idx ] . NumButtons , joysticks [ joy_idx ] . NumHats , rumble_support ) ; } } } }
Search for usb joysticks.
Search for usb joysticks .
//Kratus (20-04-21) new joystick scan, avoid accelerometer detection as buttons in Android // avoid overflow bug // print JOY_MAX_INPUTS (64) spaces for alignment