\r
\r
/* External function declarations (mostly platform-specific) */\r
+extern void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes );\r
extern void fgPlatformJoystickOpen( SFG_Joystick* joy );\r
extern void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident );\r
extern void fgPlatformJoystickClose ( int ident );\r
*/\r
static void fghJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )\r
{\r
-#if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE)\r
- MMRESULT status;\r
-#else\r
- int status;\r
-#endif\r
-\r
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)\r
- int len;\r
-#endif\r
-\r
int i;\r
\r
/* Defaults */\r
if( joy->error )\r
return;\r
\r
-#if TARGET_HOST_MACINTOSH\r
- if ( buttons )\r
- {\r
- *buttons = 0;\r
-\r
- for ( i = 0; i < joy->num_buttons; i++ )\r
- {\r
- UInt32 state;\r
- int err = ISpElement_GetSimpleState ( isp_elem [ i + isp_num_axis ], &state);\r
- ISP_CHECK_ERR(err)\r
-\r
- *buttons |= state << i;\r
- }\r
- }\r
-\r
- if ( axes )\r
- {\r
- for ( i = 0; i < joy->num_axes; i++ )\r
- {\r
- UInt32 state;\r
- int err = ISpElement_GetSimpleState ( isp_elem [ i ], &state );\r
- ISP_CHECK_ERR(err)\r
-\r
- axes [i] = (float) state;\r
- }\r
- }\r
-#endif\r
-\r
-#if TARGET_HOST_MAC_OSX\r
- if ( buttons != NULL )\r
- {\r
- *buttons = 0;\r
-\r
- for ( i = 0; i < joy->num_buttons; i++ )\r
- {\r
- IOHIDEventStruct hidEvent;\r
- (*(joy->hidDev))->getElementValue ( joy->hidDev, buttonCookies[i], &hidEvent );\r
- if ( hidEvent.value )\r
- *buttons |= 1 << i;\r
- }\r
- }\r
-\r
- if ( axes != NULL )\r
- {\r
- for ( i = 0; i < joy->num_axes; i++ )\r
- {\r
- IOHIDEventStruct hidEvent;\r
- (*(joy->hidDev))->getElementValue ( joy->hidDev, axisCookies[i], &hidEvent );\r
- axes[i] = hidEvent.value;\r
- }\r
- }\r
-#endif\r
-\r
-#if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE)\r
- status = joyGetPosEx( joy->js_id, &joy->js );\r
-\r
- if ( status != JOYERR_NOERROR )\r
- {\r
- joy->error = GL_TRUE;\r
- return;\r
- }\r
-\r
- if ( buttons )\r
- *buttons = joy->js.dwButtons;\r
-\r
- if ( axes )\r
- {\r
- /*\r
- * WARNING - Fall through case clauses!!\r
- */\r
- switch ( joy->num_axes )\r
- {\r
- case 8:\r
- /* Generate two POV axes from the POV hat angle.\r
- * Low 16 bits of js.dwPOV gives heading (clockwise from ahead) in\r
- * hundredths of a degree, or 0xFFFF when idle.\r
- */\r
- if ( ( joy->js.dwPOV & 0xFFFF ) == 0xFFFF )\r
- {\r
- axes [ 6 ] = 0.0;\r
- axes [ 7 ] = 0.0;\r
- }\r
- else\r
- {\r
- /* This is the contentious bit: how to convert angle to X/Y.\r
- * wk: I know of no define for PI that we could use here:\r
- * SG_PI would pull in sg, M_PI is undefined for MSVC\r
- * But the accuracy of the value of PI is very unimportant at\r
- * this point.\r
- */\r
- float s = (float) sin ( ( joy->js.dwPOV & 0xFFFF ) * ( 0.01 * 3.1415926535f / 180.0f ) );\r
- float c = (float) cos ( ( joy->js.dwPOV & 0xFFFF ) * ( 0.01 * 3.1415926535f / 180.0f ) );\r
-\r
- /* Convert to coordinates on a square so that North-East\r
- * is (1,1) not (.7,.7), etc.\r
- * s and c cannot both be zero so we won't divide by zero.\r
- */\r
- if ( fabs ( s ) < fabs ( c ) )\r
- {\r
- axes [ 6 ] = ( c < 0.0 ) ? -s/c : s/c ;\r
- axes [ 7 ] = ( c < 0.0 ) ? -1.0f : 1.0f;\r
- }\r
- else\r
- {\r
- axes [ 6 ] = ( s < 0.0 ) ? -1.0f : 1.0f;\r
- axes [ 7 ] = ( s < 0.0 ) ? -c/s : c/s ;\r
- }\r
- }\r
-\r
- case 6: axes[5] = (float) joy->js.dwVpos;\r
- case 5: axes[4] = (float) joy->js.dwUpos;\r
- case 4: axes[3] = (float) joy->js.dwRpos;\r
- case 3: axes[2] = (float) joy->js.dwZpos;\r
- case 2: axes[1] = (float) joy->js.dwYpos;\r
- case 1: axes[0] = (float) joy->js.dwXpos;\r
- }\r
- }\r
-#endif\r
-\r
-#if TARGET_HOST_POSIX_X11\r
-# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)\r
- if ( joy->os->is_analog )\r
- {\r
- int status = read ( joy->os->fd, &joy->os->ajs, sizeof(joy->os->ajs) );\r
- if ( status != sizeof(joy->os->ajs) ) {\r
- perror ( joy->os->fname );\r
- joy->error = GL_TRUE;\r
- return;\r
- }\r
- if ( buttons != NULL )\r
- *buttons = ( joy->os->ajs.b1 ? 1 : 0 ) | ( joy->os->ajs.b2 ? 2 : 0 );\r
-\r
- if ( axes != NULL )\r
- {\r
- axes[0] = (float) joy->os->ajs.x;\r
- axes[1] = (float) joy->os->ajs.y;\r
- }\r
-\r
- return;\r
- }\r
-\r
-# ifdef HAVE_USB_JS\r
- while ( ( len = read ( joy->os->fd, joy->os->hid_data_buf, joy->os->hid_dlen ) ) == joy->os->hid_dlen )\r
- {\r
- struct hid_item *h;\r
-\r
- for ( h = joy->os->hids; h; h = h->next )\r
- {\r
- int d = hid_get_data ( joy->os->hid_data_buf, h );\r
-\r
- int page = HID_PAGE ( h->usage );\r
- int usage = HID_USAGE ( h->usage );\r
-\r
- if ( page == HUP_GENERIC_DESKTOP )\r
- {\r
- int i;\r
- for ( i = 0; i < joy->num_axes; i++ )\r
- if (joy->os->axes_usage[i] == usage)\r
- {\r
- if (usage == HUG_HAT_SWITCH)\r
- {\r
- if (d < 0 || d > 8)\r
- d = 0; /* safety */\r
- joy->os->cache_axes[i] = (float)hatmap_x[d];\r
- joy->os->cache_axes[i + 1] = (float)hatmap_y[d];\r
- }\r
- else\r
- {\r
- joy->os->cache_axes[i] = (float)d;\r
- }\r
- break;\r
- }\r
- }\r
- else if (page == HUP_BUTTON)\r
- {\r
- if (usage > 0 && usage < _JS_MAX_BUTTONS + 1)\r
- {\r
- if (d)\r
- joy->os->cache_buttons |= (1 << ( usage - 1 ));\r
- else\r
- joy->os->cache_buttons &= ~(1 << ( usage - 1 ));\r
- }\r
- }\r
- }\r
- }\r
-#ifdef HAVE_ERRNO_H\r
- if ( len < 0 && errno != EAGAIN )\r
-#else\r
- if ( len < 0 )\r
-#endif\r
- {\r
- perror( joy->os->fname );\r
- joy->error = 1;\r
- }\r
- if ( buttons != NULL ) *buttons = joy->os->cache_buttons;\r
- if ( axes != NULL )\r
- memcpy ( axes, joy->os->cache_axes, sizeof(float) * joy->num_axes );\r
-# endif\r
-# endif\r
-\r
-# 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
+ fgPlatformJoystickRawRead ( joy, buttons, axes );\r
}\r
\r
/*\r
*/\r
\r
#if TARGET_HOST_MACINTOSH\r
+void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )\r
+{\r
+ int i;\r
+\r
+ if ( buttons )\r
+ {\r
+ *buttons = 0;\r
+\r
+ for ( i = 0; i < joy->num_buttons; i++ )\r
+ {\r
+ UInt32 state;\r
+ int err = ISpElement_GetSimpleState ( isp_elem [ i + isp_num_axis ], &state);\r
+ ISP_CHECK_ERR(err)\r
+\r
+ *buttons |= state << i;\r
+ }\r
+ }\r
+\r
+ if ( axes )\r
+ {\r
+ for ( i = 0; i < joy->num_axes; i++ )\r
+ {\r
+ UInt32 state;\r
+ int err = ISpElement_GetSimpleState ( isp_elem [ i ], &state );\r
+ ISP_CHECK_ERR(err)\r
+\r
+ axes [i] = (float) state;\r
+ }\r
+ }\r
+}\r
+\r
+\r
void fgPlatformJoystickOpen( SFG_Joystick* joy )\r
{\r
int i = 0;\r
#endif\r
\r
#if TARGET_HOST_MAC_OSX\r
+void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )\r
+{\r
+ int i;\r
+\r
+ if ( buttons != NULL )\r
+ {\r
+ *buttons = 0;\r
+\r
+ for ( i = 0; i < joy->num_buttons; i++ )\r
+ {\r
+ IOHIDEventStruct hidEvent;\r
+ (*(joy->hidDev))->getElementValue ( joy->hidDev, buttonCookies[i], &hidEvent );\r
+ if ( hidEvent.value )\r
+ *buttons |= 1 << i;\r
+ }\r
+ }\r
+\r
+ if ( axes != NULL )\r
+ {\r
+ for ( i = 0; i < joy->num_axes; i++ )\r
+ {\r
+ IOHIDEventStruct hidEvent;\r
+ (*(joy->hidDev))->getElementValue ( joy->hidDev, axisCookies[i], &hidEvent );\r
+ axes[i] = hidEvent.value;\r
+ }\r
+ }\r
+}\r
+\r
+\r
void fgPlatformJoystickOpen( SFG_Joystick* joy )\r
{\r
IOReturn rv;\r
#endif\r
\r
#if TARGET_HOST_POSIX_X11\r
+void fgPlatformJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )\r
+{\r
+ int status;\r
+\r
+ int i;\r
+\r
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)\r
+ int len;\r
+\r
+ if ( joy->os->is_analog )\r
+ {\r
+ int status = read ( joy->os->fd, &joy->os->ajs, sizeof(joy->os->ajs) );\r
+ if ( status != sizeof(joy->os->ajs) ) {\r
+ perror ( joy->os->fname );\r
+ joy->error = GL_TRUE;\r
+ return;\r
+ }\r
+ if ( buttons != NULL )\r
+ *buttons = ( joy->os->ajs.b1 ? 1 : 0 ) | ( joy->os->ajs.b2 ? 2 : 0 );\r
+\r
+ if ( axes != NULL )\r
+ {\r
+ axes[0] = (float) joy->os->ajs.x;\r
+ axes[1] = (float) joy->os->ajs.y;\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+# ifdef HAVE_USB_JS\r
+ while ( ( len = read ( joy->os->fd, joy->os->hid_data_buf, joy->os->hid_dlen ) ) == joy->os->hid_dlen )\r
+ {\r
+ struct hid_item *h;\r
+\r
+ for ( h = joy->os->hids; h; h = h->next )\r
+ {\r
+ int d = hid_get_data ( joy->os->hid_data_buf, h );\r
+\r
+ int page = HID_PAGE ( h->usage );\r
+ int usage = HID_USAGE ( h->usage );\r
+\r
+ if ( page == HUP_GENERIC_DESKTOP )\r
+ {\r
+ int i;\r
+ for ( i = 0; i < joy->num_axes; i++ )\r
+ if (joy->os->axes_usage[i] == usage)\r
+ {\r
+ if (usage == HUG_HAT_SWITCH)\r
+ {\r
+ if (d < 0 || d > 8)\r
+ d = 0; /* safety */\r
+ joy->os->cache_axes[i] = (float)hatmap_x[d];\r
+ joy->os->cache_axes[i + 1] = (float)hatmap_y[d];\r
+ }\r
+ else\r
+ {\r
+ joy->os->cache_axes[i] = (float)d;\r
+ }\r
+ break;\r
+ }\r
+ }\r
+ else if (page == HUP_BUTTON)\r
+ {\r
+ if (usage > 0 && usage < _JS_MAX_BUTTONS + 1)\r
+ {\r
+ if (d)\r
+ joy->os->cache_buttons |= (1 << ( usage - 1 ));\r
+ else\r
+ joy->os->cache_buttons &= ~(1 << ( usage - 1 ));\r
+ }\r
+ }\r
+ }\r
+ }\r
+# ifdef HAVE_ERRNO_H\r
+ if ( len < 0 && errno != EAGAIN )\r
+# else\r
+ if ( len < 0 )\r
+# endif\r
+ {\r
+ perror( joy->os->fname );\r
+ joy->error = 1;\r
+ }\r
+ if ( buttons != NULL ) *buttons = joy->os->cache_buttons;\r
+ if ( axes != NULL )\r
+ memcpy ( axes, joy->os->cache_axes, sizeof(float) * joy->num_axes );\r
+# endif\r
+#endif\r
+\r
+#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
+}\r
+\r
+\r
void fgPlatformJoystickOpen( SFG_Joystick* joy )\r
{\r
#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )\r