Example #1
0
        public void SetContinuousPov(int pov, int value)
        {
            if (pov >= maxContinuousPov)
            {
                throw new Exception(string.Format("Maximum analog POV sticks are {0}. You need to increase number of analog POV hats in vJoy config", maxContinuousPov));
            }

            joystick.SetContPov(value, Index, (uint)pov + 1);
        }
Example #2
0
 public void SetButtonState(uint id, string button, int value)
 {
     if (button.Contains("Buttons"))
     {
         vjoy.SetBtn(value > 0, id, (uint)RLocalInput.MapButtonToId[button] + 1);
     }
     else if (button.Contains("PointOfViewControllers"))
     {
         vjoy.SetContPov(value, id, 1);
     }
     else
     {
         var axis = MapButtonToAxis[button];
         vjoy.SetAxis(value / 2, id, axis);
     }
 }
        static void Main(string[] args)
        {
            // Create one joystick object and a position structure.
            joystick = new vJoy();
            iReport  = new vJoy.JoystickState();


            // Device ID can only be in the range 1-16
            if (args.Length > 0 && !String.IsNullOrEmpty(args[0]))
            {
                id = Convert.ToUInt32(args[0]);
            }
            if (id <= 0 || id > 16)
            {
                Console.WriteLine("Illegal device ID {0}\nExit!", id);
                return;
            }

            // Get the driver attributes (Vendor ID, Product ID, Version Number)
            if (!joystick.vJoyEnabled())
            {
                Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n");
                return;
            }
            else
            {
                Console.WriteLine("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", joystick.GetvJoyManufacturerString(), joystick.GetvJoyProductString(), joystick.GetvJoySerialNumberString());
            }

            // Get the state of the requested device
            VjdStat status = joystick.GetVJDStatus(id);

            switch (status)
            {
            case VjdStat.VJD_STAT_OWN:
                Console.WriteLine("vJoy Device {0} is already owned by this feeder\n", id);
                break;

            case VjdStat.VJD_STAT_FREE:
                Console.WriteLine("vJoy Device {0} is free\n", id);
                break;

            case VjdStat.VJD_STAT_BUSY:
                Console.WriteLine("vJoy Device {0} is already owned by another feeder\nCannot continue\n", id);
                return;

            case VjdStat.VJD_STAT_MISS:
                Console.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue\n", id);
                return;

            default:
                Console.WriteLine("vJoy Device {0} general error\nCannot continue\n", id);
                return;
            }
            ;

            // Check which axes are supported
            bool AxisX  = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X);
            bool AxisY  = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y);
            bool AxisZ  = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z);
            bool AxisRX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX);
            bool AxisRZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RZ);
            // Get the number of buttons and POV Hat switchessupported by this vJoy device
            int nButtons      = joystick.GetVJDButtonNumber(id);
            int ContPovNumber = joystick.GetVJDContPovNumber(id);
            int DiscPovNumber = joystick.GetVJDDiscPovNumber(id);

            // Print results
            Console.WriteLine("\nvJoy Device {0} capabilities:\n", id);
            Console.WriteLine("Numner of buttons\t\t{0}\n", nButtons);
            Console.WriteLine("Numner of Continuous POVs\t{0}\n", ContPovNumber);
            Console.WriteLine("Numner of Descrete POVs\t\t{0}\n", DiscPovNumber);
            Console.WriteLine("Axis X\t\t{0}\n", AxisX ? "Yes" : "No");
            Console.WriteLine("Axis Y\t\t{0}\n", AxisX ? "Yes" : "No");
            Console.WriteLine("Axis Z\t\t{0}\n", AxisX ? "Yes" : "No");
            Console.WriteLine("Axis Rx\t\t{0}\n", AxisRX ? "Yes" : "No");
            Console.WriteLine("Axis Rz\t\t{0}\n", AxisRZ ? "Yes" : "No");

            // Acquire the target
            if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id))))
            {
                Console.WriteLine("Failed to acquire vJoy device number {0}.\n", id);
                return;
            }
            else
            {
                Console.WriteLine("Acquired: vJoy device number {0}.\n", id);
            }

            Console.WriteLine("\npress enter to stat feeding");
            Console.ReadKey(true);

            int  X, Y, Z, ZR, XR;
            uint count  = 0;
            long maxval = 0;

            X  = 20;
            Y  = 30;
            Z  = 40;
            XR = 60;
            ZR = 80;

            joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval);

#if ROBUST
            bool res;
            // Reset this device to default values
            joystick.ResetVJD(id);

            // Feed the device in endless loop
            while (true)
            {
                // Set position of 4 axes
                res = joystick.SetAxis(X, id, HID_USAGES.HID_USAGE_X);
                res = joystick.SetAxis(Y, id, HID_USAGES.HID_USAGE_Y);
                res = joystick.SetAxis(Z, id, HID_USAGES.HID_USAGE_Z);
                res = joystick.SetAxis(XR, id, HID_USAGES.HID_USAGE_RX);
                res = joystick.SetAxis(ZR, id, HID_USAGES.HID_USAGE_RZ);

                // Press/Release Buttons
                res = joystick.SetBtn(true, id, count / 50);
                res = joystick.SetBtn(false, id, 1 + count / 50);

                // If Continuous POV hat switches installed - make them go round
                // For high values - put the switches in neutral state
                if (ContPovNumber > 0)
                {
                    if ((count * 70) < 30000)
                    {
                        res = joystick.SetContPov(((int)count * 70), id, 1);
                        res = joystick.SetContPov(((int)count * 70) + 2000, id, 2);
                        res = joystick.SetContPov(((int)count * 70) + 4000, id, 3);
                        res = joystick.SetContPov(((int)count * 70) + 6000, id, 4);
                    }
                    else
                    {
                        res = joystick.SetContPov(-1, id, 1);
                        res = joystick.SetContPov(-1, id, 2);
                        res = joystick.SetContPov(-1, id, 3);
                        res = joystick.SetContPov(-1, id, 4);
                    };
                }
                ;

                // If Discrete POV hat switches installed - make them go round
                // From time to time - put the switches in neutral state
                if (DiscPovNumber > 0)
                {
                    if (count < 550)
                    {
                        joystick.SetDiscPov((((int)count / 20) + 0) % 4, id, 1);
                        joystick.SetDiscPov((((int)count / 20) + 1) % 4, id, 2);
                        joystick.SetDiscPov((((int)count / 20) + 2) % 4, id, 3);
                        joystick.SetDiscPov((((int)count / 20) + 3) % 4, id, 4);
                    }
                    else
                    {
                        joystick.SetDiscPov(-1, id, 1);
                        joystick.SetDiscPov(-1, id, 2);
                        joystick.SetDiscPov(-1, id, 3);
                        joystick.SetDiscPov(-1, id, 4);
                    };
                }
                ;

                System.Threading.Thread.Sleep(20);
                X += 150; if (X > maxval)
                {
                    X = 0;
                }
                Y += 250; if (Y > maxval)
                {
                    Y = 0;
                }
                Z += 350; if (Z > maxval)
                {
                    Z = 0;
                }
                XR += 220; if (XR > maxval)
                {
                    XR = 0;
                }
                ZR += 200; if (ZR > maxval)
                {
                    ZR = 0;
                }
                count++;

                if (count > 640)
                {
                    count = 0;
                }
            } // While (Robust)
