Date: Sat, 26 Apr 2014 06:11:38 GMT From: Thomas Russo <russo@bogodyn.org> To: freebsd-gnats-submit@FreeBSD.org Subject: ports/189006: x11-toolkits/plib improperly handles USB joystick min/max/center, and ignores "dial" axes Message-ID: <201404260611.s3Q6Bcoj059131@cgiserv.freebsd.org> Resent-Message-ID: <201404260620.s3Q6K02o097389@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 189006 >Category: ports >Synopsis: x11-toolkits/plib improperly handles USB joystick min/max/center, and ignores "dial" axes >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Apr 26 06:20:00 UTC 2014 >Closed-Date: >Last-Modified: >Originator: Thomas Russo >Release: 9.2-STABLE >Organization: >Environment: FreeBSD bogodyn.org 9.2-STABLE FreeBSD 9.2-STABLE #0 r261812: Wed Feb 12 17:21:14 MST 2014 russo@bogodyn.org:/usr/obj/usr/src/sys/BOGODYN i386 >Description: plib upstream has not produced a release tarball since 2006, and in the release version the min/max/center values of USB uhid joysticks is hard coded as 0/255/127. This is clearly wrong for many joysticks on the market today. In 2008 someone submitted a patch to the PLIB developers and it was put into their sourceforge repository, but no release was created after that. Thus, the plib in the FreeBSD ports collection still has the hard-coded min/max/center. Further, the jsBSD.cxx file switch statement that detects various axis types doesn't recognize "Dial" type axes. Joysticks such as the Saitek X45 have such dials, which get ignored by plib. The result is that UHID devices that have min/max values other than 0/255 fail to perform correctly in games such as flightgear --- they will either not have the full range of values showing up, will not center properly, or will otherwise produce weird, uncalibrated input to the game. >How-To-Repeat: Install Flightgear. Plug a USB joystick device such as the Saitek X45 Flight Controller or the Saitek Pro Flight Rudder Pedals into a BSD machine, and run the "js_demo" program. For the X45, only 6 of the 7 axes will show up. Few of the axes will show their full range -1 to 1. This is because most of the axes don't have logical min/max of 0/255: Input rid=0 size=12 count=1 page=Generic_Desktop usage=X, logical range 52..264 Input rid=0 size=12 count=1 page=Generic_Desktop usage=Y, logical range 22..232 Input rid=0 size=8 count=1 page=Generic_Desktop usage=Slider, logical range 96..246 Input rid=0 size=8 count=1 page=Generic_Desktop usage=Rz, logical range 91..253 Input rid=0 size=8 count=1 page=Generic_Desktop usage=Dial, logical range 1..163 Input rid=0 size=8 count=1 page=Generic_Desktop usage=Rx, logical range 4..172 Input rid=0 size=4 count=1 page=Generic_Desktop usage=Hat_Switch, logical range 1..8, physical range 0..315, unit=0x14 exp=0 For the Pro Flight Rudder Pedals, the logical range is 0 to 511, and so 0-255 (left rudder) are mapped to -1 to +1, and 256-511 (right rudder)are treated as "saturated", always showing up as +1 >Fix: The attached patch completely fixes the problem for me. It is a combination of the 2008 patch that fixes the min/max/center issue, and an addition of HUG_DIAL to the recognized axis types. Patch attached with submission follows: --- src/js/jsBSD.cxx_orig 2014-04-25 23:37:11.000000000 -0600 +++ src/js/jsBSD.cxx 2014-04-25 23:38:54.000000000 -0600 @@ -99,6 +99,8 @@ // on every read of a USB device int cache_buttons ; float cache_axes [ _JS_MAX_AXES ] ; + float axes_minimum [ _JS_MAX_AXES ] ; + float axes_maximum [ _JS_MAX_AXES ] ; }; // Idents lower than USB_IDENT_OFFSET are for analog joysticks. @@ -196,9 +198,12 @@ case HUG_Z: case HUG_RZ: case HUG_SLIDER: + case HUG_DIAL: if (*num_axes < _JS_MAX_AXES) { os->axes_usage[*num_axes] = usage; + os->axes_minimum[*num_axes] = h.logical_minimum; + os->axes_maximum[*num_axes] = h.logical_maximum; (*num_axes)++; } break; @@ -324,9 +329,6 @@ for ( int i = 0 ; i < _JS_MAX_AXES ; i++ ) { - // We really should get this from the HID, but that data seems - // to be quite unreliable for analog-to-USB converters. Punt for - // now. if ( os->axes_usage [ i ] == HUG_HAT_SWITCH ) { max [ i ] = 1.0f ; @@ -335,9 +337,9 @@ } else { - max [ i ] = 255.0f ; - center [ i ] = 127.0f ; - min [ i ] = 0.0f ; + max [ i ] = os->axes_maximum [ i ]; + min [ i ] = os->axes_minimum [ i ]; + center [ i ] = (max [ i ] + min [ i ]) / 2.0 ; } dead_band [ i ] = 0.0f ; saturate [ i ] = 1.0f ; >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201404260611.s3Q6Bcoj059131>