| 44 | } |
| 45 | |
| 46 | Result Dualshock4Controller::OpenInterfaces() |
| 47 | { |
| 48 | Result rc; |
| 49 | rc = m_device->Open(); |
| 50 | if (R_FAILED(rc)) |
| 51 | return rc; |
| 52 | |
| 53 | //Open each interface, send it a setup packet and get the endpoints if it succeeds |
| 54 | std::vector<std::unique_ptr<IUSBInterface>> &interfaces = m_device->GetInterfaces(); |
| 55 | for (auto &&interface : interfaces) |
| 56 | { |
| 57 | rc = interface->Open(); |
| 58 | if (R_FAILED(rc)) |
| 59 | return rc; |
| 60 | |
| 61 | if (interface->GetDescriptor()->bInterfaceClass != 3) |
| 62 | continue; |
| 63 | |
| 64 | if (interface->GetDescriptor()->bInterfaceProtocol != 0) |
| 65 | continue; |
| 66 | |
| 67 | if (interface->GetDescriptor()->bNumEndpoints < 2) |
| 68 | continue; |
| 69 | |
| 70 | if (!m_inPipe) |
| 71 | { |
| 72 | for (int i = 0; i != 15; ++i) |
| 73 | { |
| 74 | IUSBEndpoint *inEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_IN, i); |
| 75 | if (inEndpoint) |
| 76 | { |
| 77 | rc = inEndpoint->Open(); |
| 78 | if (R_FAILED(rc)) |
| 79 | return 61; |
| 80 | |
| 81 | m_inPipe = inEndpoint; |
| 82 | break; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | if (!m_outPipe) |
| 88 | { |
| 89 | for (int i = 0; i != 15; ++i) |
| 90 | { |
| 91 | IUSBEndpoint *outEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_OUT, i); |
| 92 | if (outEndpoint) |
| 93 | { |
| 94 | rc = outEndpoint->Open(); |
| 95 | if (R_FAILED(rc)) |
| 96 | return 62; |
| 97 | |
| 98 | m_outPipe = outEndpoint; |
| 99 | break; |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | } |
nothing calls this directly
no test coverage detected