#endif // ROBUST
#if EFFICIENT
            byte[] pov = new byte[4];

            while (true)
            {
                iReport.bDevice  = (byte)id;
                iReport.AxisX    = X;
                iReport.AxisY    = Y;
                iReport.AxisZ    = Z;
                iReport.AxisZRot = ZR;
                iReport.AxisXRot = XR;

                // Set buttons one by one
                iReport.Buttons = (uint)(0x1 << (int)(count / 20));

                if (ContPovNumber > 0)
                {
                    // Make Continuous POV Hat spin
                    iReport.bHats    = (count * 70);
                    iReport.bHatsEx1 = (count * 70) + 3000;
                    iReport.bHatsEx2 = (count * 70) + 5000;
                    iReport.bHatsEx3 = 15000 - (count * 70);
                    if ((count * 70) > 36000)
                    {
                        iReport.bHats    = 0xFFFFFFFF; // Neutral state
                        iReport.bHatsEx1 = 0xFFFFFFFF; // Neutral state
                        iReport.bHatsEx2 = 0xFFFFFFFF; // Neutral state
                        iReport.bHatsEx3 = 0xFFFFFFFF; // Neutral state
                    }
                    ;
                }
                else
                {
                    // Make 5-position POV Hat spin

                    pov[0] = (byte)(((count / 20) + 0) % 4);
                    pov[1] = (byte)(((count / 20) + 1) % 4);
                    pov[2] = (byte)(((count / 20) + 2) % 4);
                    pov[3] = (byte)(((count / 20) + 3) % 4);

                    iReport.bHats = (uint)(pov[3] << 12) | (uint)(pov[2] << 8) | (uint)(pov[1] << 4) | (uint)pov[0];
                    if ((count) > 550)
                    {
                        iReport.bHats = 0xFFFFFFFF;         // Neutral state
                    }
                };

                /*** Feed the driver with the position packet - is fails then wait for input then try to re-acquire device ***/
                if (!joystick.UpdateVJD(id, ref iReport))
                {
                    Console.WriteLine("Feeding vJoy device number {0} failed - try to enable device then press enter\n", id);
                    Console.ReadKey(true);
                    joystick.AcquireVJD(id);
                }

                System.Threading.Thread.Sleep(20);
                count++;
                if (count > 640)
                {
                    count = 0;
                }

                X += 150; if (X > maxval)
                {
                    X = 0;
                }
                Y += 250; if (Y > maxval)
                {
                    Y = 0;
                }
                Z += 350; if (Z > maxval)
                {
                    Z = 0;
                }
                XR += 220; if (XR > maxval)
                {
                    XR = 0;
                }
                ZR += 200; if (ZR > maxval)
                {
                    ZR = 0;
                }
            }
            ; // While
#endif // EFFICIENT
        } // Main
Example #4
0
        } // Main

        public static IEnumerator TestCoroutine()
        {
            int ContPovNumber = joystick.GetVJDContPovNumber(id);
            int DiscPovNumber = joystick.GetVJDDiscPovNumber(id);

            int  X, Y, Z, ZR, XR;
            uint count  = 0;
            long maxval = 0;

            X  = 20;
            Y  = 30;
            Z  = 40;
            XR = 60;
            ZR = 80;

            joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval);

            bool res;

            // Reset this device to default values
            joystick.ResetVJD(id);
            // Feed the device in endless loop

            Debug.Log("start");

            while (true)
            {
                // Set position of 4 axes
                res = joystick.SetAxis(X, id, HID_USAGES.HID_USAGE_X);
                res = joystick.SetAxis(Y, id, HID_USAGES.HID_USAGE_Y);
                res = joystick.SetAxis(Z, id, HID_USAGES.HID_USAGE_Z);
                res = joystick.SetAxis(XR, id, HID_USAGES.HID_USAGE_RX);
                res = joystick.SetAxis(ZR, id, HID_USAGES.HID_USAGE_RZ);

                // Press/Release Buttons
                res = joystick.SetBtn(true, id, count / 50);
                res = joystick.SetBtn(false, id, 1 + count / 50);

                // If Continuous POV hat switches installed - make them go round
                // For high values - put the switches in neutral state
                if (ContPovNumber > 0)
                {
                    if ((count * 70) < 30000)
                    {
                        res = joystick.SetContPov(((int)count * 70), id, 1);
                        res = joystick.SetContPov(((int)count * 70) + 2000, id, 2);
                        res = joystick.SetContPov(((int)count * 70) + 4000, id, 3);
                        res = joystick.SetContPov(((int)count * 70) + 6000, id, 4);
                    }
                    else
                    {
                        res = joystick.SetContPov(-1, id, 1);
                        res = joystick.SetContPov(-1, id, 2);
                        res = joystick.SetContPov(-1, id, 3);
                        res = joystick.SetContPov(-1, id, 4);
                    };
                }
                ;

                // If Discrete POV hat switches installed - make them go round
                // From time to time - put the switches in neutral state
                if (DiscPovNumber > 0)
                {
                    if (count < 550)
                    {
                        joystick.SetDiscPov((((int)count / 20) + 0) % 4, id, 1);
                        joystick.SetDiscPov((((int)count / 20) + 1) % 4, id, 2);
                        joystick.SetDiscPov((((int)count / 20) + 2) % 4, id, 3);
                        joystick.SetDiscPov((((int)count / 20) + 3) % 4, id, 4);
                    }
                    else
                    {
                        joystick.SetDiscPov(-1, id, 1);
                        joystick.SetDiscPov(-1, id, 2);
                        joystick.SetDiscPov(-1, id, 3);
                        joystick.SetDiscPov(-1, id, 4);
                    };
                }
                ;

                System.Threading.Thread.Sleep(20);
                X += 150; if (X > maxval)
                {
                    X = 0;
                }
                Y += 250; if (Y > maxval)
                {
                    Y = 0;
                }
                Z += 350; if (Z > maxval)
                {
                    Z = 0;
                }
                XR += 220; if (XR > maxval)
                {
                    XR = 0;
                }
                ZR += 200; if (ZR > maxval)
                {
                    ZR = 0;
                }
                count++;

                if (count > 640)
                {
                    count = 0;
                }
                yield return(new WaitForFixedUpdate());
            } // While (Robust)
        }
