From 517851a17395bf699662cf3a34572ff92d19311a Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Sun, 5 Jun 2011 00:30:33 +0000 Subject: [PATCH] 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. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41923 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../input/usb_hid/JoystickProtocolHandler.cpp | 44 ++++++++----------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/src/add-ons/kernel/drivers/input/usb_hid/JoystickProtocolHandler.cpp b/src/add-ons/kernel/drivers/input/usb_hid/JoystickProtocolHandler.cpp index 085752b052..2fa42edd19 100644 --- a/src/add-ons/kernel/drivers/input/usb_hid/JoystickProtocolHandler.cpp +++ b/src/add-ons/kernel/drivers/input/usb_hid/JoystickProtocolHandler.cpp @@ -66,34 +66,25 @@ JoystickProtocolHandler::JoystickProtocolHandler(HIDReport &report) 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 @@ JoystickProtocolHandler::JoystickProtocolHandler(HIDReport &report) 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()); }