HIDReport * HIDParser::FindReport(uint8 type, uint8 id) { for (uint8 i = 0; i < fReportCount; i++) { HIDReport *report = fReports[i]; if (report == NULL) continue; if ((report->Type() & type) != 0 && report->ID() == id) return report; } return NULL; }
JoystickProtocolHandler::JoystickProtocolHandler(HIDReport &report) : ProtocolHandler(report.Device(), "joystick/usb/", 0), fReport(report), fAxisCount(0), fAxis(NULL), fHatCount(0), fHats(NULL), fButtonCount(0), fMaxButton(0), fButtons(NULL), fOpenCount(0), fUpdateThread(-1) { mutex_init(&fUpdateLock, "joystick update lock"); memset(&fJoystickModuleInfo, 0, sizeof(joystick_module_info)); memset(&fCurrentValues, 0, sizeof(variable_joystick)); for (uint32 i = 0; i < report.CountItems(); i++) { HIDReportItem *item = report.ItemAt(i); if (!item->HasData()) continue; switch (item->UsagePage()) { case B_HID_USAGE_PAGE_BUTTON: { if (item->UsageID() > INT16_MAX) break; HIDReportItem **newButtons = (HIDReportItem **)realloc(fButtons, ++fButtonCount * sizeof(HIDReportItem *)); if (newButtons == NULL) { fButtonCount--; break; } fButtons = newButtons; fButtons[fButtonCount - 1] = item; if (fMaxButton < item->UsageID()) fMaxButton = item->UsageID(); break; } case B_HID_USAGE_PAGE_GENERIC_DESKTOP: { if (item->UsageID() == B_HID_UID_GD_HAT_SWITCH) { HIDReportItem **newHats = (HIDReportItem **)realloc(fHats, ++fHatCount * sizeof(HIDReportItem *)); if (newHats == NULL) { fHatCount--; break; } fHats = newHats; fHats[fHatCount - 1] = item; break; } // TODO: "axis" is set but not used! // 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; HIDReportItem **newAxis = (HIDReportItem **)realloc(fAxis, ++fAxisCount * sizeof(HIDReportItem *)); if (newAxis == NULL) { fAxisCount--; break; } fAxis = newAxis; fAxis[fAxisCount - 1] = item; break; } } } fCurrentValues.initialize(fAxisCount, fHatCount, fMaxButton); TRACE("joystick device with %lu buttons, %lu axes and %lu hats\n", fButtonCount, fAxisCount, fHatCount); TRACE("report id: %u\n", report.ID()); }
TabletProtocolHandler::TabletProtocolHandler(HIDReport &report, HIDReportItem &xAxis, HIDReportItem &yAxis) : ProtocolHandler(report.Device(), "input/tablet/usb", 0), fReport(report), fXAxis(xAxis), fYAxis(yAxis), fWheel(NULL), fPressure(NULL), fRange(NULL), fTip(NULL), fBarrelSwitch(NULL), fEraser(NULL), fXTilt(NULL), fYTilt(NULL), fLastButtons(0), fClickCount(0), fLastClickTime(0), fClickSpeed(250000) { uint32 buttonCount = 0; for (uint32 i = 0; i < report.CountItems(); i++) { HIDReportItem *item = report.ItemAt(i); if (!item->HasData()) continue; if (item->UsagePage() == B_HID_USAGE_PAGE_BUTTON && item->UsageID() - 1 < B_MAX_MOUSE_BUTTONS) { fButtons[buttonCount++] = item; } } fButtons[buttonCount] = NULL; fWheel = report.FindItem(B_HID_USAGE_PAGE_GENERIC_DESKTOP, B_HID_UID_GD_WHEEL); fPressure = report.FindItem(B_HID_USAGE_PAGE_DIGITIZER, B_HID_UID_DIG_TIP_PRESSURE); fRange = report.FindItem(B_HID_USAGE_PAGE_DIGITIZER, B_HID_UID_DIG_IN_RANGE); fTip = report.FindItem(B_HID_USAGE_PAGE_DIGITIZER, B_HID_UID_DIG_TIP_SWITCH); fBarrelSwitch = report.FindItem(B_HID_USAGE_PAGE_DIGITIZER, B_HID_UID_DIG_BARREL_SWITCH); fEraser = report.FindItem(B_HID_USAGE_PAGE_DIGITIZER, B_HID_UID_DIG_ERASER); fXTilt = report.FindItem(B_HID_USAGE_PAGE_DIGITIZER, B_HID_UID_DIG_X_TILT); fYTilt = report.FindItem(B_HID_USAGE_PAGE_DIGITIZER, B_HID_UID_DIG_Y_TILT); TRACE("tablet device with %lu buttons, %stip, %seraser, " "%spressure, and %stilt\n", buttonCount, fTip == NULL ? "no " : "", fEraser == NULL ? "no " : "", fPressure == NULL ? "no " : "", fXTilt == NULL && fYTilt == NULL ? "no " : ""); TRACE("report id: %u\n", report.ID()); }