Example #5
0
        public static void Initialize(uint id)  //(string[] args)
        {
            // Create one joystick object and a position structure.
            joystick = new vJoy();
            iReport  = new vJoy.JoystickState();

            string buffer;

            // Device ID can only be in the range 1-16
            if (id < 1 || id > 16)
            {
                buffer = string.Format("Illegal device ID {0}\nExit!", id);
                BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
                return;
            }

            // Get the driver attributes (Vendor ID, Product ID, Version Number)
            if (!joystick.vJoyEnabled())
            {
                BalanceWalker.FormMain.consoleBoxWriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n");
                return;
            }
            else
            {
                buffer = string.Format("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", joystick.GetvJoyManufacturerString(), joystick.GetvJoyProductString(), joystick.GetvJoySerialNumberString());     //BalanceWalker.FormMain.consoleBoxWriteLine($"Vendor: {joystick.GetvJoyManufacturerString()}\nProduct :{joystick.GetvJoyProductString()}\nVersion Number:{joystick.GetvJoySerialNumberString()}\n");
                BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
            }


            // Get the state of the requested device
            VjdStat status = joystick.GetVJDStatus(id);

            switch (status)
            {
            case VjdStat.VJD_STAT_OWN:
                buffer = string.Format("vJoy Device {0} is already owned by this feeder\n", id);
                BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
                break;

            case VjdStat.VJD_STAT_FREE:
                buffer = string.Format("vJoy Device {0} is free\n", id);
                BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
                break;

            case VjdStat.VJD_STAT_BUSY:
                buffer = string.Format("vJoy Device {0} is already owned by another feeder\nCannot continue\n", id);
                BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
                return;

            case VjdStat.VJD_STAT_MISS:
                buffer = string.Format("vJoy Device {0} is not installed or disabled. \nCannot continue\n", id);
                BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
                return;

            default:
                buffer = string.Format("vJoy Device {0} general error\nCannot continue\n", id);
                BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
                return;
            }
            ;

            // Check which axes are supported
            bool AxisX  = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X);
            bool AxisY  = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y);
            bool AxisZ  = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z);
            bool AxisRX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX);
            bool AxisRZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RZ);
            bool AxisRY = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RY);
            // Get the number of buttons and POV Hat switches supported by this vJoy device
            int nButtons      = joystick.GetVJDButtonNumber(id);
            int ContPovNumber = joystick.GetVJDContPovNumber(id);
            int DiscPovNumber = joystick.GetVJDDiscPovNumber(id);

            // Print results
            buffer = string.Format("\nvJoy Device {0} capabilities:\n", id);
            BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
            buffer = string.Format("Number of buttons\t\t{0}\n", nButtons);
            BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
            buffer = string.Format("Number of Continuous POVs\t{0}\n", ContPovNumber);
            BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
            buffer = string.Format("Number of Descrete POVs\t\t{0}\n", DiscPovNumber);
            BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
            buffer = string.Format("Axis X\t\t{0}\n", AxisX ? "Yes" : "No");
            BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
            buffer = string.Format("Axis Y\t\t{0}\n", AxisY ? "Yes" : "No");
            BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
            buffer = string.Format("Axis Z\t\t{0}\n", AxisZ ? "Yes" : "No");
            BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
            buffer = string.Format("Axis Rx\t\t{0}\n", AxisRX ? "Yes" : "No");
            BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
            buffer = string.Format("Axis Ry\t\t{0}\n", AxisRY ? "Yes" : "No");
            BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
            buffer = string.Format("Axis Rz\t\t{0}\n", AxisRZ ? "Yes" : "No");
            BalanceWalker.FormMain.consoleBoxWriteLine(buffer);

            if (!(AxisX && AxisY && AxisZ && AxisRX && AxisRZ && AxisRY))
            {
                buffer = string.Format("Please enable Axes X,Y,Z,RX,RY,RZ in vJoyConf for device number", id, " in order to use all functions", id);
                BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
            }
            if (nButtons < 1)
            {
                buffer = string.Format("Please enable at least 1 button in vJoyConf for device ", id, " in order to use the only button on the wii balance board");
                BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
            }
            // Test if DLL matches the driver
            UInt32 DllVer = 0, DrvVer = 0;
            bool   match = joystick.DriverMatch(ref DllVer, ref DrvVer);

            if (match)
            {
                buffer = string.Format("Version of Driver Matches DLL Version ({0:X})\n", DllVer);
                BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
            }
            else
            {
                buffer = string.Format("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})\n", DrvVer, DllVer);
                BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
            }

            // Acquire the target
            if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id))))
            {
                buffer = string.Format("Failed to acquire vJoy device number {0}.\n", id);
                BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
                return;
            }
            else
            {
                buffer = string.Format("Acquired: vJoy device number {0}.\n", id);
                BalanceWalker.FormMain.consoleBoxWriteLine(buffer);
            }
            int  X, Y, Z, XR, ZR;
            uint count  = 0;
            long maxval = 0;    // maxval is -32767 +32767

            X  = 20;
            Y  = 30;
            Z  = 40;
            XR = 60;
            ZR = 80;

            joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval);

