From 1d16b46e4d8f22499a2dfbe6b25871248aa434f0 Mon Sep 17 00:00:00 2001 From: cathery Date: Sat, 9 Nov 2019 11:48:53 +0300 Subject: [PATCH] forgot a bracket --- source/mainLoop.cpp | 130 ++++++++++++++++++++++---------------------- 1 file changed, 66 insertions(+), 64 deletions(-) diff --git a/source/mainLoop.cpp b/source/mainLoop.cpp index cab8232..cb6ec2d 100644 --- a/source/mainLoop.cpp +++ b/source/mainLoop.cpp @@ -118,6 +118,7 @@ Result mainLoop() WriteToLog("But the controllers table reached its max size!"); else { + UsbHsInterface interfaces[8]; s32 total_entries; @@ -150,85 +151,86 @@ Result mainLoop() controllerPtr = std::make_unique(std::move(devicePtr)); } } - rc = eventWait(&ds3Event, 0); - if (R_SUCCEEDED(rc)) - { - WriteToLog("Dualshock 3 event went off"); - UsbHsInterface interfaces[4]; - s32 total_entries; + } + 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(interfaces, total_entries); - controllerPtr = std::make_unique(std::move(devicePtr)); - } + if (R_SUCCEEDED(QueryInterfaces(interfaces, sizeof(interfaces), &total_entries, USB_CLASS_HID, 0, 0))) + { + WriteToLog("Registering DS3 controller"); + devicePtr = std::make_unique(interfaces, total_entries); + controllerPtr = std::make_unique(std::move(devicePtr)); } - CallInitHandler(); + } + CallInitHandler(); - //On interface change event, check if any devices were removed, and erase them from memory appropriately - rc = eventWait(usbHsGetInterfaceStateChangeEvent(), 0); + //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)) { - 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) { - for (auto it = controllerInterfaces.begin(); it != controllerInterfaces.end(); ++it) - { - bool found_flag = false; + bool found_flag = false; - for (auto &&ptr : (*it)->GetController()->GetDevice()->GetInterfaces()) + for (auto &&ptr : (*it)->GetController()->GetDevice()->GetInterfaces()) + { + //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) { - //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) + if (interfaces[i].inf.ID == static_cast(ptr.get())->GetID()) { - if (interfaces[i].inf.ID == static_cast(ptr.get())->GetID()) - { - found_flag = true; - break; - } + found_flag = true; + break; } } + } - if (!found_flag) - { - WriteToLog("Erasing controller! ", (*it)->GetController()->GetType()); - controllerInterfaces.erase(it--); - WriteToLog("Controller erased!"); - } + if (!found_flag) + { + WriteToLog("Erasing controller! ", (*it)->GetController()->GetType()); + controllerInterfaces.erase(it--); + WriteToLog("Controller erased!"); } } } - - rc = waitSingle(filecheckTimerWaiter, 0); - if (R_SUCCEEDED(rc)) - { - if (CheckForFileChanges()) - { - WriteToLog("File check succeeded! Loading configs..."); - LoadAllConfigs(); - } - } - -#ifdef __APPLET__ - consoleUpdate(nullptr); -#else - svcSleepThread(1e+7L); -#endif } - //After we break out of the loop, close all events and exit - WriteToLog("Destroying events"); - usbHsDestroyInterfaceAvailableEvent(&ds3Event, 0); - usbHsDestroyInterfaceAvailableEvent(&catchAllEvent, 1); + rc = waitSingle(filecheckTimerWaiter, 0); + if (R_SUCCEEDED(rc)) + { + if (CheckForFileChanges()) + { + WriteToLog("File check succeeded! Loading configs..."); + LoadAllConfigs(); + } + } - //controllerInterfaces.clear(); - return rc; - } \ No newline at end of file +#ifdef __APPLET__ + consoleUpdate(nullptr); +#else + svcSleepThread(1e+7L); +#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; +} \ No newline at end of file