Normalized the style of the new joystick a bit.

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@462 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
rkrolib 2004-02-14 08:51:54 +00:00
parent c03f197329
commit a1547dde81

View File

@ -1136,7 +1136,10 @@ static void fghJoystickOpen( SFG_Joystick* joy )
# endif # endif
#endif #endif
/* Default values (for no joystick -- each conditional will reset the error flag) */ /*
* Default values (for no joystick -- each conditional will reset the
* error flag)
*/
joy->error = TRUE; joy->error = TRUE;
joy->num_axes = joy->num_buttons = 0; joy->num_axes = joy->num_buttons = 0;
joy->name[ 0 ] = '\0'; joy->name[ 0 ] = '\0';
@ -1216,10 +1219,13 @@ static void fghJoystickOpen( SFG_Joystick* joy )
ISP_CHECK_ERR(err) ISP_CHECK_ERR(err)
*/ */
err = ISpElement_NewVirtualFromNeeds ( joy->isp_num_needs, joy->isp_needs, joy->isp_elem, 0 ); err = ISpElement_NewVirtualFromNeeds( joy->isp_num_needs,
joy->isp_needs, joy->isp_elem,
0 );
ISP_CHECK_ERR( err ) ISP_CHECK_ERR( err )
err = ISpInit ( joy->isp_num_needs, joy->isp_needs, joy->isp_elem, 'freeglut', nil, 0, 128, 0 ); err = ISpInit( joy->isp_num_needs, joy->isp_needs, joy->isp_elem,
'freeglut', nil, 0, 128, 0 );
ISP_CHECK_ERR( err ) ISP_CHECK_ERR( err )
joy->num_buttons = joy->isp_num_needs - joy->isp_num_axis; joy->num_buttons = joy->isp_num_needs - joy->isp_num_axis;
@ -1241,7 +1247,8 @@ static void fghJoystickOpen( SFG_Joystick* joy )
#endif #endif
#if TARGET_HOST_MAC_OSX #if TARGET_HOST_MAC_OSX
if (joy->id >= numDevices) { if( joy->id >= numDevices )
{
fgWarning( "%s", "device index out of range in fgJoystickOpen()" ); fgWarning( "%s", "device index out of range in fgJoystickOpen()" );
return; return;
} }
@ -1252,24 +1259,30 @@ static void fghJoystickOpen( SFG_Joystick* joy )
kIOCFPlugInInterfaceID, kIOCFPlugInInterfaceID,
&plugin, &score ); &plugin, &score );
if (rv != kIOReturnSuccess) { if( rv != kIOReturnSuccess )
{
fgWarning( "%s", "error creating plugin for io device" ); fgWarning( "%s", "error creating plugin for io device" );
return; return;
} }
pluginResult = (*plugin)->QueryInterface ( plugin, pluginResult = ( *plugin )->QueryInterface(
CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), &(LPVOID) joy->hidDev ); plugin,
CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID),
&( LPVOID )joy->hidDev
);
if( pluginResult != S_OK ) if( pluginResult != S_OK )
fgWarning ( "%s", "QI-ing IO plugin to HID Device interface failed" ); fgWarning ( "%s", "QI-ing IO plugin to HID Device interface failed" );
( *plugin )->Release( plugin ); /* don't leak a ref */ ( *plugin )->Release( plugin ); /* don't leak a ref */
if (joy->hidDev == NULL) return; if( joy->hidDev == NULL )
return;
/* store the interface in this instance */ /* store the interface in this instance */
rv = ( *( joy->hidDev ) )->open( joy->hidDev, 0 ); rv = ( *( joy->hidDev ) )->open( joy->hidDev, 0 );
if (rv != kIOReturnSuccess) { if( rv != kIOReturnSuccess )
fgWarning ( "%s", "error opening device interface"); {
fgWarning( "error opening device interface");
return; return;
} }
@ -1303,9 +1316,10 @@ static void fghJoystickOpen( SFG_Joystick* joy )
/* Device name from jsCaps is often "Microsoft PC-joystick driver", /* Device name from jsCaps is often "Microsoft PC-joystick driver",
* at least for USB. Try to get the real name from the registry. * at least for USB. Try to get the real name from the registry.
*/ */
if ( ! fghJoystickGetOEMProductName ( joy, joy->name, sizeof(joy->name) ) ) if ( ! fghJoystickGetOEMProductName( joy, joy->name,
sizeof( joy->name ) ) )
{ {
fgWarning ( "%s", "JS: Failed to read joystick name from registry" ); fgWarning( "JS: Failed to read joystick name from registry" );
strncpy( joy->name, joy->jsCaps.szPname, sizeof( joy->name ) ); strncpy( joy->name, joy->jsCaps.szPname, sizeof( joy->name ) );
} }
@ -1416,8 +1430,10 @@ static void fghJoystickOpen( SFG_Joystick* joy )
} }
cp = strrchr( joy->os->fname, '/' ); cp = strrchr( joy->os->fname, '/' );
if ( cp ) { if( cp )
if ( fghJoystickFindUSBdev ( &cp[1], joy->name, sizeof(joy->name) ) == 0 ) {
if( fghJoystickFindUSBdev( &cp[1], joy->name, sizeof( joy->name ) ) ==
0 )
strcpy( joy->name, &cp[1] ); strcpy( joy->name, &cp[1] );
} }
@ -1538,7 +1554,8 @@ void fgJoystickInit( int ident )
if( fgJoystick[ ident ] ) if( fgJoystick[ ident ] )
fgError( "illegal attempt to initialize joystick device" ); fgError( "illegal attempt to initialize joystick device" );
fgJoystick[ident] = ( SFG_Joystick * )calloc( sizeof( SFG_Joystick ), 1 ); fgJoystick[ ident ] =
( SFG_Joystick * )calloc( sizeof( SFG_Joystick ), 1 );
/* Set defaults */ /* Set defaults */
fgJoystick[ ident ]->num_axes = fgJoystick[ ident ]->num_buttons = 0; fgJoystick[ ident ]->num_axes = fgJoystick[ ident ]->num_buttons = 0;
@ -1556,31 +1573,38 @@ void fgJoystickInit( int ident )
fgJoystick[ ident ]->num_axes = 0; fgJoystick[ ident ]->num_axes = 0;
fgJoystick[ ident ]->num_buttons = 0; fgJoystick[ ident ]->num_buttons = 0;
if (numDevices < 0) { if( numDevices < 0 )
{
/* do first-time init (since we can't over-ride jsInit, hmm */ /* do first-time init (since we can't over-ride jsInit, hmm */
numDevices = 0; numDevices = 0;
mach_port_t masterPort; mach_port_t masterPort;
IOReturn rv = IOMasterPort( bootstrap_port, &masterPort ); IOReturn rv = IOMasterPort( bootstrap_port, &masterPort );
if ( rv != kIOReturnSuccess ) { if( rv != kIOReturnSuccess )
{
fgWarning( "%s", "error getting master Mach port" ); fgWarning( "%s", "error getting master Mach port" );
return; return;
} }
fghJoystickFindDevices( masterPort ); fghJoystickFindDevices( masterPort );
} }
if ( ident >= numDevices ) { if ( ident >= numDevices )
{
fgJoystick[ ident ]->error = GL_TRUE; fgJoystick[ ident ]->error = GL_TRUE;
return; return;
} }
/* get the name now too */ /* get the name now too */
CFDictionaryRef properties = getCFProperties( ioDevices[ ident ] ); CFDictionaryRef properties = getCFProperties( ioDevices[ ident ] );
CFTypeRef ref = CFDictionaryGetValue (properties, CFSTR(kIOHIDProductKey)); CFTypeRef ref = CFDictionaryGetValue( properties,
CFSTR( kIOHIDProductKey ) );
if (!ref) if (!ref)
ref = CFDictionaryGetValue(properties, CFSTR( "USB Product Name" ) ); ref = CFDictionaryGetValue(properties, CFSTR( "USB Product Name" ) );
if (!ref || !CFStringGetCString ((CFStringRef) ref, name, 128, CFStringGetSystemEncoding ())) { if( !ref ||
!CFStringGetCString( ( CFStringRef )ref, name, 128,
CFStringGetSystemEncoding( ) ) )
{
fgWarning( "%s", "error getting device name" ); fgWarning( "%s", "error getting device name" );
name[ 0 ] = '\0'; name[ 0 ] = '\0';
} }
@ -1616,7 +1640,8 @@ void fgJoystickInit( int ident )
if( fgJoystick[ ident ]->os->is_analog ) if( fgJoystick[ ident ]->os->is_analog )
sprintf( fgJoystick[ ident ]->os->fname, "%s%d", AJSDEV, ident ); sprintf( fgJoystick[ ident ]->os->fname, "%s%d", AJSDEV, ident );
else else
sprintf ( fgJoystick[ident]->os->fname, "%s%d", UHIDDEV, ident - USB_IDENT_OFFSET ); sprintf( fgJoystick[ ident ]->os->fname, "%s%d", UHIDDEV,
ident - USB_IDENT_OFFSET );
# elif defined( __linux__ ) # elif defined( __linux__ )
fgJoystick[ ident ]->id = ident; fgJoystick[ ident ]->id = ident;
fgJoystick[ ident ]->error = GL_FALSE; fgJoystick[ ident ]->error = GL_FALSE;
@ -1649,7 +1674,8 @@ void fgJoystickClose( void )
#endif #endif
#if TARGET_HOST_MAC_OSX #if TARGET_HOST_MAC_OSX
(*(fgJoystick[ident]->hidDev))->close(fgJoystick[ident]->hidDev); ( *( fgJoystick[ ident ]->hidDev ) )->
close( fgJoystick[ ident ]->hidDev );
#endif #endif
#if TARGET_HOST_WIN32 #if TARGET_HOST_WIN32
@ -1677,7 +1703,8 @@ void fgJoystickClose( void )
#endif #endif
free( fgJoystick[ ident ] ); free( fgJoystick[ ident ] );
fgJoystick[ident] = NULL; /* show joystick has been deinitialized */ fgJoystick[ ident ] = NULL;
/* show joystick has been deinitialized */
} }
} }
} }
@ -1717,32 +1744,62 @@ void fgJoystickPollWindow( SFG_Window* window )
* We might consider adding such functions to freeglut-2.0. * We might consider adding such functions to freeglut-2.0.
*/ */
int glutJoystickGetNumAxes( int ident ) int glutJoystickGetNumAxes( int ident )
{ return fgJoystick[ident]->num_axes; } {
return fgJoystick[ ident ]->num_axes;
}
int glutJoystickNotWorking( int ident ) int glutJoystickNotWorking( int ident )
{ return fgJoystick[ident]->error; } {
return fgJoystick[ ident ]->error;
}
float glutJoystickGetDeadBand( int ident, int axis ) float glutJoystickGetDeadBand( int ident, int axis )
{ return fgJoystick[ident]->dead_band [ axis ]; } {
return fgJoystick[ ident ]->dead_band [ axis ];
}
void glutJoystickSetDeadBand( int ident, int axis, float db ) void glutJoystickSetDeadBand( int ident, int axis, float db )
{ fgJoystick[ident]->dead_band [ axis ] = db; } {
fgJoystick[ ident ]->dead_band[ axis ] = db;
}
float glutJoystickGetSaturation( int ident, int axis ) float glutJoystickGetSaturation( int ident, int axis )
{ return fgJoystick[ident]->saturate [ axis ]; } {
return fgJoystick[ ident ]->saturate[ axis ];
}
void glutJoystickSetSaturation( int ident, int axis, float st ) void glutJoystickSetSaturation( int ident, int axis, float st )
{ fgJoystick[ident]->saturate [ axis ] = st; } {
fgJoystick[ ident ]->saturate [ axis ] = st;
}
void glutJoystickSetMinRange( int ident, float *axes ) void glutJoystickSetMinRange( int ident, float *axes )
{ memcpy ( fgJoystick[ident]->min , axes, fgJoystick[ident]->num_axes * sizeof(float) ); } {
memcpy( fgJoystick[ ident ]->min, axes,
fgJoystick[ ident ]->num_axes * sizeof( float ) );
}
void glutJoystickSetMaxRange( int ident, float *axes ) void glutJoystickSetMaxRange( int ident, float *axes )
{ memcpy ( fgJoystick[ident]->max , axes, fgJoystick[ident]->num_axes * sizeof(float) ); } {
memcpy( fgJoystick[ ident ]->max, axes,
fgJoystick[ ident ]->num_axes * sizeof( float ) );
}
void glutJoystickSetCenter( int ident, float *axes ) void glutJoystickSetCenter( int ident, float *axes )
{ memcpy ( fgJoystick[ident]->center, axes, fgJoystick[ident]->num_axes * sizeof(float) ); } {
memcpy( fgJoystick[ ident ]->center, axes,
fgJoystick[ ident ]->num_axes * sizeof( float ) );
}
void glutJoystickGetMinRange( int ident, float *axes ) void glutJoystickGetMinRange( int ident, float *axes )
{ memcpy ( axes, fgJoystick[ident]->min , fgJoystick[ident]->num_axes * sizeof(float) ); } {
memcpy( axes, fgJoystick[ ident ]->min,
fgJoystick[ ident ]->num_axes * sizeof( float ) );
}
void glutJoystickGetMaxRange( int ident, float *axes ) void glutJoystickGetMaxRange( int ident, float *axes )
{ memcpy ( axes, fgJoystick[ident]->max , fgJoystick[ident]->num_axes * sizeof(float) ); } {
memcpy( axes, fgJoystick[ ident ]->max,
fgJoystick[ ident ]->num_axes * sizeof( float ) );
}
void glutJoystickGetCenter( int ident, float *axes ) void glutJoystickGetCenter( int ident, float *axes )
{ memcpy ( axes, fgJoystick[ident]->center, fgJoystick[ident]->num_axes * sizeof(float) ); } {
memcpy( axes, fgJoystick[ ident ]->center,
fgJoystick[ ident ]->num_axes * sizeof( float ) );
}
/*** END OF FILE ***/ /*** END OF FILE ***/