-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update ControllerManager.cs #872
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,7 @@ static ControllerManager() | |
watchdogThread.IsBackground = true; | ||
} | ||
|
||
public static void Start() | ||
public static Task Start() | ||
{ | ||
// Flushing possible JoyShocks... | ||
JslDisconnectAndDisposeAll(); | ||
|
@@ -94,6 +94,8 @@ public static void Start() | |
ControllerSelected?.Invoke(GetEmulatedController()); | ||
|
||
LogManager.LogInformation("{0} has started", "ControllerManager"); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public static void Stop() | ||
|
@@ -328,6 +330,8 @@ private static async void HidDeviceArrived(PnPDetails details, DeviceEventArgs o | |
|
||
// JoyShockLibrary | ||
int connectedJoys = -1; | ||
int joyShockId = -1; | ||
JOY_SETTINGS settings = new(); | ||
|
||
DateTime timeout = DateTime.Now.Add(TimeSpan.FromSeconds(4)); | ||
while (DateTime.Now < timeout && connectedJoys == -1) | ||
|
@@ -343,15 +347,12 @@ private static async void HidDeviceArrived(PnPDetails details, DeviceEventArgs o | |
} | ||
} | ||
|
||
if (connectedJoys >= 0) | ||
if (connectedJoys > 0) | ||
{ | ||
int[] joysHandle = new int[connectedJoys]; | ||
JslGetConnectedDeviceHandles(joysHandle, connectedJoys); | ||
|
||
// scroll handles until we find matching device path | ||
int joyShockId = -1; | ||
JOY_SETTINGS settings = new(); | ||
|
||
foreach (int i in joysHandle) | ||
{ | ||
settings = JslGetControllerInfoAndSettings(i); | ||
Comment on lines
347
to
358
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The check |
||
|
@@ -365,51 +366,45 @@ private static async void HidDeviceArrived(PnPDetails details, DeviceEventArgs o | |
break; | ||
} | ||
} | ||
} | ||
|
||
// device found | ||
if (joyShockId != -1) | ||
{ | ||
// use handle | ||
settings.playerNumber = joyShockId; | ||
// device found | ||
if (joyShockId != -1) | ||
{ | ||
// use handle | ||
settings.playerNumber = joyShockId; | ||
|
||
JOY_TYPE joyShockType = (JOY_TYPE)JslGetControllerType(joyShockId); | ||
JOY_TYPE joyShockType = (JOY_TYPE)JslGetControllerType(joyShockId); | ||
|
||
if (controller is not null) | ||
{ | ||
((JSController)controller).AttachDetails(details); | ||
((JSController)controller).AttachJoySettings(settings); | ||
if (controller is not null) | ||
{ | ||
((JSController)controller).AttachDetails(details); | ||
((JSController)controller).AttachJoySettings(settings); | ||
|
||
// hide new InstanceID (HID) | ||
if (controller.IsHidden()) | ||
controller.Hide(false); | ||
// hide new InstanceID (HID) | ||
if (controller.IsHidden()) | ||
controller.Hide(false); | ||
|
||
IsPowerCycling = true; | ||
} | ||
else | ||
{ | ||
// UI thread (sync) | ||
Application.Current.Dispatcher.Invoke(() => | ||
{ | ||
switch (joyShockType) | ||
{ | ||
case JOY_TYPE.DualSense: | ||
controller = new DualSenseController(settings, details); | ||
break; | ||
case JOY_TYPE.DualShock4: | ||
controller = new DS4Controller(settings, details); | ||
break; | ||
case JOY_TYPE.ProController: | ||
controller = new ProController(settings, details); | ||
break; | ||
} | ||
}); | ||
} | ||
IsPowerCycling = true; | ||
} | ||
else | ||
{ | ||
// unsupported controller | ||
LogManager.LogError("Couldn't find matching JoyShock controller: VID:{0} and PID:{1}", | ||
details.GetVendorID(), details.GetProductID()); | ||
// UI thread (sync) | ||
Application.Current.Dispatcher.Invoke(() => | ||
{ | ||
switch (joyShockType) | ||
{ | ||
case JOY_TYPE.DualSense: | ||
controller = new DualSenseController(settings, details); | ||
break; | ||
case JOY_TYPE.DualShock4: | ||
controller = new DS4Controller(settings, details); | ||
break; | ||
case JOY_TYPE.ProController: | ||
controller = new ProController(settings, details); | ||
break; | ||
} | ||
}); | ||
} | ||
} | ||
else | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialization of
connectedJoys
to-1
and the subsequent loop to connect devices may result in an infinite loop ifJslConnectDevices()
throws an exception that is not caught. Ensure that exceptions are handled properly to avoid an infinite loop.