Exemplo n.º 1
0
 public void Stop(bool[] parSelectedPads, DeviceManagement devManLevel)
 {
     for (uint dsID = 1; dsID <= SCPConstants.MAX_XINPUT_DEVICES; dsID++)
     {
         if (parSelectedPads[dsID - 1])
         {
             uint id = GetvjFromDS(dsID);
             try
             {
                 if (vibrationCore != null)
                 {
                     vibrationCore.FfbStop(id);
                     vibrationCore = null;
                 }
                 joystick.RelinquishVJD(id);
             }
             catch
             {
                 //if this ever produces an error
             }
         }
     }
     if ((devManLevel & DeviceManagement.vJoy_Device) == DeviceManagement.vJoy_Device)
     {
         EnableVJoy(false);
     }
 }
Exemplo n.º 2
0
        public bool Start(bool[] parSelectedPads, PadSettings config, DeviceManagement devManLevel)
        {
            //Setup vJoy
            //Perform device enable/disable based on dll version
            //EnableVJoy needs to know which version of vJoy we are running
            joystick = new vJoy();
            UInt32 DllVer = 0, DrvVer = 0;
            joystick.DriverMatch(ref DllVer, ref DrvVer);
            //MIN Version Check 1
            vJoyVersion = DllVer;
            if (vJoyVersion < vJoyConstants.MIN_VER)
            {
                Trace.WriteLine("vJoy version less than required: Aborting\n");
                Stop(parSelectedPads, devManLevel);
                return false;
            }

            if ((devManLevel & DeviceManagement.vJoy_Config) == DeviceManagement.vJoy_Config)
            {
                EnableVJoy(false);
                SetupVjoy(parSelectedPads, config);
                vJoyInstall.RefreshvJoy(); //do it like vJConfig does (needed in 2.1.6)
                EnableVJoy(true);
            }
            else if ((devManLevel & DeviceManagement.vJoy_Device) == DeviceManagement.vJoy_Device)
            {
                EnableVJoy(true);
            }

            if (!joystick.vJoyEnabled())
            {
                Trace.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n");
                return false;
            }
            else
            {
                Trace.WriteLine(String.Format("Vendor : {0}\nProduct: {1}\nVersion: {2}\n",
                joystick.GetvJoyManufacturerString(),
                joystick.GetvJoyProductString(),
                joystick.GetvJoySerialNumberString()));

                // Test if DLL matches the driver
                bool match = joystick.DriverMatch(ref DllVer, ref DrvVer);
                if (match)
                {
                    Trace.WriteLine(String.Format("Version of Driver Matches DLL Version ({0:X})", DllVer));
                    Trace.WriteLine(String.Format("Version of vJoyInterfaceWrap.dll is ({0})",
                        typeof(vJoy).Assembly.GetName().Version));
                    Trace.WriteLine(String.Format("Version of ScpControl.dll is ({0})\n",
                        typeof(ScpControl.ScpProxy).Assembly.GetName().Version));
                }
                else
                {
                    Trace.WriteLine(String.Format("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})\n", DrvVer, DllVer));
                    Stop(parSelectedPads, devManLevel);
                    return false;
                }
                //MinVersion Check
                vJoyVersion = DrvVer;
                if (vJoyVersion < vJoyConstants.MIN_VER)
                {
                    Trace.WriteLine("vJoy version less than required: Aborting\n");
                    Stop(parSelectedPads, devManLevel);
                    return false;
                }
            }

            for (uint dsID = 1; dsID <= SCPConstants.MAX_XINPUT_DEVICES; dsID++)
            {
                if (parSelectedPads[dsID - 1])
                {
                    uint id = GetvjFromDS(dsID);

                    // Acquire the target
                    VjdStat status = joystick.GetVJDStatus(id);
                    if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id))))
                    {
                        Trace.WriteLine(String.Format("Failed to acquire vJoy device number {0}.", id));
                        Stop(parSelectedPads, devManLevel);
                        return false;
                    }
                    else
                    {
                        Trace.WriteLine(String.Format("Acquired vJoy device number {0}.", id));
                    }
                    Trace.WriteLine(String.Format("Buttons : {0}.", joystick.GetVJDButtonNumber(id)));
                    Trace.WriteLine(String.Format("DiscPov : {0}.", joystick.GetVJDDiscPovNumber(id)));
                    Trace.WriteLine(String.Format("ContPov : {0}.", joystick.GetVJDContPovNumber(id)));
                    //FFB
                    if (config.ffb)
                    {
                        vibrationCore = new vJoyVibrate(joystick);
                        vibrationCore.FfbInterface(dsID);
                        vibrationCore.VibrationCommand += VibEventProxy;
                    }
                    // Reset this device to default values
                    joystick.ResetVJD(id);
                    //Set Axis to mid value
                    joyReport[dsID - 1].AxisX = HALF_VJOY_AXIS;
                    joyReport[dsID - 1].AxisY = HALF_VJOY_AXIS;
                    joyReport[dsID - 1].AxisZ = HALF_VJOY_AXIS;
                    joyReport[dsID - 1].AxisXRot = HALF_VJOY_AXIS;
                    joyReport[dsID - 1].AxisYRot = HALF_VJOY_AXIS;
                    joyReport[dsID - 1].AxisZRot = HALF_VJOY_AXIS;
                    joyReport[dsID - 1].Slider = HALF_VJOY_AXIS;
                    joyReport[dsID - 1].Dial = HALF_VJOY_AXIS;
                }
            }
            return true;
        }