示例#1
0
文件: TesterForm.cs 项目: evilC/vGen
        // Demo callback function
        // Called with every FFB packet that is sent to a vGen device
        // Must be registered using function FfbRegisterGenCB()

        private void TesterForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            VjdStat status;

            // Don't use (Too slow) -  joystick.ResetAll();
            joystick.ResetVJD(id);
            status = joystick.GetVJDStatus(id);
            joystick.RelinquishVJD(id);
            status = joystick.GetVJDStatus(id);
        }
        private bool vJoySetup()
        {
            joystick = new vGen();
            iReport  = new vGen.JoystickState();
            if (id <= 0 || id > 16)
            {
                consoleOut("Illegal device ID " + id + "!");
            }
            if (!joystick.vJoyEnabled())
            {
                consoleOut("vJoy driver not enabled: Failed Getting vJoy attributes.");
                return(false);
            }
            else
            {
                consoleOut("Vendor: " + joystick.GetvJoyManufacturerString() + "\nProduct: " + joystick.GetvJoyProductString() + "\nVersion Number: " + joystick.GetvJoySerialNumberString() + ".");
            }
            VjdStat st = joystick.GetVJDStatus(id);

            switch (st)
            {
            case VjdStat.VJD_STAT_OWN:
                consoleOut("vJoy Device " + id + " is already owned by this feeder.");
                break;

            case VjdStat.VJD_STAT_FREE:
                consoleOut("vJoy Device " + id + " is free.");
                break;

            case VjdStat.VJD_STAT_BUSY:
                joystick.RelinquishVJD(id);
                consoleOut("vJoy Device " + id + " is already owned by another feeder - Trying to recover.");
                return(false);

            case VjdStat.VJD_STAT_MISS:
                consoleOut("vJoy Device " + id + " is not installed or disabled - Cannot continue.");
                return(false);

            default:
                consoleOut("vJoy Device " + id + " general error - Cannot continue.");
                return(false);
            }
            ;

            st = joystick.GetVJDStatus(id);

            if ((st == VjdStat.VJD_STAT_OWN) || ((st == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id))))
            {
                consoleOut("Failed to acquire vJoy device number " + id + ".");
            }
            else
            {
                consoleOut("Acquired vJoy device number " + id + ".");
            }
            int    nButtons = joystick.GetVJDButtonNumber(id);
            UInt32 DllVer = 0, DrvVer = 0;
            bool   match = joystick.DriverMatch(ref DllVer, ref DrvVer);

            if (match)
            {
                consoleOut("Version of Driver Matches DLL Version (" + DllVer + ")");
            }
            else
            {
                consoleOut("Version of Driver (" + DrvVer + ") does NOT match DLL Version (" + DllVer + ")");
            }
            joystick.ResetVJD(id);
            for (uint i = 1; i <= nButtons; i++)
            {
                consoleOut(i + ") OFF: " + joystick.SetBtn(false, id, i));
            }
            consoleOut("\nvJoy setup completed succesfully!\n");
            return(true);
        }