#if ROBUST
            bool res;
            // Reset this device to default values
            joystick.ResetVJD(id);

            // set this to true to test if the vJoy driver is working. This will feed vjoy with an endless loop of joystick commands.

            while (false)
            {
                // Set position of 4 axes
                res = joystick.SetAxis(X, id, HID_USAGES.HID_USAGE_X);
                res = joystick.SetAxis(Y, id, HID_USAGES.HID_USAGE_Y);
                res = joystick.SetAxis(Z, id, HID_USAGES.HID_USAGE_Z);
                res = joystick.SetAxis(XR, id, HID_USAGES.HID_USAGE_RX);
                res = joystick.SetAxis(ZR, id, HID_USAGES.HID_USAGE_RZ);

                // Press/Release Buttons
                res = joystick.SetBtn(true, id, count / 50);
                res = joystick.SetBtn(false, id, 1 + count / 50);

                // If Continuous POV hat switches installed - make them go round
                // For high values - put the switches in neutral state
                if (ContPovNumber > 0)
                {
                    if ((count * 70) < 30000)
                    {
                        res = joystick.SetContPov(((int)count * 70), id, 1);
                        res = joystick.SetContPov(((int)count * 70) + 2000, id, 2);
                        res = joystick.SetContPov(((int)count * 70) + 4000, id, 3);
                        res = joystick.SetContPov(((int)count * 70) + 6000, id, 4);
                    }
                    else
                    {
                        res = joystick.SetContPov(-1, id, 1);
                        res = joystick.SetContPov(-1, id, 2);
                        res = joystick.SetContPov(-1, id, 3);
                        res = joystick.SetContPov(-1, id, 4);
                    };
                }
                ;

                // If Discrete POV hat switches installed - make them go round
                // From time to time - put the switches in neutral state
                if (DiscPovNumber > 0)
                {
                    if (count < 550)
                    {
                        joystick.SetDiscPov((((int)count / 20) + 0) % 4, id, 1);
                        joystick.SetDiscPov((((int)count / 20) + 1) % 4, id, 2);
                        joystick.SetDiscPov((((int)count / 20) + 2) % 4, id, 3);
                        joystick.SetDiscPov((((int)count / 20) + 3) % 4, id, 4);
                    }
                    else
                    {
                        joystick.SetDiscPov(-1, id, 1);
                        joystick.SetDiscPov(-1, id, 2);
                        joystick.SetDiscPov(-1, id, 3);
                        joystick.SetDiscPov(-1, id, 4);
                    };
                }
                ;

                System.Threading.Thread.Sleep(20);
                X += 150; if (X > maxval)
                {
                    X = 0;
                }
                Y += 250; if (Y > maxval)
                {
                    Y = 0;
                }
                Z += 350; if (Z > maxval)
                {
                    Z = 0;
                }
                XR += 220; if (XR > maxval)
                {
                    XR = 0;
                }
                ZR += 200; if (ZR > maxval)
                {
                    ZR = 0;
                }
                count++;

                if (count > 640)
                {
                    count = 0;
                }
            } // While (Robust)
#endif // ROBUST
#if EFFICIENT   // todo: unused, from the original vjoy feeder demo code.
            byte[] pov = new byte[4];

            while (true)
            {
                iReport.bDevice  = (byte)id;
                iReport.AxisX    = X;
                iReport.AxisY    = Y;
                iReport.AxisZ    = Z;
                iReport.AxisZRot = ZR;
                iReport.AxisXRot = XR;

                // Set buttons one by one
                iReport.Buttons = (uint)(0x1 << (int)(count / 20));

                if (ContPovNumber > 0)
                {
                    // Make Continuous POV Hat spin
                    iReport.bHats    = (count * 70);
                    iReport.bHatsEx1 = (count * 70) + 3000;
                    iReport.bHatsEx2 = (count * 70) + 5000;
                    iReport.bHatsEx3 = 15000 - (count * 70);
                    if ((count * 70) > 36000)
                    {
                        iReport.bHats    = 0xFFFFFFFF; // Neutral state
                        iReport.bHatsEx1 = 0xFFFFFFFF; // Neutral state
                        iReport.bHatsEx2 = 0xFFFFFFFF; // Neutral state
                        iReport.bHatsEx3 = 0xFFFFFFFF; // Neutral state
                    }
                    ;
                }
                else
                {
                    // Make 5-position POV Hat spin

                    pov[0] = (byte)(((count / 20) + 0) % 4);
                    pov[1] = (byte)(((count / 20) + 1) % 4);
                    pov[2] = (byte)(((count / 20) + 2) % 4);
                    pov[3] = (byte)(((count / 20) + 3) % 4);

                    iReport.bHats = (uint)(pov[3] << 12) | (uint)(pov[2] << 8) | (uint)(pov[1] << 4) | (uint)pov[0];
                    if ((count) > 550)
                    {
                        iReport.bHats = 0xFFFFFFFF;         // Neutral state
                    }
                };

                /*** Feed the driver with the position packet - is fails then wait for input then try to re-acquire device ***/
                if (!joystick.UpdateVJD(id, ref iReport))
                {
                    Console.WriteLine("Feeding vJoy device number {0} failed - try to enable device then press enter\n", id);
                    Console.ReadKey(true);
                    joystick.AcquireVJD(id);
                }

                System.Threading.Thread.Sleep(20);
                count++;
                if (count > 640)
                {
                    count = 0;
                }

                X += 150; if (X > maxval)
                {
                    X = 0;
                }
                Y += 250; if (Y > maxval)
                {
                    Y = 0;
                }
                Z += 350; if (Z > maxval)
                {
                    Z = 0;
                }
                XR += 220; if (XR > maxval)
                {
                    XR = 0;
                }
                ZR += 200; if (ZR > maxval)
                {
                    ZR = 0;
                }
            }
            ; // While
#endif // EFFICIENT
        }
