private void vJoyXboxSetup()
 {
     joystick = new vGen();
     iReport  = new vGen.JoystickState();
     stat     = joystick.isVBusExist();
     if (stat == 0)
     {
         stat = joystick.PlugIn(1);
         if (stat == 0)
         {
             consoleOut("vXbox device 1 was plugged in.");
             if (!xboxMapped && isLan == 0)
             {
                 xboxKeyMapper();
             }
         }
         else
         {
             consoleOut("Couldn't plugin vXbox Controller, but driver exists.");
             checkBox2.Checked = false;
         }
     }
     else
     {
         consoleOut("Virtual Xbox Driver not installed.");
         checkBox2.Checked = false;
         checkBox2.Enabled = false;
     }
 }
示例#2
0
文件: TesterForm.cs 项目: evilC/vGen
        public FfbInterface(TesterForm dialog)
        {
            dlg      = dialog;
            joystick = dialog.joystick;
            // FFB
#if false
#pragma warning disable 0618
            if (!joystick.FfbStart(id))
            {
                throw new Exception(String.Format("Failed to start Forcefeedback on device {0}", id));
            }
#pragma warning restore 0618

            // Convert Form to pointer and pass it as user data to the callback function
            GCHandle h         = GCHandle.Alloc(dialog);
            IntPtr   parameter = (IntPtr)h;
            // joystick.FfbRegisterGenCB(OnEffect, parameter);
            joystick.FfbRegisterGenCB(OnEffectObj, dialog);
 #endif
        }
示例#3
0
文件: Program.cs 项目: evilC/vGen
        static void Main(string[] args)
        {
            Char    last_c = '\0';
            uint    id     = 0;
            string  line;
            DevType type = DevType.vJoy;
            int     hDev = 0;

            joystick = new vGen();

            // Print device' status
            dev_stat();

            // Get type of device
            Console.WriteLine("\n\nvJoy or vXbox [J/X]?");
            ConsoleKeyInfo key = Console.ReadKey();

            last_c = Char.ToUpper(key.KeyChar);
            if (last_c == 'X')
            {
                type = DevType.vXbox;
            }

            //get device ID
            Console.WriteLine("\n\nDevice ID [1-16]?");
            line = Console.ReadLine();
            if (line.Length == 0)
            {
                Console.WriteLine("\n\nDevice ID <empty>, exiting?");
                return;
            }
            id = Convert.ToUInt32(line);

            // Verify ID
            if (id < 1)
            {
                Console.WriteLine("\n\nDevice ID negative, exiting?");
                return;
            }
            if ((type == DevType.vXbox) && (id > 4))
            {
                Console.WriteLine("\n\nDevice ID is greater than 4, exiting?");
                return;
            }
            if ((type == DevType.vJoy) && (id > 16))
            {
                Console.WriteLine("\n\nDevice ID is greater than 16, exiting?");
                return;
            }

            // Acquire Device and verify
            joystick.AcquireDev(id, type, ref hDev);
            dev_stat();

            Console.WriteLine("\nHit any key to reliquish device");
            Console.ReadKey();
            joystick.RelinquishDev(hDev);
            dev_stat();

            Console.WriteLine("\nHit any key to re-acquire device");
            Console.ReadKey();
            joystick.AcquireDev(id, type, ref hDev);
            dev_stat();

            joystick.GetDevType(hDev, ref type);
            Console.WriteLine("\nDevice type: " + type.ToString());

            dev_axes(hDev);

            uint nBtn = 0;

            joystick.GetDevButtonN(hDev, ref nBtn);
            Console.WriteLine("\nNumber of buttons: " + nBtn.ToString());

            uint nHat = 0;

            joystick.GetDevHatN(hDev, ref nHat);
            Console.WriteLine("\nNumber of Hats: " + nHat.ToString());

            bool go_on = true;

            do
            {
                go_on = SetVal(hDev);
            } while (go_on);

            Console.WriteLine("\nHit any key to exit");
            Console.ReadKey();
        }
示例#4
0
        private void button1_Click(object sender, EventArgs e)
        {
            joystick = new vGen();
            insim    = new InSim();

            insim.Initialized += (o, ec) =>
            {
                insim.Send(new IS_BTN()
                {
                    ReqI    = 5,
                    L       = 40,
                    T       = 20,
                    H       = 5,
                    W       = 40,
                    BStyle  = ButtonStyles.ISB_CLICK,
                    ClickID = 66,
                    Text    = "Control mode: 0",
                    UCID    = 0
                });

                foreach (var p in paths.paths)
                {
                    MSL("^3Path: ^7" + p.Name);
                }
                DrawClickables();
            };

            insim.Bind(PacketType.ISP_BTC, (ins, bb) =>
            {
                var bt = (IS_BTC)bb;
                if (bt.ClickID == 66)
                {
                    control = (control + 1) % 2;
                }
                else if (bt.ClickID == 67)
                {
                    initPhase = true;
                }
                else if (bt.ClickID >= PATH_CLICKID)
                {
                    var p       = paths.paths[bt.ClickID - PATH_CLICKID];
                    currentPath = p.Waypoints;
                    MSL("^7Selected path: ^3" + p.Name);
                    initPhase = true;
                }


                DrawClickables();
            });

            insim.Bind(PacketType.ISP_BTT, (ins, bb) =>
            {
                var bt = (IS_BTT)bb;

                if (bt.ClickID == 67)
                {
                    speedmod = int.Parse(bt.Text);
                    MSL("^3Speedmod set to ^7" + speedmod + "%");
                }

                DrawClickables();
            });

            insim.Initialize(new InSimSettings()
            {
                IName    = "^7Afto^1Piliet",
                Host     = "127.0.0.1",
                Port     = 29997,
                Interval = 100,
                Prefix   = '!',
                Flags    = InSimFlags.ISF_LOCAL
            });

            outsim           = new OutSim(10000);
            outsim.TimedOut += (a, b) => { insim.Send(new InSimDotNet.Packets.IS_MSL()
                {
                    Msg = "TimeOut..", ReqI = 10, Sound = MessageSound.SND_MESSAGE
                }); };
            outsim.PacketReceived += Outsim_PacketReceived;

            outsim.Connect("127.0.0.1", 30000);



            joystick.AcquireDev(1, DevType.vJoy, ref hDev);
            //joystick.SetDevAxis(hDev, 1, (float)100.0);
            //timer = new System.Timers.Timer(100);
            //timer.Elapsed += (o, ee) => {
            //    //joystick.SetDevAxis(hDev, 1, (float)DateTime.Now.Millisecond*0.1f);
            //    var cpos = Cursor.Position;

            //    joystick.SetDevAxis(hDev, 1, cpos.X / 19.2f);
            //    joystick.SetDevAxis(hDev, 2, cpos.Y / 10.8f);
            //};
            //timer.Start();
        }
示例#5
0
文件: TesterForm.cs 项目: evilC/vGen
        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);
        }
        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);
        }