diff --git a/FreePIE.Core.Plugins/VJoyPlugin.cs b/FreePIE.Core.Plugins/VJoyPlugin.cs index 12c40485..18bfa67b 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 reacquire."); + + 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)