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
This commit is contained in:
Michael Lotz
2011-06-05 00:30:33 +00:00
parent 9aec639d12
commit 517851a173
@@ -66,34 +66,25 @@ JoystickProtocolHandler::JoystickProtocolHandler(HIDReport &report)
case B_HID_USAGE_PAGE_GENERIC_DESKTOP: case B_HID_USAGE_PAGE_GENERIC_DESKTOP:
{ {
switch (item->UsageID()) { uint16 axis = 0;
case B_HID_UID_GD_X: if (item->UsageID() >= B_HID_UID_GD_X
case B_HID_UID_GD_Y: && item->UsageID() <= B_HID_UID_GD_WHEEL) {
case B_HID_UID_GD_Z: axis = item->UsageID() - B_HID_UID_GD_X;
case B_HID_UID_GD_RX: } else if (item->UsageID() >= B_HID_UID_GD_VX
case B_HID_UID_GD_RY: && item->UsageID() <= B_HID_UID_GD_VNO) {
case B_HID_UID_GD_RZ: axis = item->UsageID() - B_HID_UID_GD_VX;
uint16 axis = item->UsageID() - B_HID_UID_GD_X + 1; } else
if (axis > INT16_MAX)
break; break;
if (fAxisCount < axis) { HIDReportItem **newAxis = (HIDReportItem **)realloc(fAxis,
HIDReportItem **newAxis = (HIDReportItem **)realloc( ++fAxisCount * sizeof(HIDReportItem *));
fAxis, axis * sizeof(HIDReportItem *)); if (newAxis == NULL) {
if (newAxis == NULL) fAxisCount--;
break; break;
}
for (uint16 i = fAxisCount; i < axis; i++)
newAxis[i] = NULL;
fAxis = newAxis; fAxis = newAxis;
fAxisCount = axis; fAxis[fAxisCount - 1] = item;
}
fAxis[axis - 1] = item;
break;
}
break; break;
} }
} }
@@ -102,7 +93,8 @@ JoystickProtocolHandler::JoystickProtocolHandler(HIDReport &report)
fCurrentValues.initialize(fAxisCount, 0, fMaxButton); 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()); TRACE("report id: %u\n", report.ID());
} }