Example #6
0
        static void Main(string[] args)
        {
            // Create one joystick object and a position structure.
            joystick = new vJoy();
            iReport  = new vJoy.JoystickState();


            // Device ID can only be in the range 1-16
            if (args.Length > 0 && !String.IsNullOrEmpty(args[0]))
            {
                id = Convert.ToUInt32(args[0]);
            }
            if (id <= 0 || id > 16)
            {
                Console.WriteLine("Illegal device ID {0}\nExit!", id);
                return;
            }

            // Get the driver attributes (Vendor ID, Product ID, Version Number)
            if (!joystick.vJoyEnabled())
            {
                Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n");
                return;
            }
            else
            {
                Console.WriteLine("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", joystick.GetvJoyManufacturerString(), joystick.GetvJoyProductString(), joystick.GetvJoySerialNumberString());
            }

            // Get the state of the requested device
            VjdStat status = joystick.GetVJDStatus(id);

            switch (status)
            {
            case VjdStat.VJD_STAT_OWN:
                Console.WriteLine("vJoy Device {0} is already owned by this feeder\n", id);
                break;

            case VjdStat.VJD_STAT_FREE:
                Console.WriteLine("vJoy Device {0} is free\n", id);
                break;

            case VjdStat.VJD_STAT_BUSY:
                Console.WriteLine("vJoy Device {0} is already owned by another feeder\nCannot continue\n", id);
                return;

            case VjdStat.VJD_STAT_MISS:
                Console.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue\n", id);
                return;

            default:
                Console.WriteLine("vJoy Device {0} general error\nCannot continue\n", id);
                return;
            }
            ;

            // Check which axes are supported
            bool AxisX  = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X);
            bool AxisY  = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y);
            bool AxisZ  = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z);
            bool AxisRX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX);
            bool AxisRZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RZ);
            // Get the number of buttons and POV Hat switchessupported by this vJoy device
            int nButtons      = joystick.GetVJDButtonNumber(id);
            int ContPovNumber = joystick.GetVJDContPovNumber(id);
            int DiscPovNumber = joystick.GetVJDDiscPovNumber(id);

            // Print results
            Console.WriteLine("\nvJoy Device {0} capabilities:\n", id);
            Console.WriteLine("Numner of buttons\t\t{0}\n", nButtons);
            Console.WriteLine("Numner of Continuous POVs\t{0}\n", ContPovNumber);
            Console.WriteLine("Numner of Descrete POVs\t\t{0}\n", DiscPovNumber);
            Console.WriteLine("Axis X\t\t{0}\n", AxisX ? "Yes" : "No");
            Console.WriteLine("Axis Y\t\t{0}\n", AxisX ? "Yes" : "No");
            Console.WriteLine("Axis Z\t\t{0}\n", AxisX ? "Yes" : "No");
            Console.WriteLine("Axis Rx\t\t{0}\n", AxisRX ? "Yes" : "No");
            Console.WriteLine("Axis Rz\t\t{0}\n", AxisRZ ? "Yes" : "No");

            // Test if DLL matches the driver
            UInt32 DllVer = 0, DrvVer = 0;
            bool   match = joystick.DriverMatch(ref DllVer, ref DrvVer);

            if (match)
            {
                Console.WriteLine("Version of Driver Matches DLL Version ({0:X})\n", DllVer);
            }
            else
            {
                Console.WriteLine("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})\n", DrvVer, DllVer);
            }


            // Acquire the target
            if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id))))
            {
                Console.WriteLine("Failed to acquire vJoy device number {0}.\n", id);
                return;
            }
            else
            {
                Console.WriteLine("Acquired: vJoy device number {0}.\n", id);
            }

            // Acquire the target
            if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(2))))
            {
                Console.WriteLine("Failed to acquire vJoy device number {0}.\n", 2);
                return;
            }
            else
            {
                Console.WriteLine("Acquired: vJoy device number {0}.\n", 2);
            }

            // Acquire the target
            if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(3))))
            {
                Console.WriteLine("Failed to acquire vJoy device number {0}.\n", 3);
                return;
            }
            else
            {
                Console.WriteLine("Acquired: vJoy device number {0}.\n", 3);
            }

            // Acquire the target
            if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(4))))
            {
                Console.WriteLine("Failed to acquire vJoy device number {0}.\n", 4);
                return;
            }
            else
            {
                Console.WriteLine("Acquired: vJoy device number {0}.\n", 4);
            }

            int  X, Y, Z, ZR, XR;
            uint count  = 0;
            long maxval = 0;

            X  = 20;
            Y  = 30;
            Z  = 40;
            XR = 60;
            ZR = 80;

            joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval);

#if LMAONEITHER
            bool res;
            // Reset this device to default values
            joystick.ResetVJD(id);

            // Connecting to socket.io server (make sure the server is up first!)
            var socket = IO.Socket("http://localhost:14178");
            socket.On(Socket.EVENT_CONNECT, () =>
            {
                socket.Emit("clientconnect", "iamclient");
                Console.WriteLine("Thanks for using LocalLink! This is a controller log; feel free to minimize it, but DO NOT CLOSE IT unless you're finished using our program.");
            });
            socket.On("buttondown", (data) => {
                JObject a = (JObject)data;
                joystick.SetBtn(true, Convert.ToUInt32((string)a["controllerid"]), Convert.ToUInt32((string)a["buttonid"]));
                Console.WriteLine("\ngot button " + (string)a["buttonid"] + " down on controller " + (string)a["controllerid"]);
            });
            socket.On("buttonup", (data) => {
                JObject a = (JObject)data;
                joystick.SetBtn(false, Convert.ToUInt32((string)a["controllerid"]), Convert.ToUInt32((string)a["buttonid"]));
                Console.WriteLine("\ngot button " + (string)a["buttonid"] + " up on controller " + (string)a["controllerid"]);
            });
            socket.On("setaxis", (data) =>
            {
                JObject a = (JObject)data;
                switch (a["axis"].ToString().ToLower())
                {
                case "x":
                    joystick.SetAxis((int)a["value"], Convert.ToUInt32((string)a["controllerid"]), HID_USAGES.HID_USAGE_X);
                    Console.WriteLine("got x " + (int)a["value"]);
                    break;

                case "y":
                    joystick.SetAxis((int)a["value"], Convert.ToUInt32((string)a["controllerid"]), HID_USAGES.HID_USAGE_Y);
                    break;

                case "z":
                    joystick.SetAxis((int)a["value"], Convert.ToUInt32((string)a["controllerid"]), HID_USAGES.HID_USAGE_Z);
                    break;

                case "rx":
                    joystick.SetAxis((int)a["value"], Convert.ToUInt32((string)a["controllerid"]), HID_USAGES.HID_USAGE_RX);
                    break;

                case "ry":
                    joystick.SetAxis((int)a["value"], Convert.ToUInt32((string)a["controllerid"]), HID_USAGES.HID_USAGE_RY);
                    break;

                case "rz":
                    joystick.SetAxis((int)a["value"], Convert.ToUInt32((string)a["controllerid"]), HID_USAGES.HID_USAGE_RZ);
                    break;
                }
            });

            Console.ReadLine();
