From 9b0500f1a9cdabf3d10cb8aff8ab4791deb0adec Mon Sep 17 00:00:00 2001 From: laqqah <621386+laqqah@users.noreply.github.com> Date: Sun, 14 Oct 2018 01:06:15 +0200 Subject: [PATCH 1/2] Fix reconnect on lost connection to vJoy driver --- FreePIE.Core.Plugins/VJoyPlugin.cs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/FreePIE.Core.Plugins/VJoyPlugin.cs b/FreePIE.Core.Plugins/VJoyPlugin.cs index 12c40485..44f1ba87 100644 --- a/FreePIE.Core.Plugins/VJoyPlugin.cs +++ b/FreePIE.Core.Plugins/VJoyPlugin.cs @@ -47,6 +47,7 @@ private VJoyGlobal Create(uint index) public override void DoBeforeNextExecute() { + holders.ForEach(h => h.CheckAlive()); holders.ForEach(h => h.SendPressed()); } @@ -130,6 +131,35 @@ public VJoyGlobalHolder(uint index) joystick.ResetVJD(index); } + public void CheckAlive() + { + var status = joystick.GetVJDStatus(Index); + if (status != VjdStat.VJD_STAT_OWN) + { + System.Console.WriteLine("No longer own the vjoy device... attempting to reaquire"); + + string error = null; + switch (status) + { + case VjdStat.VJD_STAT_BUSY: + error = "vJoy Device {0} is already owned by another feeder"; + break; + case VjdStat.VJD_STAT_MISS: + error = "vJoy Device {0} is not installed or disabled"; + break; + case VjdStat.VJD_STAT_UNKN: + error = ("vJoy Device {0} general error"); + break; + } + + if (error == null && !joystick.AcquireVJD(Index)) + error = "Failed to acquire vJoy device number {0}"; + + if (error != null) + throw new Exception(string.Format(error, Index)); + } + } + public void SetButton(int button, bool pressed) { if(button >= maxButtons) From 5e3f4c17a4838afd437f4132fe772f1dc6d2ba34 Mon Sep 17 00:00:00 2001 From: laqqah <621386+laqqah@users.noreply.github.com> Date: Sun, 14 Oct 2018 16:10:14 +0200 Subject: [PATCH 2/2] Change message when attempting reconnect to vJoy device --- FreePIE.Core.Plugins/VJoyPlugin.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FreePIE.Core.Plugins/VJoyPlugin.cs b/FreePIE.Core.Plugins/VJoyPlugin.cs index 44f1ba87..18bfa67b 100644 --- a/FreePIE.Core.Plugins/VJoyPlugin.cs +++ b/FreePIE.Core.Plugins/VJoyPlugin.cs @@ -136,7 +136,7 @@ public void CheckAlive() var status = joystick.GetVJDStatus(Index); if (status != VjdStat.VJD_STAT_OWN) { - System.Console.WriteLine("No longer own the vjoy device... attempting to reaquire"); + System.Console.WriteLine("No longer own the vjoy device. Attempting to reacquire."); string error = null; switch (status)