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