#endif // LMAONEITHER
#if ROBUST
            bool res;
            // Reset this device to default values
            joystick.ResetVJD(id);

            // Feed the device in endless loop
            while (true)
            {
                // Set position of 4 axes
                res = joystick.SetAxis(X, id, HID_USAGES.HID_USAGE_X);
                res = joystick.SetAxis(Y, id, HID_USAGES.HID_USAGE_Y);
                res = joystick.SetAxis(Z, id, HID_USAGES.HID_USAGE_Z);
                res = joystick.SetAxis(XR, id, HID_USAGES.HID_USAGE_RX);
                res = joystick.SetAxis(ZR, id, HID_USAGES.HID_USAGE_RZ);

                // Press/Release Buttons
                res = joystick.SetBtn(true, id, count / 50);
                res = joystick.SetBtn(false, id, 1 + count / 50);

                // If Continuous POV hat switches installed - make them go round
                // For high values - put the switches in neutral state
                if (ContPovNumber > 0)
                {
                    if ((count * 70) < 30000)
                    {
                        res = joystick.SetContPov(((int)count * 70), id, 1);
                        res = joystick.SetContPov(((int)count * 70) + 2000, id, 2);
                        res = joystick.SetContPov(((int)count * 70) + 4000, id, 3);
                        res = joystick.SetContPov(((int)count * 70) + 6000, id, 4);
                    }
                    else
                    {
                        res = joystick.SetContPov(-1, id, 1);
                        res = joystick.SetContPov(-1, id, 2);
                        res = joystick.SetContPov(-1, id, 3);
                        res = joystick.SetContPov(-1, id, 4);
                    };
                }
                ;

                // If Discrete POV hat switches installed - make them go round
                // From time to time - put the switches in neutral state
                if (DiscPovNumber > 0)
                {
                    if (count < 550)
                    {
                        joystick.SetDiscPov((((int)count / 20) + 0) % 4, id, 1);
                        joystick.SetDiscPov((((int)count / 20) + 1) % 4, id, 2);
                        joystick.SetDiscPov((((int)count / 20) + 2) % 4, id, 3);
                        joystick.SetDiscPov((((int)count / 20) + 3) % 4, id, 4);
                    }
                    else
                    {
                        joystick.SetDiscPov(-1, id, 1);
                        joystick.SetDiscPov(-1, id, 2);
                        joystick.SetDiscPov(-1, id, 3);
                        joystick.SetDiscPov(-1, id, 4);
                    };
                }
                ;

                System.Threading.Thread.Sleep(20);
                X += 150; if (X > maxval)
                {
                    X = 0;
                }
                Y += 250; if (Y > maxval)
                {
                    Y = 0;
                }
                Z += 350; if (Z > maxval)
                {
                    Z = 0;
                }
                XR += 220; if (XR > maxval)
                {
                    XR = 0;
                }
                ZR += 200; if (ZR > maxval)
                {
                    ZR = 0;
                }
                count++;

                if (count > 640)
                {
                    count = 0;
                }
            } // While (Robust)
#endif // ROBUST
#if EFFICIENT
            byte[] pov = new byte[4];

            while (true)
            {
                iReport.bDevice  = (byte)id;
                iReport.AxisX    = X;
                iReport.AxisY    = Y;
                iReport.AxisZ    = Z;
                iReport.AxisZRot = ZR;
                iReport.AxisXRot = XR;

                // Set buttons one by one
                iReport.Buttons = (uint)(0x1 << (int)(count / 20));

                if (ContPovNumber > 0)
                {
                    // Make Continuous POV Hat spin
                    iReport.bHats    = (count * 70);
                    iReport.bHatsEx1 = (count * 70) + 3000;
                    iReport.bHatsEx2 = (count * 70) + 5000;
                    iReport.bHatsEx3 = 15000 - (count * 70);
                    if ((count * 70) > 36000)
                    {
                        iReport.bHats    = 0xFFFFFFFF; // Neutral state
                        iReport.bHatsEx1 = 0xFFFFFFFF; // Neutral state
                        iReport.bHatsEx2 = 0xFFFFFFFF; // Neutral state
                        iReport.bHatsEx3 = 0xFFFFFFFF; // Neutral state
                    }
                    ;
                }
                else
                {
                    // Make 5-position POV Hat spin

                    pov[0] = (byte)(((count / 20) + 0) % 4);
                    pov[1] = (byte)(((count / 20) + 1) % 4);
                    pov[2] = (byte)(((count / 20) + 2) % 4);
                    pov[3] = (byte)(((count / 20) + 3) % 4);

                    iReport.bHats = (uint)(pov[3] << 12) | (uint)(pov[2] << 8) | (uint)(pov[1] << 4) | (uint)pov[0];
                    if ((count) > 550)
                    {
                        iReport.bHats = 0xFFFFFFFF;         // Neutral state
                    }
                };

                /*** Feed the driver with the position packet - is fails then wait for input then try to re-acquire device ***/
                if (!joystick.UpdateVJD(id, ref iReport))
                {
                    Console.WriteLine("Feeding vJoy device number {0} failed - try to enable device then press enter\n", id);
                    Console.ReadKey(true);
                    joystick.AcquireVJD(id);
                }

                System.Threading.Thread.Sleep(20);
                count++;
                if (count > 640)
                {
                    count = 0;
                }

                X += 150; if (X > maxval)
                {
                    X = 0;
                }
                Y += 250; if (Y > maxval)
                {
                    Y = 0;
                }
                Z += 350; if (Z > maxval)
                {
                    Z = 0;
                }
                XR += 220; if (XR > maxval)
                {
                    XR = 0;
                }
                ZR += 200; if (ZR > maxval)
                {
                    ZR = 0;
                }
            }
            ; // While
#endif // EFFICIENT
        } // Main
Example #7
0
        public void Evaluate(int SpreadMax)
        {
            if (init)
            {
                VJInstance = new vJoy();
                VJState    = new vJoy.JoystickState();
                if (!VJInstance.vJoyEnabled())
                {
                    FEnabled[0] = false;
                    return;
                }
                Status     = VJInstance.GetVJDStatus(FID[0]);
                FStatus[0] = Status.ToString();

                ButtonCount = VJInstance.GetVJDButtonNumber(FID[0]);
                PovCount    = VJInstance.GetVJDContPovNumber(FID[0]);
                if (Status != VjdStat.VJD_STAT_FREE && Status != VjdStat.VJD_STAT_OWN)
                {
                    return;
                }
                if (!VJInstance.AcquireVJD(FID[0]))
                {
                    return;
                }

                Axes = new[] {
                    HID_USAGES.HID_USAGE_X,
                    HID_USAGES.HID_USAGE_Y,
                    HID_USAGES.HID_USAGE_Z,
                    HID_USAGES.HID_USAGE_RX,
                    HID_USAGES.HID_USAGE_RY,
                    HID_USAGES.HID_USAGE_RZ,
                    HID_USAGES.HID_USAGE_SL0,
                    HID_USAGES.HID_USAGE_SL1,
                    HID_USAGES.HID_USAGE_WHL,
                    HID_USAGES.HID_USAGE_ACCELERATOR,
                    HID_USAGES.HID_USAGE_BRAKE,
                    HID_USAGES.HID_USAGE_CLUTCH,
                    HID_USAGES.HID_USAGE_STEERING,
                    HID_USAGES.HID_USAGE_AILERON,
                    HID_USAGES.HID_USAGE_RUDDER,
                    HID_USAGES.HID_USAGE_THROTTLE
                };
                FAxisPresent.SliceCount = Axes.Length;
                AxisMaxVal = new long[Axes.Length];
                AxisMinVal = new long[Axes.Length];

                for (int i = 0; i < Axes.Length; i++)
                {
                    FAxisPresent[i] = VJInstance.GetVJDAxisExist(FID[0], Axes[i]);
                    if (FAxisPresent[i])
                    {
                        long minv = 0, maxv = 0;
                        VJInstance.GetVJDAxisMin(FID[0], Axes[i], ref minv);
                        VJInstance.GetVJDAxisMax(FID[0], Axes[i], ref maxv);
                        AxisMinVal[i] = minv;
                        AxisMaxVal[i] = maxv;
                    }
                }
                init = false;
            }
            FEnabled[0] = true;
            FStatus[0]  = Status.ToString();
            for (int i = 0; i < Math.Min(FAxesIn.SliceCount, Axes.Length); i++)
            {
                if (FAxisPresent[i])
                {
                    VJInstance.SetAxis(
                        (int)(FAxesIn[i] * AxisMaxVal[i] + (1 - FAxesIn[i]) * AxisMinVal[i]),
                        FID[0],
                        Axes[i]);
                }
            }
            for (int i = 0; i < Math.Min(FButtonsIn.SliceCount, ButtonCount); i++)
            {
                VJInstance.SetBtn(FButtonsIn[i], FID[0], (uint)i + 1);
            }
            for (int i = 0; i < Math.Min(FPovPosIn.SliceCount, PovCount); i++)
            {
                if (!FPovSetIn[i])
                {
                    VJInstance.SetContPov(-1, FID[0], (uint)i + 1);
                }
                else
                {
                    VJInstance.SetContPov((int)(FPovPosIn[i] * 35999), FID[0], (uint)i + 1);
                }
            }
        }
