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

Method OpenInterfaces

source/ControllerLib/Controllers/Dualshock3Controller.cpp:32–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30}
31
32Result Dualshock3Controller::OpenInterfaces()
33{
34 Result rc;
35 rc = m_device->Open();
36 if (R_FAILED(rc))
37 return rc;
38
39 //Open each interface, send it a setup packet and get the endpoints if it succeeds
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()->bInterfaceClass != 3)
48 continue;
49
50 if (interface->GetDescriptor()->bInterfaceProtocol != 0)
51 continue;
52
53 if (interface->GetDescriptor()->bNumEndpoints < 2)
54 continue;
55
56 //Send an initial control packet
57 constexpr uint8_t initBytes[] = {0x42, 0x0C, 0x00, 0x00};
58 rc = SendCommand(interface.get(), Ds3FeatureStartDevice, initBytes, sizeof(initBytes));
59 if (R_FAILED(rc))
60 return 60;
61
62 m_interface = interface.get();
63
64 if (!m_inPipe)
65 {
66 for (int i = 0; i != 15; ++i)
67 {
68 IUSBEndpoint *inEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_IN, i);
69 if (inEndpoint)
70 {
71 rc = inEndpoint->Open();
72 if (R_FAILED(rc))
73 return 61;
74
75 m_inPipe = inEndpoint;
76 break;
77 }
78 }
79 }
80
81 if (!m_outPipe)
82 {
83 for (int i = 0; i != 15; ++i)
84 {
85 IUSBEndpoint *outEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_OUT, i);
86 if (outEndpoint)
87 {
88 rc = outEndpoint->Open();
89 if (R_FAILED(rc))

Callers

nothing calls this directly

Calls 3

GetEndpointMethod · 0.80
OpenMethod · 0.45
GetDescriptorMethod · 0.45

Tested by

no test coverage detected