Recreate X360 device on fatal failure (might happen after resume)

This commit is contained in:
Kamil Trzciński 2022-12-10 10:36:00 +01:00
parent fdb94c42ed
commit 8ff22739c5
2 changed files with 35 additions and 4 deletions

View file

@ -19,3 +19,4 @@
- Allow to assign BackPanel keys to X360 controller (breaks all current configs to set mappings)
- All SteamDeckTools settings are stored in `.ini` file in root folder
- Detect SAS (Secure Attention Sequence) in a way that does not prevent screen sleep
- Recreate X360 device on fatal failure (might happen after resume)

View file

@ -66,6 +66,18 @@ namespace SteamController.Devices
}
}
private void Fail()
{
var client = this.client;
// unset current device
this.client = null;
this.device = null;
try { using (client) { } }
catch (Exception) { }
}
internal void BeforeUpdate()
{
device?.ResetReport();
@ -89,13 +101,31 @@ namespace SteamController.Devices
if (wantsConnected)
{
device?.Connect();
TraceLine("Connected X360 Controller.");
try
{
device?.Connect();
TraceLine("Connected X360 Controller.");
}
catch (Exception e)
{
TraceLine("X360: Connect: {0}", e);
Fail();
return;
}
}
else
{
device?.Disconnect();
TraceLine("Disconnected X360 Controller.");
try
{
device?.Disconnect();
TraceLine("Disconnected X360 Controller.");
}
catch (Exception e)
{
TraceLine("X360: Disconnect: {0}", e);
Fail();
return;
}
}
isConnected = wantsConnected;