Example #8
0
        private void SetDPad(byte[] values, Collection <GamepadConfigurationItem> config)
        {
            var dPadUp    = false;
            var dPadRight = false;
            var dPadDown  = false;
            var dPadLeft  = false;

            for (var i = 0; i < config.Count; i++)
            {
                if (config[i].Type == GamepadItemType.DPadUp)
                {
                    dPadUp = ConvertToButtonState(values[i]);
                }

                if (config[i].Type == GamepadItemType.DPadRight)
                {
                    dPadRight = ConvertToButtonState(values[i]);
                }

                if (config[i].Type == GamepadItemType.DPadDown)
                {
                    dPadDown = ConvertToButtonState(values[i]);
                }

                if (config[i].Type == GamepadItemType.DPadLeft)
                {
                    dPadLeft = ConvertToButtonState(values[i]);
                }
            }

            var angle = -1;

            if (dPadUp && dPadRight)
            {
                angle = 4500;
            }
            else if (dPadRight && dPadDown)
            {
                angle = 13500;
            }
            else if (dPadDown && dPadLeft)
            {
                angle = 22500;
            }
            else if (dPadLeft && dPadUp)
            {
                angle = 31500;
            }
            else if (dPadUp)
            {
                angle = 0;
            }
            else if (dPadRight)
            {
                angle = 9000;
            }
            else if (dPadDown)
            {
                angle = 18000;
            }
            else if (dPadLeft)
            {
                angle = 27000;
            }


            _vJoy.SetContPov(angle, _gamepadId, 1);
        }
