Beispiel #1
0
        public TesterForm()
        {
            InitializeComponent();
            joystick = new vGen();
            position = new vGen.JoystickState();


            /////	General driver data
            short  iVer    = joystick.GetvJoyVersion();
            bool   enabled = joystick.vJoyEnabled();
            string Prd     = joystick.GetvJoyProductString();
            string Mnf     = joystick.GetvJoyManufacturerString();
            string Srl     = joystick.GetvJoySerialNumberString();
            string prt     = String.Format("Product: {0}; Version {1:X}; Manuf: {2}; Serial:{3}", Prd, iVer, Mnf, Srl);

            label1.Text   = prt;
            Enbld.Checked = enabled;

            /////	vGen Device properties (vJoy Devices)
            int  nBtn     = joystick.GetVJDButtonNumber(id);
            int  nDPov    = joystick.GetVJDDiscPovNumber(id);
            int  nCPov    = joystick.GetVJDContPovNumber(id);
            bool X_Exist  = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X);
            bool Y_Exist  = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y);
            bool Z_Exist  = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z);
            bool RX_Exist = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX);

            prt         = String.Format("Device[{0}]: Buttons={1}; DiscPOVs:{2}; ContPOVs:{3}", id, nBtn, nDPov, nCPov);
            label2.Text = prt;

            UInt32 DllVer = 0, DrvVer = 0;
            bool   match = joystick.DriverMatch(ref DllVer, ref DrvVer);

            if (match)
            {
                prt = String.Format("Version of Driver Matches DLL Version {0:X}", DllVer);
            }
            else
            {
                prt = String.Format("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})", DrvVer, DllVer);
            }
            label7.Text = prt;

            // vXbox devices
            UInt32 UserIndex = 0;
            bool   Exist     = false;
            uint   stat      = joystick.isVBusExist();

            if (stat == 0)
            {
                System.Diagnostics.Debug.WriteLine("======== vXbox bus installed");
                Byte nSlots = 0;
                stat = joystick.GetNumEmptyBusSlots(ref nSlots);
                System.Diagnostics.Debug.WriteLine("======== Number of empty slots: " + nSlots.ToString());
                UserIndex = 2;
                stat      = joystick.PlugIn(UserIndex);
                if (stat == 0)
                {
                    System.Diagnostics.Debug.WriteLine("======== vXbox device 2 was plugged in");
                }
                joystick.isControllerPluggedIn(UserIndex, ref Exist);
                System.Diagnostics.Debug.WriteLine("======== vXbox device " + UserIndex.ToString() + " is plugged in: " + Exist.ToString());
                joystick.isControllerOwned(UserIndex, ref Exist);
                System.Diagnostics.Debug.WriteLine("======== vXbox device " + UserIndex.ToString() + " is owned: " + Exist.ToString());
                UserIndex = 1;
                joystick.isControllerPluggedIn(UserIndex, ref Exist);
                System.Diagnostics.Debug.WriteLine("======== vXbox device " + UserIndex.ToString() + " is plugged in: " + Exist.ToString());
                joystick.isControllerOwned(UserIndex, ref Exist);
                System.Diagnostics.Debug.WriteLine("======== vXbox device " + UserIndex.ToString() + " is owned: " + Exist.ToString());
                joystick.PlugInNext(ref UserIndex);
                joystick.isControllerPluggedIn(UserIndex, ref Exist);
                System.Diagnostics.Debug.WriteLine("======== vXbox device " + UserIndex.ToString() + " is plugged in: " + Exist.ToString());
                joystick.isControllerOwned(UserIndex, ref Exist);
                System.Diagnostics.Debug.WriteLine("======== vXbox device " + UserIndex.ToString() + " is owned: " + Exist.ToString());

                joystick.SetButton(UserIndex, 1, true);
                joystick.SetButton(UserIndex, 3, true);
                joystick.ResetAllControllers();
                joystick.SetButton(UserIndex, 1, false);
                joystick.SetButton(UserIndex, 3, false);

                joystick.SetTriggerL(UserIndex, 255);
                joystick.SetTriggerR(UserIndex, 128);
                joystick.SetAxisLx(UserIndex, -32768);
                joystick.SetAxisLy(UserIndex, 32767);
                joystick.SetAxisRx(UserIndex, -32000);
                joystick.SetAxisRy(UserIndex, 32000);
                joystick.SetDpad(UserIndex, vGen.XINPUT_GAMEPAD_DPAD_UP);
                joystick.SetDpad(UserIndex, 0);

                byte Led = 0xFF;
                vGen.XINPUT_VIBRATION Vib;
                Vib.wRightMotorSpeed = Vib.wLeftMotorSpeed = 0;
                joystick.GetLedNumber(UserIndex, ref Led);
                System.Diagnostics.Debug.WriteLine("======== vXbox device " + UserIndex.ToString() + ": Led=" + Led.ToString());

                int x = 0, L = 0, R = 0;
                while (x < 1000)
                {
                    x++;
                    stat = joystick.GetVibration(UserIndex, ref Vib);
                    if ((Vib.wLeftMotorSpeed != L) || (Vib.wRightMotorSpeed != R))
                    {
                        System.Diagnostics.Debug.WriteLine("======== vXbox device " + UserIndex.ToString() + ": Vibration (L/R)=" + Vib.wLeftMotorSpeed.ToString() + "/" + Vib.wRightMotorSpeed.ToString());
                    }
                    System.Threading.Thread.Sleep(10);
                }


                //joystick.UnPlug(2);
            }

            // Testing
            long max = 10, min = 10;
            bool ok;

            ok = joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref max);
            ok = joystick.GetVJDAxisMin(id, HID_USAGES.HID_USAGE_X, ref min);

            /////	Write access to vGen Device - Basic
            VjdStat status;

            status = joystick.GetVJDStatus(id);
            bool acq = joystick.AcquireVJD(id);

            status = joystick.GetVJDStatus(id);

            position.AxisX      = 1000;
            position.AxisY      = 5000;
            position.AxisZ      = 10000;
            position.AxisXRot   = 20000;
            position.Buttons    = 0xA5A5A5A5;
            position.ButtonsEx1 = 0;
            bool upd = joystick.UpdateVJD(id, ref position);

            status = joystick.GetVJDStatus(id);

            //// Reset functions
            joystick.ResetButtons(id);

            // Register callback function
            // Function to register:     Removal()
            // User data to pass:        label2
            joystick.RegisterRemovalCB(Removal, label2);
        }