mirror of
https://github.com/cathery/sys-con.git
synced 2024-10-02 20:52:02 +00:00
Raise device limit to 10 and prevent it from going any further
This commit is contained in:
parent
562f5f37dc
commit
fc48561b3a
@ -98,7 +98,7 @@ Result mainLoop()
|
|||||||
WriteToLog("Successfully created catch-all event");
|
WriteToLog("Successfully created catch-all event");
|
||||||
}
|
}
|
||||||
|
|
||||||
controllerInterfaces.reserve(8);
|
controllerInterfaces.reserve(10);
|
||||||
|
|
||||||
while (appletMainLoop())
|
while (appletMainLoop())
|
||||||
{
|
{
|
||||||
@ -114,117 +114,121 @@ Result mainLoop()
|
|||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc))
|
||||||
{
|
{
|
||||||
WriteToLog("Catch-all event went off");
|
WriteToLog("Catch-all event went off");
|
||||||
UsbHsInterface interfaces[8];
|
if (controllerInterfaces.size() >= 10)
|
||||||
s32 total_entries;
|
WriteToLog("But the controllers table reached its max size!");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UsbHsInterface interfaces[8];
|
||||||
|
s32 total_entries;
|
||||||
|
|
||||||
if (R_SUCCEEDED(QueryInterfaces(interfaces, sizeof(interfaces), &total_entries, USB_CLASS_VENDOR_SPEC, 93, 1)))
|
if (R_SUCCEEDED(QueryInterfaces(interfaces, sizeof(interfaces), &total_entries, USB_CLASS_VENDOR_SPEC, 93, 1)))
|
||||||
{
|
|
||||||
WriteToLog("Registering Xbox 360 controller");
|
|
||||||
devicePtr = std::make_unique<SwitchUSBDevice>(interfaces, total_entries);
|
|
||||||
controllerPtr = std::make_unique<Xbox360Controller>(std::move(devicePtr));
|
|
||||||
}
|
|
||||||
else if (R_SUCCEEDED(QueryInterfaces(interfaces, sizeof(interfaces), &total_entries, USB_CLASS_VENDOR_SPEC, 93, 129)))
|
|
||||||
{
|
|
||||||
WriteToLog("Registering Xbox 360 Wireless adapter");
|
|
||||||
for (int i = 0; i != total_entries; ++i)
|
|
||||||
{
|
{
|
||||||
devicePtr = std::make_unique<SwitchUSBDevice>(interfaces + i, 1);
|
WriteToLog("Registering Xbox 360 controller");
|
||||||
controllerPtr = std::make_unique<Xbox360WirelessController>(std::move(devicePtr));
|
devicePtr = std::make_unique<SwitchUSBDevice>(interfaces, total_entries);
|
||||||
CallInitHandler();
|
controllerPtr = std::make_unique<Xbox360Controller>(std::move(devicePtr));
|
||||||
|
}
|
||||||
|
else if (R_SUCCEEDED(QueryInterfaces(interfaces, sizeof(interfaces), &total_entries, USB_CLASS_VENDOR_SPEC, 93, 129)))
|
||||||
|
{
|
||||||
|
WriteToLog("Registering Xbox 360 Wireless adapter");
|
||||||
|
for (int i = 0; i != total_entries; ++i)
|
||||||
|
{
|
||||||
|
devicePtr = std::make_unique<SwitchUSBDevice>(interfaces + i, 1);
|
||||||
|
controllerPtr = std::make_unique<Xbox360WirelessController>(std::move(devicePtr));
|
||||||
|
CallInitHandler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (R_SUCCEEDED(QueryInterfaces(interfaces, sizeof(interfaces), &total_entries, 0x58, 0x42, 0x00)))
|
||||||
|
{
|
||||||
|
WriteToLog("Registering Xbox One controller");
|
||||||
|
devicePtr = std::make_unique<SwitchUSBDevice>(interfaces, total_entries);
|
||||||
|
controllerPtr = std::make_unique<XboxController>(std::move(devicePtr));
|
||||||
|
}
|
||||||
|
else if (R_SUCCEEDED(QueryInterfaces(interfaces, sizeof(interfaces), &total_entries, USB_CLASS_VENDOR_SPEC, 71, 208)))
|
||||||
|
{
|
||||||
|
WriteToLog("Registering Xbox One controller");
|
||||||
|
devicePtr = std::make_unique<SwitchUSBDevice>(interfaces, total_entries);
|
||||||
|
controllerPtr = std::make_unique<XboxOneController>(std::move(devicePtr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (R_SUCCEEDED(QueryInterfaces(interfaces, sizeof(interfaces), &total_entries, 0x58, 0x42, 0x00)))
|
rc = eventWait(&ds3Event, 0);
|
||||||
{
|
|
||||||
WriteToLog("Registering Xbox One controller");
|
|
||||||
devicePtr = std::make_unique<SwitchUSBDevice>(interfaces, total_entries);
|
|
||||||
controllerPtr = std::make_unique<XboxController>(std::move(devicePtr));
|
|
||||||
}
|
|
||||||
else if (R_SUCCEEDED(QueryInterfaces(interfaces, sizeof(interfaces), &total_entries, USB_CLASS_VENDOR_SPEC, 71, 208)))
|
|
||||||
{
|
|
||||||
WriteToLog("Registering Xbox One controller");
|
|
||||||
devicePtr = std::make_unique<SwitchUSBDevice>(interfaces, total_entries);
|
|
||||||
controllerPtr = std::make_unique<XboxOneController>(std::move(devicePtr));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rc = eventWait(&ds3Event, 0);
|
|
||||||
if (R_SUCCEEDED(rc))
|
|
||||||
{
|
|
||||||
WriteToLog("Dualshock 3 event went off");
|
|
||||||
UsbHsInterface interfaces[4];
|
|
||||||
s32 total_entries;
|
|
||||||
|
|
||||||
if (R_SUCCEEDED(QueryInterfaces(interfaces, sizeof(interfaces), &total_entries, USB_CLASS_HID, 0, 0)))
|
|
||||||
{
|
|
||||||
WriteToLog("Registering DS3 controller");
|
|
||||||
devicePtr = std::make_unique<SwitchUSBDevice>(interfaces, total_entries);
|
|
||||||
controllerPtr = std::make_unique<Dualshock3Controller>(std::move(devicePtr));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CallInitHandler();
|
|
||||||
|
|
||||||
//On interface change event, check if any devices were removed, and erase them from memory appropriately
|
|
||||||
rc = eventWait(usbHsGetInterfaceStateChangeEvent(), 0);
|
|
||||||
if (R_SUCCEEDED(rc))
|
|
||||||
{
|
|
||||||
WriteToLog("Interface state was changed");
|
|
||||||
eventClear(usbHsGetInterfaceStateChangeEvent());
|
|
||||||
|
|
||||||
UsbHsInterface interfaces[4];
|
|
||||||
s32 total_entries;
|
|
||||||
|
|
||||||
rc = usbHsQueryAcquiredInterfaces(interfaces, sizeof(interfaces), &total_entries);
|
|
||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc))
|
||||||
{
|
{
|
||||||
for (auto it = controllerInterfaces.begin(); it != controllerInterfaces.end(); ++it)
|
WriteToLog("Dualshock 3 event went off");
|
||||||
{
|
UsbHsInterface interfaces[4];
|
||||||
bool found_flag = false;
|
s32 total_entries;
|
||||||
|
|
||||||
for (auto &&ptr : (*it)->GetController()->GetDevice()->GetInterfaces())
|
if (R_SUCCEEDED(QueryInterfaces(interfaces, sizeof(interfaces), &total_entries, USB_CLASS_HID, 0, 0)))
|
||||||
|
{
|
||||||
|
WriteToLog("Registering DS3 controller");
|
||||||
|
devicePtr = std::make_unique<SwitchUSBDevice>(interfaces, total_entries);
|
||||||
|
controllerPtr = std::make_unique<Dualshock3Controller>(std::move(devicePtr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CallInitHandler();
|
||||||
|
|
||||||
|
//On interface change event, check if any devices were removed, and erase them from memory appropriately
|
||||||
|
rc = eventWait(usbHsGetInterfaceStateChangeEvent(), 0);
|
||||||
|
if (R_SUCCEEDED(rc))
|
||||||
|
{
|
||||||
|
WriteToLog("Interface state was changed");
|
||||||
|
eventClear(usbHsGetInterfaceStateChangeEvent());
|
||||||
|
|
||||||
|
UsbHsInterface interfaces[4];
|
||||||
|
s32 total_entries;
|
||||||
|
|
||||||
|
rc = usbHsQueryAcquiredInterfaces(interfaces, sizeof(interfaces), &total_entries);
|
||||||
|
if (R_SUCCEEDED(rc))
|
||||||
|
{
|
||||||
|
for (auto it = controllerInterfaces.begin(); it != controllerInterfaces.end(); ++it)
|
||||||
{
|
{
|
||||||
//We check if a device was removed by comparing the controller's interfaces and the currently acquired interfaces
|
bool found_flag = false;
|
||||||
//If we didn't find a single matching interface ID, we consider a controller removed
|
|
||||||
for (int i = 0; i != total_entries; ++i)
|
for (auto &&ptr : (*it)->GetController()->GetDevice()->GetInterfaces())
|
||||||
{
|
{
|
||||||
if (interfaces[i].inf.ID == static_cast<SwitchUSBInterface *>(ptr.get())->GetID())
|
//We check if a device was removed by comparing the controller's interfaces and the currently acquired interfaces
|
||||||
|
//If we didn't find a single matching interface ID, we consider a controller removed
|
||||||
|
for (int i = 0; i != total_entries; ++i)
|
||||||
{
|
{
|
||||||
found_flag = true;
|
if (interfaces[i].inf.ID == static_cast<SwitchUSBInterface *>(ptr.get())->GetID())
|
||||||
break;
|
{
|
||||||
|
found_flag = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!found_flag)
|
if (!found_flag)
|
||||||
{
|
{
|
||||||
WriteToLog("Erasing controller! ", (*it)->GetController()->GetType());
|
WriteToLog("Erasing controller! ", (*it)->GetController()->GetType());
|
||||||
controllerInterfaces.erase(it--);
|
controllerInterfaces.erase(it--);
|
||||||
WriteToLog("Controller erased!");
|
WriteToLog("Controller erased!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
rc = waitSingle(filecheckTimerWaiter, 0);
|
rc = waitSingle(filecheckTimerWaiter, 0);
|
||||||
if (R_SUCCEEDED(rc))
|
if (R_SUCCEEDED(rc))
|
||||||
{
|
|
||||||
if (CheckForFileChanges())
|
|
||||||
{
|
{
|
||||||
WriteToLog("File check succeeded! Loading configs...");
|
if (CheckForFileChanges())
|
||||||
LoadAllConfigs();
|
{
|
||||||
|
WriteToLog("File check succeeded! Loading configs...");
|
||||||
|
LoadAllConfigs();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __APPLET__
|
#ifdef __APPLET__
|
||||||
consoleUpdate(nullptr);
|
consoleUpdate(nullptr);
|
||||||
#else
|
#else
|
||||||
svcSleepThread(1e+7L);
|
svcSleepThread(1e+7L);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
//After we break out of the loop, close all events and exit
|
||||||
|
WriteToLog("Destroying events");
|
||||||
|
usbHsDestroyInterfaceAvailableEvent(&ds3Event, 0);
|
||||||
|
usbHsDestroyInterfaceAvailableEvent(&catchAllEvent, 1);
|
||||||
|
|
||||||
|
//controllerInterfaces.clear();
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
//After we break out of the loop, close all events and exit
|
|
||||||
WriteToLog("Destroying events");
|
|
||||||
usbHsDestroyInterfaceAvailableEvent(&ds3Event, 0);
|
|
||||||
usbHsDestroyInterfaceAvailableEvent(&catchAllEvent, 1);
|
|
||||||
|
|
||||||
//controllerInterfaces.clear();
|
|
||||||
return rc;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user