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:
parent
c03f197329
commit
a1547dde81
@ -1136,7 +1136,10 @@ static void fghJoystickOpen( SFG_Joystick* joy )
|
||||
# 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->num_axes = joy->num_buttons = 0;
|
||||
joy->name[ 0 ] = '\0';
|
||||
@ -1216,10 +1219,13 @@ static void fghJoystickOpen( SFG_Joystick* joy )
|
||||
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 )
|
||||
|
||||
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 )
|
||||
|
||||
joy->num_buttons = joy->isp_num_needs - joy->isp_num_axis;
|
||||
@ -1241,7 +1247,8 @@ static void fghJoystickOpen( SFG_Joystick* joy )
|
||||
#endif
|
||||
|
||||
#if TARGET_HOST_MAC_OSX
|
||||
if (joy->id >= numDevices) {
|
||||
if( joy->id >= numDevices )
|
||||
{
|
||||
fgWarning( "%s", "device index out of range in fgJoystickOpen()" );
|
||||
return;
|
||||
}
|
||||
@ -1252,24 +1259,30 @@ static void fghJoystickOpen( SFG_Joystick* joy )
|
||||
kIOCFPlugInInterfaceID,
|
||||
&plugin, &score );
|
||||
|
||||
if (rv != kIOReturnSuccess) {
|
||||
if( rv != kIOReturnSuccess )
|
||||
{
|
||||
fgWarning( "%s", "error creating plugin for io device" );
|
||||
return;
|
||||
}
|
||||
|
||||
pluginResult = (*plugin)->QueryInterface ( plugin,
|
||||
CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), &(LPVOID) joy->hidDev );
|
||||
pluginResult = ( *plugin )->QueryInterface(
|
||||
plugin,
|
||||
CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID),
|
||||
&( LPVOID )joy->hidDev
|
||||
);
|
||||
|
||||
if( pluginResult != S_OK )
|
||||
fgWarning ( "%s", "QI-ing IO plugin to HID Device interface failed" );
|
||||
|
||||
( *plugin )->Release( plugin ); /* don't leak a ref */
|
||||
if (joy->hidDev == NULL) return;
|
||||
if( joy->hidDev == NULL )
|
||||
return;
|
||||
|
||||
/* store the interface in this instance */
|
||||
rv = ( *( joy->hidDev ) )->open( joy->hidDev, 0 );
|
||||
if (rv != kIOReturnSuccess) {
|
||||
fgWarning ( "%s", "error opening device interface");
|
||||
if( rv != kIOReturnSuccess )
|
||||
{
|
||||
fgWarning( "error opening device interface");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1303,9 +1316,10 @@ static void fghJoystickOpen( SFG_Joystick* joy )
|
||||
/* Device name from jsCaps is often "Microsoft PC-joystick driver",
|
||||
* 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 ) );
|
||||
}
|
||||
|
||||
@ -1416,8 +1430,10 @@ static void fghJoystickOpen( SFG_Joystick* joy )
|
||||
}
|
||||
|
||||
cp = strrchr( joy->os->fname, '/' );
|
||||
if ( cp ) {
|
||||
if ( fghJoystickFindUSBdev ( &cp[1], joy->name, sizeof(joy->name) ) == 0 )
|
||||
if( cp )
|
||||
{
|
||||
if( fghJoystickFindUSBdev( &cp[1], joy->name, sizeof( joy->name ) ) ==
|
||||
0 )
|
||||
strcpy( joy->name, &cp[1] );
|
||||
}
|
||||
|
||||
@ -1538,7 +1554,8 @@ void fgJoystickInit( int ident )
|
||||
if( fgJoystick[ ident ] )
|
||||
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 */
|
||||
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_buttons = 0;
|
||||
|
||||
if (numDevices < 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 ) {
|
||||
if( rv != kIOReturnSuccess )
|
||||
{
|
||||
fgWarning( "%s", "error getting master Mach port" );
|
||||
return;
|
||||
}
|
||||
fghJoystickFindDevices( masterPort );
|
||||
}
|
||||
|
||||
if ( ident >= numDevices ) {
|
||||
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));
|
||||
CFTypeRef ref = CFDictionaryGetValue( properties,
|
||||
CFSTR( kIOHIDProductKey ) );
|
||||
if (!ref)
|
||||
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" );
|
||||
name[ 0 ] = '\0';
|
||||
}
|
||||
@ -1616,7 +1640,8 @@ void fgJoystickInit( int ident )
|
||||
if( fgJoystick[ ident ]->os->is_analog )
|
||||
sprintf( fgJoystick[ ident ]->os->fname, "%s%d", AJSDEV, ident );
|
||||
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__ )
|
||||
fgJoystick[ ident ]->id = ident;
|
||||
fgJoystick[ ident ]->error = GL_FALSE;
|
||||
@ -1649,7 +1674,8 @@ void fgJoystickClose( void )
|
||||
#endif
|
||||
|
||||
#if TARGET_HOST_MAC_OSX
|
||||
(*(fgJoystick[ident]->hidDev))->close(fgJoystick[ident]->hidDev);
|
||||
( *( fgJoystick[ ident ]->hidDev ) )->
|
||||
close( fgJoystick[ ident ]->hidDev );
|
||||
#endif
|
||||
|
||||
#if TARGET_HOST_WIN32
|
||||
@ -1677,7 +1703,8 @@ void fgJoystickClose( void )
|
||||
#endif
|
||||
|
||||
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.
|
||||
*/
|
||||
int glutJoystickGetNumAxes( int ident )
|
||||
{ return fgJoystick[ident]->num_axes; }
|
||||
{
|
||||
return fgJoystick[ ident ]->num_axes;
|
||||
}
|
||||
int glutJoystickNotWorking( int ident )
|
||||
{ return fgJoystick[ident]->error; }
|
||||
{
|
||||
return fgJoystick[ ident ]->error;
|
||||
}
|
||||
|
||||
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 )
|
||||
{ fgJoystick[ident]->dead_band [ axis ] = db; }
|
||||
{
|
||||
fgJoystick[ ident ]->dead_band[ axis ] = db;
|
||||
}
|
||||
|
||||
float glutJoystickGetSaturation( int ident, int axis )
|
||||
{ return fgJoystick[ident]->saturate [ axis ]; }
|
||||
{
|
||||
return fgJoystick[ ident ]->saturate[ axis ];
|
||||
}
|
||||
void glutJoystickSetSaturation( int ident, int axis, float st )
|
||||
{ fgJoystick[ident]->saturate [ axis ] = st; }
|
||||
{
|
||||
fgJoystick[ ident ]->saturate [ axis ] = st;
|
||||
}
|
||||
|
||||
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 )
|
||||
{ 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 )
|
||||
{ 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 )
|
||||
{ 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 )
|
||||
{ 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 )
|
||||
{ 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 ***/
|
||||
|
Reference in New Issue
Block a user