mirror of
https://github.com/ayufan/steam-deck-tools.git
synced 2026-03-17 10:14:46 +01:00
Improve exception handling for SteamController
This commit is contained in:
parent
9f1288cfb0
commit
12b92ab151
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue