diff --git a/freeglut/freeglut/src/Common/freeglut_joystick.c b/freeglut/freeglut/src/Common/freeglut_joystick.c index c5e1b4a..5cfa430 100644 --- a/freeglut/freeglut/src/Common/freeglut_joystick.c +++ b/freeglut/freeglut/src/Common/freeglut_joystick.c @@ -388,6 +388,7 @@ static void fghJoystickAddHatElement ( SFG_Joystick* joy, CFDictionaryRef hat ); /* External function declarations (mostly platform-specific) */ +extern void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident ); extern void fgPlatformJoystickClose ( int ident ); /* @@ -401,6 +402,14 @@ static SFG_Joystick *fgJoystick [ MAX_NUM_JOYSTICKS ]; */ #if TARGET_HOST_MACINTOSH +void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident ) +{ + fgJoystick[ ident ]->id = ident; + snprintf( fgJoystick[ ident ]->fname, sizeof(fgJoystick[ ident ]->fname), "/dev/js%d", ident ); /* FIXME */ + fgJoystick[ ident ]->error = GL_FALSE; +} + + void fgPlatformJoystickClose ( int ident ) { ISpSuspend( ); @@ -410,6 +419,51 @@ void fgPlatformJoystickClose ( int ident ) #endif #if TARGET_HOST_MAC_OSX +void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident ) +{ + fgJoystick[ ident ]->id = ident; + fgJoystick[ ident ]->error = GL_FALSE; + fgJoystick[ ident ]->num_axes = 0; + fgJoystick[ ident ]->num_buttons = 0; + + if( numDevices < 0 ) + { + /* do first-time init (since we can't over-ride jsInit, hmm */ + numDevices = 0; + + mach_port_t masterPort; + IOReturn rv = IOMasterPort( bootstrap_port, &masterPort ); + if( rv != kIOReturnSuccess ) + { + fgWarning( "error getting master Mach port" ); + return; + } + fghJoystickFindDevices( masterPort ); + } + + if ( ident >= numDevices ) + { + fgJoystick[ ident ]->error = GL_TRUE; + return; + } + + /* get the name now too */ + CFDictionaryRef properties = getCFProperties( ioDevices[ ident ] ); + CFTypeRef ref = CFDictionaryGetValue( properties, + CFSTR( kIOHIDProductKey ) ); + if (!ref) + ref = CFDictionaryGetValue(properties, CFSTR( "USB Product Name" ) ); + + if( !ref || + !CFStringGetCString( ( CFStringRef )ref, name, 128, + CFStringGetSystemEncoding( ) ) ) + { + fgWarning( "error getting device name" ); + name[ 0 ] = '\0'; + } +} + + void fgPlatformJoystickClose ( int ident ) { ( *( fgJoystick[ ident ]->hidDev ) )-> @@ -418,6 +472,33 @@ void fgPlatformJoystickClose ( int ident ) #endif #if TARGET_HOST_POSIX_X11 +void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident ) +{ +#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ ) + fgJoystick[ ident ]->id = ident; + fgJoystick[ ident ]->error = GL_FALSE; + + fgJoystick[ ident ]->os = calloc( 1, sizeof( struct os_specific_s ) ); + memset( fgJoystick[ ident ]->os, 0, sizeof( struct os_specific_s ) ); + if( ident < USB_IDENT_OFFSET ) + fgJoystick[ ident ]->os->is_analog = 1; + if( fgJoystick[ ident ]->os->is_analog ) + snprintf( fgJoystick[ ident ]->os->fname, sizeof(fgJoystick[ ident ]->os->fname), "%s%d", AJSDEV, ident ); + else + snprintf( fgJoystick[ ident ]->os->fname, sizeof(fgJoystick[ ident ]->os->fname), "%s%d", UHIDDEV, + ident - USB_IDENT_OFFSET ); +#elif defined( __linux__ ) + fgJoystick[ ident ]->id = ident; + fgJoystick[ ident ]->error = GL_FALSE; + + snprintf( fgJoystick[ident]->fname, sizeof(fgJoystick[ident]->fname), "/dev/input/js%d", ident ); + + if( access( fgJoystick[ ident ]->fname, F_OK ) != 0 ) + snprintf( fgJoystick[ ident ]->fname, sizeof(fgJoystick[ ident ]->fname), "/dev/js%d", ident ); +#endif +} + + void fgPlatformJoystickClose ( int ident ) { #if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ ) @@ -1486,97 +1567,7 @@ static void fghJoystickInit( int ident ) fgJoystick[ ident ]->num_axes = fgJoystick[ ident ]->num_buttons = 0; fgJoystick[ ident ]->error = GL_TRUE; -#if TARGET_HOST_MACINTOSH - fgJoystick[ ident ]->id = ident; - snprintf( fgJoystick[ ident ]->fname, sizeof(fgJoystick[ ident ]->fname), "/dev/js%d", ident ); /* FIXME */ - fgJoystick[ ident ]->error = GL_FALSE; -#endif - -#if TARGET_HOST_MAC_OSX - fgJoystick[ ident ]->id = ident; - fgJoystick[ ident ]->error = GL_FALSE; - fgJoystick[ ident ]->num_axes = 0; - fgJoystick[ ident ]->num_buttons = 0; - - if( numDevices < 0 ) - { - /* do first-time init (since we can't over-ride jsInit, hmm */ - numDevices = 0; - - mach_port_t masterPort; - IOReturn rv = IOMasterPort( bootstrap_port, &masterPort ); - if( rv != kIOReturnSuccess ) - { - fgWarning( "error getting master Mach port" ); - return; - } - fghJoystickFindDevices( masterPort ); - } - - if ( ident >= numDevices ) - { - fgJoystick[ ident ]->error = GL_TRUE; - return; - } - - /* get the name now too */ - CFDictionaryRef properties = getCFProperties( ioDevices[ ident ] ); - CFTypeRef ref = CFDictionaryGetValue( properties, - CFSTR( kIOHIDProductKey ) ); - if (!ref) - ref = CFDictionaryGetValue(properties, CFSTR( "USB Product Name" ) ); - - if( !ref || - !CFStringGetCString( ( CFStringRef )ref, name, 128, - CFStringGetSystemEncoding( ) ) ) - { - fgWarning( "error getting device name" ); - name[ 0 ] = '\0'; - } -#endif - -#if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) - switch( ident ) - { - case 0: - fgJoystick[ ident ]->js_id = JOYSTICKID1; - fgJoystick[ ident ]->error = GL_FALSE; - break; - case 1: - fgJoystick[ ident ]->js_id = JOYSTICKID2; - fgJoystick[ ident ]->error = GL_FALSE; - break; - default: - fgJoystick[ ident ]->num_axes = 0; - fgJoystick[ ident ]->error = GL_TRUE; - return; - } -#endif - -#if TARGET_HOST_POSIX_X11 -# if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ ) - fgJoystick[ ident ]->id = ident; - fgJoystick[ ident ]->error = GL_FALSE; - - fgJoystick[ ident ]->os = calloc( 1, sizeof( struct os_specific_s ) ); - memset( fgJoystick[ ident ]->os, 0, sizeof( struct os_specific_s ) ); - if( ident < USB_IDENT_OFFSET ) - fgJoystick[ ident ]->os->is_analog = 1; - if( fgJoystick[ ident ]->os->is_analog ) - snprintf( fgJoystick[ ident ]->os->fname, sizeof(fgJoystick[ ident ]->os->fname), "%s%d", AJSDEV, ident ); - else - snprintf( fgJoystick[ ident ]->os->fname, sizeof(fgJoystick[ ident ]->os->fname), "%s%d", UHIDDEV, - ident - USB_IDENT_OFFSET ); -# elif defined( __linux__ ) - fgJoystick[ ident ]->id = ident; - fgJoystick[ ident ]->error = GL_FALSE; - - snprintf( fgJoystick[ident]->fname, sizeof(fgJoystick[ident]->fname), "/dev/input/js%d", ident ); - - if( access( fgJoystick[ ident ]->fname, F_OK ) != 0 ) - snprintf( fgJoystick[ ident ]->fname, sizeof(fgJoystick[ ident ]->fname), "/dev/js%d", ident ); -# endif -#endif + fgPlatformJoystickInit( fgJoystick, ident ); fghJoystickOpen( fgJoystick[ ident ] ); } diff --git a/freeglut/freeglut/src/mswin/freeglut_joystick_mswin.c b/freeglut/freeglut/src/mswin/freeglut_joystick_mswin.c index 2aad217..e154223 100644 --- a/freeglut/freeglut/src/mswin/freeglut_joystick_mswin.c +++ b/freeglut/freeglut/src/mswin/freeglut_joystick_mswin.c @@ -30,6 +30,27 @@ #if !defined(_WIN32_WCE) +void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident ) +{ + switch( ident ) + { + case 0: + fgJoystick[ ident ]->js_id = JOYSTICKID1; + fgJoystick[ ident ]->error = GL_FALSE; + break; + case 1: + fgJoystick[ ident ]->js_id = JOYSTICKID2; + fgJoystick[ ident ]->error = GL_FALSE; + break; + default: + fgJoystick[ ident ]->num_axes = 0; + fgJoystick[ ident ]->error = GL_TRUE; + return; + } +} + + + void fgPlatformJoystickClose ( int ident ) { /* Do nothing special */