| 29 | } |
| 30 | |
| 31 | Result XboxController::OpenInterfaces() |
| 32 | { |
| 33 | Result rc; |
| 34 | rc = m_device->Open(); |
| 35 | if (R_FAILED(rc)) |
| 36 | return rc; |
| 37 | |
| 38 | //This will open each interface and try to acquire Xbox controller's in and out endpoints, if it hasn't already |
| 39 | std::vector<std::unique_ptr<IUSBInterface>> &interfaces = m_device->GetInterfaces(); |
| 40 | for (auto &&interface : interfaces) |
| 41 | { |
| 42 | rc = interface->Open(); |
| 43 | if (R_FAILED(rc)) |
| 44 | return rc; |
| 45 | |
| 46 | if (interface->GetDescriptor()->bInterfaceProtocol != 0) |
| 47 | continue; |
| 48 | |
| 49 | if (interface->GetDescriptor()->bNumEndpoints < 2) |
| 50 | continue; |
| 51 | |
| 52 | if (!m_inPipe) |
| 53 | { |
| 54 | for (int i = 0; i != 15; ++i) |
| 55 | { |
| 56 | IUSBEndpoint *inEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_IN, i); |
| 57 | if (inEndpoint) |
| 58 | { |
| 59 | rc = inEndpoint->Open(); |
| 60 | if (R_FAILED(rc)) |
| 61 | return 55555; |
| 62 | |
| 63 | m_inPipe = inEndpoint; |
| 64 | break; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | if (!m_outPipe) |
| 70 | { |
| 71 | for (int i = 0; i != 15; ++i) |
| 72 | { |
| 73 | IUSBEndpoint *outEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_OUT, i); |
| 74 | if (outEndpoint) |
| 75 | { |
| 76 | rc = outEndpoint->Open(); |
| 77 | if (R_FAILED(rc)) |
| 78 | return 66666; |
| 79 | |
| 80 | m_outPipe = outEndpoint; |
| 81 | break; |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | if (!m_inPipe || !m_outPipe) |
| 88 | return 69; |
nothing calls this directly
no test coverage detected