Пример #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);
     }
 }
Пример #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    = vJoyConstants.HALF_AXIS_VALUE;
                    joyReport[dsID - 1].AxisY    = vJoyConstants.HALF_AXIS_VALUE;
                    joyReport[dsID - 1].AxisZ    = vJoyConstants.HALF_AXIS_VALUE;
                    joyReport[dsID - 1].AxisXRot = vJoyConstants.HALF_AXIS_VALUE;
                    joyReport[dsID - 1].AxisYRot = vJoyConstants.HALF_AXIS_VALUE;
                    joyReport[dsID - 1].AxisZRot = vJoyConstants.HALF_AXIS_VALUE;
                    joyReport[dsID - 1].Slider   = vJoyConstants.HALF_AXIS_VALUE;
                    joyReport[dsID - 1].Dial     = vJoyConstants.HALF_AXIS_VALUE;
                }
            }
            return(true);
        }