-# ifdef HAVE_USBHID_H
- if( ioctl( os->fd, USB_GET_REPORT_ID, &report_id ) < 0)
- {
- /*** XXX {report_id} may not be the right variable? ***/
-#ifdef HAVE_ERRNO_H
- fgWarning ( "error: %s%d: %s", UHIDDEV, report_id, strerror( errno ) );
-#else
- fgWarning ( "error: %s%d", UHIDDEV, report_id );
-#endif
- return FALSE;
- }
-
- size = hid_report_size( rd, hid_input, report_id );
-# else
- size = hid_report_size( rd, 0, hid_input );
-# endif
- os->hid_data_buf = calloc( 1, size );
- os->hid_dlen = size;
-
- is_joystick = 0;
-# ifdef HAVE_USBHID_H
- d = hid_start_parse( rd, 1 << hid_input, report_id );
-# else
- d = hid_start_parse( rd, 1 << hid_input );
-# endif
- while( hid_get_item( d, &h ) )
- {
- int usage, page, interesting_hid;
-
- page = HID_PAGE( h.usage );
- usage = HID_USAGE( h.usage );
-
- /* This test is somewhat too simplistic, but this is how MicroSoft
- * does, so I guess it works for all joysticks/game pads. */
- is_joystick = is_joystick ||
- ( h.kind == hid_collection &&
- page == HUP_GENERIC_DESKTOP &&
- ( usage == HUG_JOYSTICK || usage == HUG_GAME_PAD ) );
-
- if( h.kind != hid_input )
- continue;
-
- if( !is_joystick )
- continue;
-
- interesting_hid = TRUE;
- if( page == HUP_GENERIC_DESKTOP )
- {
- switch( usage )
- {
- case HUG_X:
- case HUG_RX:
- case HUG_Y:
- case HUG_RY:
- case HUG_Z:
- case HUG_RZ:
- case HUG_SLIDER:
- if( *num_axes < _JS_MAX_AXES )
- {
- os->axes_usage[ *num_axes ] = usage;
- ( *num_axes )++;
- }
- break;
- case HUG_HAT_SWITCH:
- /* Allocate two axes for a hat */
- if( *num_axes + 1 < _JS_MAX_AXES )
- {
- os->axes_usage[ *num_axes ] = usage;
- (*num_axes)++;
- os->axes_usage[ *num_axes ] = usage;
- (*num_axes)++;
- }
- break;
- default:
- interesting_hid = FALSE;
- break;
- }
- }
- else if( page == HUP_BUTTON )
- {
- interesting_hid = ( usage > 0 ) &&
- ( usage <= _JS_MAX_BUTTONS );
-
- if( interesting_hid && usage - 1 > *num_buttons )
- *num_buttons = usage - 1;
- }
-
- if( interesting_hid )
- {
- h.next = os->hids;
- os->hids = calloc( 1, sizeof ( struct hid_item ) );
- *os->hids = h;
- }
- }
- hid_end_parse( d );
-
- return os->hids != NULL;
-}
-# endif