MCPcopy Create free account
hub / github.com/cathery/sys-con / OpenInterfaces

Method OpenInterfaces

source/ControllerLib/Controllers/Xbox360Controller.cpp:32–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30}
31
32Result 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;

Callers

nothing calls this directly

Calls 3

GetEndpointMethod · 0.80
OpenMethod · 0.45
GetDescriptorMethod · 0.45

Tested by

no test coverage detected