[haiku-commits] r41923 - haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid

  • From: mmlr@xxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 5 Jun 2011 02:30:33 +0200 (CEST)

Author: mmlr
Date: 2011-06-05 02:30:33 +0200 (Sun, 05 Jun 2011)
New Revision: 41923
Changeset: https://dev.haiku-os.org/changeset/41923

Modified:
   
haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/JoystickProtocolHandler.cpp
Log:
Reimplement axis mapping and allow for more usages to be axes. This allows for
duplicate usages and simply adds more axes in that case. It also removes the
gaps that were previously put in place if there were higher numbered axes.
However, since the ordering of the axes now depends on the ordering inside the
HID collection, it is possible that some controllers won't have the X, Y and Z
axis mapped as the first three axes, which might confuse applications. I've not
encountered a report structure that would lead to such a situation yet, but then
again the amount of reports I was able to get hold of is fairly limited. If it
becomes a problem the mapping needs to be adjusted accordingly.


Modified: 
haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/JoystickProtocolHandler.cpp
===================================================================
--- 
haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/JoystickProtocolHandler.cpp
    2011-06-05 00:12:15 UTC (rev 41922)
+++ 
haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid/JoystickProtocolHandler.cpp
    2011-06-05 00:30:33 UTC (rev 41923)
@@ -66,34 +66,25 @@
 
                        case B_HID_USAGE_PAGE_GENERIC_DESKTOP:
                        {
-                               switch (item->UsageID()) {
-                                       case B_HID_UID_GD_X:
-                                       case B_HID_UID_GD_Y:
-                                       case B_HID_UID_GD_Z:
-                                       case B_HID_UID_GD_RX:
-                                       case B_HID_UID_GD_RY:
-                                       case B_HID_UID_GD_RZ:
-                                               uint16 axis = item->UsageID() - 
B_HID_UID_GD_X + 1;
-                                               if (axis > INT16_MAX)
-                                                       break;
+                               uint16 axis = 0;
+                               if (item->UsageID() >= B_HID_UID_GD_X
+                                       && item->UsageID() <= 
B_HID_UID_GD_WHEEL) {
+                                       axis = item->UsageID() - B_HID_UID_GD_X;
+                               } else if (item->UsageID() >= B_HID_UID_GD_VX
+                                       && item->UsageID() <= B_HID_UID_GD_VNO) 
{
+                                       axis = item->UsageID() - 
B_HID_UID_GD_VX;
+                               } else
+                                       break;
 
-                                               if (fAxisCount < axis) {
-                                                       HIDReportItem **newAxis 
= (HIDReportItem **)realloc(
-                                                               fAxis, axis * 
sizeof(HIDReportItem *));
-                                                       if (newAxis == NULL)
-                                                               break;
-
-                                                       for (uint16 i = 
fAxisCount; i < axis; i++)
-                                                               newAxis[i] = 
NULL;
-
-                                                       fAxis = newAxis;
-                                                       fAxisCount = axis;
-                                               }
-
-                                               fAxis[axis - 1] = item;
-                                               break;
+                               HIDReportItem **newAxis = (HIDReportItem 
**)realloc(fAxis,
+                                       ++fAxisCount * sizeof(HIDReportItem *));
+                               if (newAxis == NULL) {
+                                       fAxisCount--;
+                                       break;
                                }
 
+                               fAxis = newAxis;
+                               fAxis[fAxisCount - 1] = item;
                                break;
                        }
                }
@@ -102,7 +93,8 @@
 
        fCurrentValues.initialize(fAxisCount, 0, fMaxButton);
 
-       TRACE("joystick device with %lu buttons\n", fButtonCount);
+       TRACE("joystick device with %lu buttons and %lu axes\n", fButtonCount,
+               fAxisCount);
        TRACE("report id: %u\n", report.ID());
 }
 


Other related posts:

  • » [haiku-commits] r41923 - haiku/trunk/src/add-ons/kernel/drivers/input/usb_hid - mmlr