1
0
mirror of https://github.com/cathery/sys-con.git synced 2024-12-24 15:13:45 +00:00

more thorough interface check in controller init

This commit is contained in:
cathery 2019-11-08 15:54:33 +03:00
parent 4c78a716d6
commit b4ee502e04
3 changed files with 51 additions and 36 deletions

View File

@ -43,54 +43,56 @@ Status Dualshock3Controller::OpenInterfaces()
rc = interface->Open();
if (S_FAILED(rc))
return rc;
if (interface->GetDescriptor()->bNumEndpoints >= 2)
if (interface->GetDescriptor()->bNumEndpoints < 2)
continue;
//Send an initial control packet
uint8_t initBytes[] = {0x42, 0x0C, 0x00, 0x00};
rc = SendCommand(interface.get(), Ds3FeatureStartDevice, initBytes, sizeof(initBytes));
if (S_FAILED(rc))
return 60;
m_interface = interface.get();
if (!m_inPipe)
{
//Send an initial control packet
uint8_t initBytes[] = {0x42, 0x0C, 0x00, 0x00};
rc = SendCommand(interface.get(), Ds3FeatureStartDevice, initBytes, sizeof(initBytes));
if (S_FAILED(rc))
return 60;
m_interface = interface.get();
if (!m_inPipe)
for (int i = 0; i != 15; ++i)
{
for (int i = 0; i != 15; ++i)
IUSBEndpoint *inEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_IN, i);
if (inEndpoint)
{
IUSBEndpoint *inEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_IN, i);
if (inEndpoint)
{
rc = inEndpoint->Open();
if (S_FAILED(rc))
return 61;
rc = inEndpoint->Open();
if (S_FAILED(rc))
return 61;
m_inPipe = inEndpoint;
break;
}
m_inPipe = inEndpoint;
break;
}
}
}
if (!m_outPipe)
if (!m_outPipe)
{
for (int i = 0; i != 15; ++i)
{
for (int i = 0; i != 15; ++i)
IUSBEndpoint *outEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_OUT, i);
if (outEndpoint)
{
IUSBEndpoint *outEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_OUT, i);
if (outEndpoint)
{
rc = outEndpoint->Open();
if (S_FAILED(rc))
return 62;
rc = outEndpoint->Open();
if (S_FAILED(rc))
return 62;
m_outPipe = outEndpoint;
break;
}
m_outPipe = outEndpoint;
break;
}
}
if (!m_inPipe || !m_outPipe)
return 69;
}
}
if (!m_inPipe || !m_outPipe)
return 69;
return rc;
}
void Dualshock3Controller::CloseInterfaces()

View File

@ -47,6 +47,9 @@ Status Xbox360Controller::OpenInterfaces()
if (interface->GetDescriptor()->bInterfaceProtocol != 1)
continue;
if (interface->GetDescriptor()->bNumEndpoints < 2)
continue;
if (!m_inPipe)
{
for (int i = 0; i != 15; ++i)

View File

@ -91,8 +91,14 @@ Status XboxOneController::OpenInterfaces()
rc = interface->Open();
if (S_FAILED(rc))
return rc;
//TODO: check for numEndpoints before trying to open them!
if (interface->GetDescriptor()->bNumEndpoints >= 2)
if (interface->GetDescriptor()->bInterfaceProtocol != 208)
continue;
if (interface->GetDescriptor()->bNumEndpoints < 2)
continue;
if (!m_inPipe)
{
for (uint8_t i = 0; i != 15; ++i)
{
@ -107,6 +113,10 @@ Status XboxOneController::OpenInterfaces()
break;
}
}
}
if (!m_outPipe)
{
for (uint8_t i = 0; i != 15; ++i)
{
IUSBEndpoint *outEndpoint = interface->GetEndpoint(IUSBEndpoint::USB_ENDPOINT_OUT, i);