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

Method OpenInterfaces

source/ControllerLib/Controllers/XboxController.cpp:31–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

GetEndpointMethod · 0.80
OpenMethod · 0.45
GetDescriptorMethod · 0.45

Tested by

no test coverage detected