-# ifdef JS_NEW\r
-\r
- while ( 1 )\r
- {\r
- status = read ( joy->fd, &joy->js, sizeof(struct js_event) );\r
-\r
- if ( status != sizeof( struct js_event ) )\r
- {\r
-#ifdef HAVE_ERRNO_H\r
- if ( errno == EAGAIN )\r
- {\r
- /* Use the old values */\r
- if ( buttons )\r
- *buttons = joy->tmp_buttons;\r
- if ( axes )\r
- memcpy( axes, joy->tmp_axes,\r
- sizeof( float ) * joy->num_axes );\r
- return;\r
- }\r
-#endif\r
-\r
- fgWarning ( "%s", joy->fname );\r
- joy->error = GL_TRUE;\r
- return;\r
- }\r
-\r
- switch ( joy->js.type & ~JS_EVENT_INIT )\r
- {\r
- case JS_EVENT_BUTTON:\r
- if( joy->js.value == 0 ) /* clear the flag */\r
- joy->tmp_buttons &= ~( 1 << joy->js.number );\r
- else\r
- joy->tmp_buttons |= ( 1 << joy->js.number );\r
- break;\r
-\r
- case JS_EVENT_AXIS:\r
- if ( joy->js.number < joy->num_axes )\r
- {\r
- joy->tmp_axes[ joy->js.number ] = ( float )joy->js.value;\r
-\r
- if( axes )\r
- memcpy( axes, joy->tmp_axes, sizeof(float) * joy->num_axes );\r
- }\r
- break;\r
-\r
- default:\r
- fgWarning ( "PLIB_JS: Unrecognised /dev/js return!?!" );\r
-\r
- /* use the old values */\r
-\r
- if ( buttons != NULL ) *buttons = joy->tmp_buttons;\r
- if ( axes != NULL )\r
- memcpy ( axes, joy->tmp_axes, sizeof(float) * joy->num_axes );\r
-\r
- return;\r
- }\r
-\r
- if( buttons )\r
- *buttons = joy->tmp_buttons;\r
- }\r
-# else\r
-\r
- status = read( joy->fd, &joy->js, JS_RETURN );\r
-\r
- if ( status != JS_RETURN )\r
- {\r
- fgWarning( "%s", joy->fname );\r
- joy->error = GL_TRUE;\r
- return;\r
- }\r
-\r
- if ( buttons )\r
-# if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )\r
- *buttons = ( joy->js.b1 ? 1 : 0 ) | ( joy->js.b2 ? 2 : 0 ); /* XXX Should not be here -- BSD is handled earlier */\r
-# else\r
- *buttons = joy->js.buttons;\r
-# endif\r
-\r
- if ( axes )\r
- {\r
- axes[ 0 ] = (float) joy->js.x;\r
- axes[ 1 ] = (float) joy->js.y;\r
- }\r
-# endif\r
-#endif\r
-}\r
-\r
-/*\r
- * Correct the joystick axis data\r
- */\r
-static float fghJoystickFudgeAxis( SFG_Joystick* joy, float value, int axis )\r
-{\r
- if( value < joy->center[ axis ] )\r
- {\r
- float xx = ( value - joy->center[ axis ] ) / ( joy->center[ axis ] -\r
- joy->min[ axis ] );\r
-\r
- if( xx < -joy->saturate[ axis ] )\r
- return -1.0f;\r
-\r
- if( xx > -joy->dead_band [ axis ] )\r
- return 0.0f;\r
-\r
- xx = ( xx + joy->dead_band[ axis ] ) / ( joy->saturate[ axis ] -\r
- joy->dead_band[ axis ] );\r
-\r
- return ( xx < -1.0f ) ? -1.0f : xx;\r
- }\r
- else\r
- {\r
- float xx = ( value - joy->center [ axis ] ) / ( joy->max[ axis ] -\r
- joy->center[ axis ] );\r
-\r
- if( xx > joy->saturate[ axis ] )\r
- return 1.0f;\r
-\r
- if( xx < joy->dead_band[ axis ] )\r
- return 0.0f;\r
-\r
- xx = ( xx - joy->dead_band[ axis ] ) / ( joy->saturate[ axis ] -\r
- joy->dead_band[ axis ] );\r
-\r
- return ( xx > 1.0f ) ? 1.0f : xx;\r
- }\r
-}\r
-\r
-/*\r
- * Read the corrected joystick data\r
- */\r
-static void fghJoystickRead( SFG_Joystick* joy, int* buttons, float* axes )\r
-{\r
- float raw_axes[ _JS_MAX_AXES ];\r
- int i;\r
-\r
- if( joy->error )\r
- {\r
- if( buttons )\r
- *buttons = 0;\r
-\r
- if( axes )\r
- for ( i=0; i<joy->num_axes; i++ )\r
- axes[ i ] = 0.0f;\r
- }\r
-\r
- fghJoystickRawRead( joy, buttons, raw_axes );\r
-\r
- if( axes )\r
- for( i=0; i<joy->num_axes; i++ )\r
- axes[ i ] = fghJoystickFudgeAxis( joy, raw_axes[ i ], i );\r
-}\r
-\r
-/*\r
- * Happy happy happy joy joy joy (happy new year toudi :D)\r
- */\r
-\r
-\r
-#if TARGET_HOST_MAC_OSX\r
-/** open the IOKit connection, enumerate all the HID devices, add their\r
-interface references to the static array. We then use the array index\r
-as the device number when we come to open() the joystick. */\r
-static int fghJoystickFindDevices ( SFG_Joystick *joy, mach_port_t masterPort )\r
-{\r
- CFMutableDictionaryRef hidMatch = NULL;\r
- IOReturn rv = kIOReturnSuccess;\r
-\r
- io_iterator_t hidIterator;\r
- io_object_t ioDev;\r
-\r
- /* build a dictionary matching HID devices */\r
- hidMatch = IOServiceMatching(kIOHIDDeviceKey);\r
-\r
- rv = IOServiceGetMatchingServices(masterPort, hidMatch, &hidIterator);\r
- if (rv != kIOReturnSuccess || !hidIterator) {\r
- fgWarning( "no joystick (HID) devices found" );\r
- return;\r
- }\r
-\r
- /* iterate */\r
- while ((ioDev = IOIteratorNext(hidIterator))) {\r
- /* filter out keyboard and mouse devices */\r
- CFDictionaryRef properties = getCFProperties(ioDev);\r
- long usage, page;\r