Example #9
0
        public void parseMessage(NetHelper.Message message)
        {
            keys.update(message.btn);

            int angle = -1;

            if (angle == -1 && keys.isDown(Keys.DRIGHT))
            {
                angle = 9000;
                if (keys.isDown(Keys.DDOWN))
                {
                    angle += 4500;
                }
                if (keys.isDown(Keys.DUP))
                {
                    angle -= 4500;
                }
            }

            if (angle == -1 && keys.isDown(Keys.DLEFT))
            {
                angle = 27000;
                if (keys.isDown(Keys.DDOWN))
                {
                    angle -= 4500;
                }
                if (keys.isDown(Keys.DUP))
                {
                    angle += 4500;
                }
            }

            if (angle == -1 && keys.isDown(Keys.DUP))
            {
                angle = 0;
            }
            if (angle == -1 && keys.isDown(Keys.DDOWN))
            {
                angle = 18000;
            }

            joystick.SetContPov(angle, message.ID, 1);

            joystick.SetBtn(keys.isDown(Keys.A), message.ID, 1);
            joystick.SetBtn(keys.isDown(Keys.B), message.ID, 2);
            joystick.SetBtn(keys.isDown(Keys.X), message.ID, 3);
            joystick.SetBtn(keys.isDown(Keys.Y), message.ID, 4);
            joystick.SetBtn(keys.isDown(Keys.L), message.ID, 5);
            joystick.SetBtn(keys.isDown(Keys.R), message.ID, 6);
            joystick.SetBtn(keys.isDown(Keys.SELECT), message.ID, 7);
            joystick.SetBtn(keys.isDown(Keys.START), message.ID, 8);

            float localX = ((message.pdx + 156) / 312.0f);
            float localY = 1 - ((message.pdy + 156) / 312.0f);

            joystick.SetAxis((int)(localX * axisMax), message.ID, HID_USAGES.HID_USAGE_X);
            joystick.SetAxis((int)(localY * axisMax), message.ID, HID_USAGES.HID_USAGE_Y);

            // Touch & Cursor interaction
            if (keys.isDown(Keys.TOUCH))
            {
                int xx = message.touch_px;
                int yy = message.touch_py;

                float rx = xx / 320.0f;
                float ry = yy / 240.0f;

                int screen_w = Screen.PrimaryScreen.Bounds.Width;
                int screen_h = Screen.PrimaryScreen.Bounds.Height;

                int x = (int)(rx * screen_w);
                int y = (int)(ry * screen_h);

                SetCursorPos(x, y);

                // Mouse click
                if (keys.pressed(Keys.L) || keys.pressed(Keys.R))
                {
                    mouse_event(MOUSEEVENTF_LEFTDOWN, (uint)x, (uint)y, 0, 0);
                }
                else if (keys.released(Keys.L) || keys.released(Keys.R))
                {
                    mouse_event(MOUSEEVENTF_LEFTUP, (uint)x, (uint)y, 0, 0);
                }

                if (keys.pressed(Keys.DUP) || keys.pressed(Keys.X))
                {
                    mouse_event(MOUSEEVENTF_RIGHTDOWN, (uint)x, (uint)y, 0, 0);
                }
                else if (keys.released(Keys.DUP) || keys.released(Keys.X))
                {
                    mouse_event(MOUSEEVENTF_RIGHTUP, (uint)x, (uint)y, 0, 0);
                }
            }
        }
        bool FeedDinputDevice(uint id, out string message)
        {
            message = "";
            // Create one joystick object and a position structure.
            joystick = new vJoy();
            iReport  = new vJoy.JoystickState();
            // Device ID can only be in the range 1-16
            if (id <= 0 || id > 16)
            {
                message += string.Format("Illegal device ID {0}\nExit!", id);
                return(false);
            }

            // Get the driver attributes (Vendor ID, Product ID, Version Number)
            if (!joystick.vJoyEnabled())
            {
                message += string.Format("vJoy driver not enabled: Failed Getting vJoy attributes.\n");
                return(false);
            }
            else
            {
                message += string.Format("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", joystick.GetvJoyManufacturerString(), joystick.GetvJoyProductString(), joystick.GetvJoySerialNumberString());
            }

            // Get the state of the requested device
            VjdStat status = joystick.GetVJDStatus(id);

            switch (status)
            {
            case VjdStat.VJD_STAT_OWN:
                message += string.Format("vJoy Device {0} is already owned by this feeder\n", id);
                break;

            case VjdStat.VJD_STAT_FREE:
                message += string.Format("vJoy Device {0} is free\n", id);
                break;

            case VjdStat.VJD_STAT_BUSY:
                message += string.Format("vJoy Device {0} is already owned by another feeder\nCannot continue\n", id);
                return(false);

            case VjdStat.VJD_STAT_MISS:
                message += string.Format("vJoy Device {0} is not installed or disabled\nCannot continue\n", id);
                return(false);

            default:
                message += string.Format("vJoy Device {0} general error\nCannot continue\n", id);
                return(false);
            }
            ;

            // Check which axes are supported
            bool AxisX  = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X);
            bool AxisY  = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y);
            bool AxisZ  = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z);
            bool AxisRX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX);
            bool AxisRZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RZ);
            // Get the number of buttons and POV Hat switches supported by this vJoy device
            int nButtons      = joystick.GetVJDButtonNumber(id);
            int ContPovNumber = joystick.GetVJDContPovNumber(id);
            int DiscPovNumber = joystick.GetVJDDiscPovNumber(id);

            // Print results
            message += string.Format("\nvJoy Device {0} capabilities:\n", id);
            message += string.Format("Number of buttons\t\t{0}\n", nButtons);
            message += string.Format("Number of Continuous POVs\t{0}\n", ContPovNumber);
            message += string.Format("Number of Discrete POVs\t\t{0}\n", DiscPovNumber);
            message += string.Format("Axis X\t\t{0}\n", AxisX ? "Yes" : "No");
            message += string.Format("Axis Y\t\t{0}\n", AxisX ? "Yes" : "No");
            message += string.Format("Axis Z\t\t{0}\n", AxisX ? "Yes" : "No");
            message += string.Format("Axis Rx\t\t{0}\n", AxisRX ? "Yes" : "No");
            message += string.Format("Axis Rz\t\t{0}\n", AxisRZ ? "Yes" : "No");

            // Test if DLL matches the driver
            UInt32 DllVer = 0, DrvVer = 0;
            bool   match = joystick.DriverMatch(ref DllVer, ref DrvVer);

            if (match)
            {
                message += string.Format("Version of Driver Matches DLL Version ({0:X})\n", DllVer);
            }
            else
            {
                message += string.Format("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})\n", DrvVer, DllVer);
            }

            // Acquire the target
            if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id))))
            {
                message += string.Format("Failed to acquire vJoy device number {0}.\n", id);
                return(false);
            }
            else
            {
                message += string.Format("Acquired: vJoy device number {0}.\n", id);
            }


            int  X, Y, Z, ZR, XR;
            uint count  = 0;
            long maxval = 0;

            X  = 20;
            Y  = 30;
            Z  = 40;
            XR = 60;
            ZR = 80;

            joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval);

            bool res;

            // Reset this device to default values
            joystick.ResetVJD(id);

            // Feed the device in endless loop
            while (!Program.IsClosing && FeedingEnabled)
            {
                // Set position of 4 axes
                res = joystick.SetAxis(X, id, HID_USAGES.HID_USAGE_X);
                res = joystick.SetAxis(Y, id, HID_USAGES.HID_USAGE_Y);
                res = joystick.SetAxis(Z, id, HID_USAGES.HID_USAGE_Z);
                res = joystick.SetAxis(XR, id, HID_USAGES.HID_USAGE_RX);
                res = joystick.SetAxis(ZR, id, HID_USAGES.HID_USAGE_RZ);

                // Press/Release Buttons
                res = joystick.SetBtn(true, id, count / 50);
                res = joystick.SetBtn(false, id, 1 + count / 50);

                // If Continuous POV hat switches installed - make them go round
                // For high values - put the switches in neutral state
                if (ContPovNumber > 0)
                {
                    if ((count * 70) < 30000)
                    {
                        res = joystick.SetContPov(((int)count * 70), id, 1);
                        res = joystick.SetContPov(((int)count * 70) + 2000, id, 2);
                        res = joystick.SetContPov(((int)count * 70) + 4000, id, 3);
                        res = joystick.SetContPov(((int)count * 70) + 6000, id, 4);
                    }
                    else
                    {
                        res = joystick.SetContPov(-1, id, 1);
                        res = joystick.SetContPov(-1, id, 2);
                        res = joystick.SetContPov(-1, id, 3);
                        res = joystick.SetContPov(-1, id, 4);
                    };
                }
                ;

                // If Discrete POV hat switches installed - make them go round
                // From time to time - put the switches in neutral state
                if (DiscPovNumber > 0)
                {
                    if (count < 550)
                    {
                        joystick.SetDiscPov((((int)count / 20) + 0) % 4, id, 1);
                        joystick.SetDiscPov((((int)count / 20) + 1) % 4, id, 2);
                        joystick.SetDiscPov((((int)count / 20) + 2) % 4, id, 3);
                        joystick.SetDiscPov((((int)count / 20) + 3) % 4, id, 4);
                    }
                    else
                    {
                        joystick.SetDiscPov(-1, id, 1);
                        joystick.SetDiscPov(-1, id, 2);
                        joystick.SetDiscPov(-1, id, 3);
                        joystick.SetDiscPov(-1, id, 4);
                    };
                }
                ;

                System.Threading.Thread.Sleep(20);
                X += 150; if (X > maxval)
                {
                    X = 0;
                }
                Y += 250; if (Y > maxval)
                {
                    Y = 0;
                }
                Z += 350; if (Z > maxval)
                {
                    Z = 0;
                }
                XR += 220; if (XR > maxval)
                {
                    XR = 0;
                }
                ZR += 200; if (ZR > maxval)
                {
                    ZR = 0;
                }
                count++;

                if (count > 640)
                {
                    count = 0;
                }
            }     // While (Robust)
            return(true);
        }         // Main