diff --git a/RELEASE.md b/RELEASE.md index c3b574b..7a875de 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -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) diff --git a/SteamController/Devices/Xbox360Controller.cs b/SteamController/Devices/Xbox360Controller.cs index 774bb32..252702f 100644 --- a/SteamController/Devices/Xbox360Controller.cs +++ b/SteamController/Devices/Xbox360Controller.cs @@ -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;