diff --git a/SteamController/Devices/SteamController.cs b/SteamController/Devices/SteamController.cs index 87bf188..89e82ef 100644 --- a/SteamController/Devices/SteamController.cs +++ b/SteamController/Devices/SteamController.cs @@ -46,14 +46,14 @@ namespace SteamController.Devices neptuneDevice.OpenDevice(); } - internal void Fail() + internal void Fail(bool immediately = false) { foreach (var action in AllActions) action.Reset(); // Try to re-open every MaxFailures failures++; - if (failures % MaxFailures == 0) + if (failures % MaxFailures == 0 || immediately) { OpenDevice(); failures = 0; @@ -89,6 +89,12 @@ namespace SteamController.Devices BeforeUpdate(data); Updated = true; } + catch (hidapi.HidDeviceInvalidException) + { + // Steam might disconnect device + Fail(); + Updated = false; + } catch (Exception e) { TraceException("STEAM", "BeforeUpdate", e); @@ -107,6 +113,11 @@ namespace SteamController.Devices UpdateLizardButtons(); UpdateLizardMouse(); } + catch (hidapi.HidDeviceInvalidException) + { + // Steam might disconnect device + Fail(); + } catch (Exception e) { TraceException("STEAM", "Update", e); diff --git a/SteamController/Devices/SteamControllerHaptic.cs b/SteamController/Devices/SteamControllerHaptic.cs index 5c94a98..64d4e1c 100644 --- a/SteamController/Devices/SteamControllerHaptic.cs +++ b/SteamController/Devices/SteamControllerHaptic.cs @@ -108,6 +108,12 @@ namespace SteamController.Devices hapticTasks[position] = neptuneDevice.RequestFeatureReportAsync(bytes); return true; } + catch (hidapi.HidDeviceInvalidException) + { + // Steam might disconnect device + Fail(); + return false; + } catch (Exception e) { TraceException("STEAM", "Haptic", e);