// User-defined Removal/Arival callback Function
        // When registered, label2 was passed as user-data
        private void Removal(bool removal, bool first, object userData)
        {
            string prt;
            Label  l = userData as Label;

            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);

            // Final values after the last arival
            if (!removal && !first)
            {
                prt         = String.Format("Device[{0}]: Buttons={1}; DiscPOVs:{2}; ContPOVs:{3}", id, nBtn, nDPov, nCPov);
                label2.Text = prt;
            }

            // Temporary message during intermediate states
            else
            {
                prt         = String.Format("Device[{0}]: Wait ...", id);
                label2.Text = prt;
            }
        }
Esempio n. 2
0
        private void Initialize_vJoy()
        {
            // Create one joystick object and a position structure.
            joystick = new vJoy();
            iReport  = new vJoy.JoystickState();

            // Get the driver attributes (Vendor ID, Product ID, Version Number)
            if (!joystick.vJoyEnabled())
            {
                MessageBox.Show("vJoy driver not enabled: Failed Getting vJoy attributes.\n");
                Program._shouldExit = true;
                System.Environment.Exit(0);
            }

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

            switch (status)
            {
            case VjdStat.VJD_STAT_OWN:
                break;

            case VjdStat.VJD_STAT_FREE:
                break;

            case VjdStat.VJD_STAT_BUSY:
                MessageBox.Show("vJoy Device is already owned by another feeder\nInput feeding will not occur.");
                //System.Environment.Exit(0);
                return;

            case VjdStat.VJD_STAT_MISS:
                MessageBox.Show("vJoy Device is not installed or disabled\nInput feeding will not occur.");
                //System.Environment.Exit(0);
                return;

            default:
                MessageBox.Show("vJoy Device general error\nInput feeding will not occur.");
                //System.Environment.Exit(0);
                return;
            }
            ;

            // 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);

            // Acquire the target
            if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id))))
            {
                MessageBox.Show("Failed to acquire vJoy device number");
                Program._shouldExit = true;
                System.Environment.Exit(0);
            }

            joystick.ResetVJD(id);
        }
Esempio n. 3
0
        public void check2() //check if virual joystick have write driver installed and compatible with versions of vjoy
        {
            UInt32 DllVer = 0, DrvVer = 0;
            bool   match = joystick1.DriverMatch(ref DllVer, ref DrvVer);

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

            VjdStat status = joystick1.GetVJDStatus(joyid);

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

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

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

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

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

            int  nBtn     = joystick1.GetVJDButtonNumber(joyid);
            int  nDPov    = joystick1.GetVJDDiscPovNumber(joyid);
            int  nCPov    = joystick1.GetVJDContPovNumber(joyid);
            bool X_Exist  = joystick1.GetVJDAxisExist(joyid, HID_USAGES.HID_USAGE_X);
            bool Y_Exist  = joystick1.GetVJDAxisExist(joyid, HID_USAGES.HID_USAGE_Y);
            bool Z_Exist  = joystick1.GetVJDAxisExist(joyid, HID_USAGES.HID_USAGE_Z);
            bool RX_Exist = joystick1.GetVJDAxisExist(joyid, HID_USAGES.HID_USAGE_RX);

            prt = String.Format("Device[{0}]: Buttons={1}; DiscPOVs:{2}; ContPOVs:{3}",
                                joyid, nBtn, nDPov, nCPov);
            Debug.WriteLine(prt);
        }
Esempio n. 4
0
    IEnumerator Simulation()
    {
        controller.SetPolicy(Controller.PolicyFlag.POLICY_BACKGROUND_FRAMES);
        controller.SetPolicyFlags(Controller.PolicyFlag.POLICY_BACKGROUND_FRAMES);
        controller.AddListener(listener);

        int ContPovNumber = joystick.GetVJDContPovNumber(id);
        int DiscPovNumber = joystick.GetVJDDiscPovNumber(id);

        //uint count = 0;
        long maxval = 0;

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

        AxisMax  = (int)maxval;
        AxisZero = AxisMax / 2;
        int AxisX  = AxisZero;
        int AxisY  = AxisZero;
        int AxisZ  = AxisZero;
        int AxisZR = AxisZero;
        int AxisXR = AxisZero;

        AxisReset();

        Vector3 OldPosition = Tool.transform.localPosition;

        while (true)
        {
            Vector3 pos = Tool.transform.localPosition;
            if (Mathf.Abs(OldPosition.sqrMagnitude - pos.sqrMagnitude) > 0.0001f)
            {
                AxisX = pos.x > 0 ? AxisPositive(pos.x, JoyConfig.Config.MaxPosition.x, JoyConfig.Config.Deadband.x) :
                        AxisNegative(pos.x, JoyConfig.Config.MinPosition.x, -JoyConfig.Config.Deadband.x);

                AxisZ = pos.y > 0 ? AxisPositive(pos.y, JoyConfig.Config.MaxPosition.y, JoyConfig.Config.Deadband.y) :
                        AxisNegative(pos.y, JoyConfig.Config.MinPosition.y, -JoyConfig.Config.Deadband.y);

                AxisY = pos.z > 0 ? AxisPositive(pos.z, JoyConfig.Config.MaxPosition.z, JoyConfig.Config.Deadband.z) :
                        AxisNegative(pos.z, JoyConfig.Config.MinPosition.z, -JoyConfig.Config.Deadband.z);

                joystick.SetAxis(AxisX, id, HID_USAGES.HID_USAGE_X);
                joystick.SetAxis(AxisY, id, HID_USAGES.HID_USAGE_Y);
                joystick.SetAxis(AxisZ, id, HID_USAGES.HID_USAGE_Z);

                OldPosition = Tool.transform.localPosition;
            }
            ScreenLog.JLog.LinkString("AxisX = " + (float)AxisX / AxisMax);
            ScreenLog.JLog.LinkString("AxisY = " + (float)AxisY / AxisMax);
            ScreenLog.JLog.LinkString("AxisZ = " + (float)AxisZ / AxisMax);
            yield return(new WaitForFixedUpdate());
        }
    }
Esempio n. 5
0
        void Start()
        {
            joystick = new vJoy();
            iReport  = new vJoy.JoystickState();

            if (joystick.vJoyEnabled())
            {
                VjdStat status        = joystick.GetVJDStatus(1);
                bool    AxisX         = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X);
                int     nButtons      = joystick.GetVJDButtonNumber(id);
                int     ContPovNumber = joystick.GetVJDContPovNumber(id);
                int     DiscPovNumber = joystick.GetVJDDiscPovNumber(id);
                joystick.AcquireVJD(id);
                joystick.ResetVJD(id);
            }

            fpsMonitor = GetComponent <FpsMonitor> ();

            displayFacePointsToggle.isOn   = displayFacePoints;
            displayAxesToggle.isOn         = displayAxes;
            displayHeadToggle.isOn         = displayHead;
            displayEffectsToggle.isOn      = displayEffects;
            enableLowPassFilterToggle.isOn = enableLowPassFilter;

            webCamTextureToMatHelper = gameObject.GetComponent <WebCamTextureToMatHelper> ();


            dlibShapePredictorFileName = DlibFaceLandmarkDetectorExample.dlibShapePredictorFileName;
            #if UNITY_WEBGL && !UNITY_EDITOR
            getFilePath_Coroutine = DlibFaceLandmarkDetector.UnityUtils.Utils.getFilePathAsync(dlibShapePredictorFileName, (result) => {
                getFilePath_Coroutine = null;

                dlibShapePredictorFilePath = result;
                Run();
            });
            StartCoroutine(getFilePath_Coroutine);
            #else
            dlibShapePredictorFilePath = DlibFaceLandmarkDetector.UnityUtils.Utils.getFilePath(dlibShapePredictorFileName);
            Run();
            #endif
        }
Esempio n. 6
0
 private void FeederForm_Load(object sender, EventArgs e)
 {
     r             = new Random(DateTime.Now.Millisecond);
     DiscPovNumber = joystick.GetVJDDiscPovNumber(id);
     ContPovNumber = joystick.GetVJDContPovNumber(id);
     joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval);
     // Reset this device to default values
     joystick.ResetVJD(id);
     X           = 20;
     Y           = 30;
     Z           = 40;
     XR          = 60;
     ZR          = 80;
     cPitch      = cRoll = cYaw = 0.5;
     desPitch    = desRoll = desYaw = 0.5;
     cThr        = 0;
     desThr      = 0;
     cConv       = 0;
     state       = ERAState.Disarmed;
     label2.Text = "НЕ ВЗВЕДЕНО";
     joystick.SetBtn(false, id, 1);
     pParam   = 2;
     waitTime = 1.5;
 }
Esempio n. 7
0
        /// <summary>
        /// Acquire a vJoy device ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Acquire(uint id)
        {
            // Device ID can only be in the range 1-16
            vJoyDevID      = id;
            Report.bDevice = (byte)vJoyDevID;
            if (vJoyDevID <= 0 || vJoyDevID > 16)
            {
                LogFormat(LogLevels.ERROR, "Illegal device ID {0}\nExit!", vJoyDevID);
                return(-1);
            }

            // Get the state of the requested device
            VjdStat status = Joystick.GetVJDStatus(vJoyDevID);

            switch (status)
            {
            case VjdStat.VJD_STAT_OWN:
                LogFormat(LogLevels.DEBUG, "vJoy Device {0} is already owned by this feeder", vJoyDevID);
                break;

            case VjdStat.VJD_STAT_FREE:
                LogFormat(LogLevels.DEBUG, "vJoy Device {0} is free", vJoyDevID);
                break;

            case VjdStat.VJD_STAT_BUSY:
                LogFormat(LogLevels.ERROR, "vJoy Device {0} is already owned by another feeder\nCannot continue", vJoyDevID);
                return(-3);

            case VjdStat.VJD_STAT_MISS:
                LogFormat(LogLevels.ERROR, "vJoy Device {0} is not installed or disabled\nCannot continue", vJoyDevID);
                return(-4);

            default:
                LogFormat(LogLevels.ERROR, "vJoy Device {0} general error\nCannot continue", vJoyDevID);
                return(-1);
            }
            ;


            // Get the number of buttons and POV Hat switchessupported by this vJoy device
            this.NbButtons = Joystick.GetVJDButtonNumber(vJoyDevID);
            int ContPovNumber = Joystick.GetVJDContPovNumber(vJoyDevID);
            int DiscPovNumber = Joystick.GetVJDDiscPovNumber(vJoyDevID);

            // Print results
            LogFormat(LogLevels.DEBUG, "vJoy Device {0} capabilities:", vJoyDevID);
            LogFormat(LogLevels.DEBUG, "Numner of buttons\t\t{0}", this.NbButtons);
            LogFormat(LogLevels.DEBUG, "Numner of Continuous POVs\t{0}", ContPovNumber);
            LogFormat(LogLevels.DEBUG, "Numner of Descrete POVs\t\t{0}", DiscPovNumber);

            // Check which axes are supported. Follow enum HID_USAGES
            ConfiguredvJoyAxes.Clear();
            int i = 0;

            foreach (HID_USAGES toBeTested in Enum.GetValues(typeof(HID_USAGES)))
            {
                // Skip POV
                if (toBeTested == HID_USAGES.HID_USAGE_POV)
                {
                    continue;
                }
                var present = Joystick.GetVJDAxisExist(vJoyDevID, toBeTested);
                LogFormat(LogLevels.DEBUG, "Axis " + HIDAxesInfo[i].Name + " \t\t{0}", present ? "Yes" : "No");
                if (present)
                {
                    HIDAxesInfo[i].IsPresent = present;
                    // Retrieve min/max from vJoy
                    if (!Joystick.GetVJDAxisMin(vJoyDevID, toBeTested, ref HIDAxesInfo[i].MinValue))
                    {
                        Log("Failed getting min value!");
                    }
                    if (!Joystick.GetVJDAxisMax(vJoyDevID, toBeTested, ref HIDAxesInfo[i].MaxValue))
                    {
                        Log("Failed getting min value!");
                    }
                    Log(" Min= " + HIDAxesInfo[i].MinValue + " Max=" + HIDAxesInfo[i].MaxValue);

                    // Add to indexed list of configured axes
                    ConfiguredvJoyAxes.Add(HIDAxesInfo[i]);
                }
                i++;
            }

            // Acquire the target
            if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!Joystick.AcquireVJD(vJoyDevID))))
            {
                LogFormat(LogLevels.ERROR, "Failed to acquire vJoy device number {0}.", vJoyDevID);
                return(-1);
            }
            else
            {
                LogFormat(LogLevels.DEBUG, "Acquired: vJoy device number {0}.", vJoyDevID);
            }
            return((int)status);
        }
Esempio n. 8
0
        /// <summary>
        /// vJoyの初期化
        /// </summary>
        public void Initialize()
        {
            // vJoyドライバーのテスト
            // 失敗した場合、falseを返す
            bool result = joystick.vJoyEnabled();

            if (result == false)
            {
                throw new DeviceControlException(Properties.Resources.VJOY_ENABLE);
            }
            // vJoy仮想デバイスのテスト
            VjdStat status = joystick.GetVJDStatus(rID);

            switch (status)
            {
            case VjdStat.VJD_STAT_BUSY:     // 〃
                throw new DeviceControlException(Properties.Resources.VJOY_STAT_OWN);

            case VjdStat.VJD_STAT_MISS:     // インストールされていない or 無効な状態
                throw new DeviceControlException(Properties.Resources.VJOY_ENABLE);

            case VjdStat.VJD_STAT_OWN:
                return;

            case VjdStat.VJD_STAT_FREE:     // 利用可能
                break;
            }

            // vJoy仮想デバイスの設定値確認
            // 今回、仕様としては、
            //    12ボタン
            //    +字キー
            //    アナログスティック 2本
            // としています
            // ※将来的には自動的に設定するよう変更

            // ボタン数のチェック
            Int32 nBtn = joystick.GetVJDButtonNumber(rID);

            if (nBtn != 12)
            {
                throw new DeviceControlException(Properties.Resources.VJOY_BUTTON_NUMBER_FATAL);
            }
            // +字キーの有無チェック
            /* Returns the number of discrete-type POV hats in the specified device Discrete-type POV Hat values may be  North, East, South, West or neutral Valid values are 0 to 4  (from version 2.0.1)*/
            Int32 nDPov = joystick.GetVJDDiscPovNumber(rID);

            if (nDPov != 1)
            {
                throw new DeviceControlException(Properties.Resources.VJOY_POV_FATAL);
            }
            Int32 nCPov = joystick.GetVJDContPovNumber(rID);

            if (nCPov != 0)
            {
                throw new DeviceControlException(Properties.Resources.VJOY_POV_FATAL);
            }
            // アナログスティックのチェック
            // 全ての機能の有無はチェックせず必要条件のみ確認
            // 左アナログスティック←→
            result = joystick.GetVJDAxisExist(rID, HID_USAGES.HID_USAGE_X);
            if (result == false)
            {
                throw new DeviceControlException(Properties.Resources.VJOY_STICK_LEFT_FATAL);
            }
            // 左アナログスティック↑↓
            result = joystick.GetVJDAxisExist(rID, HID_USAGES.HID_USAGE_Y);
            if (result == false)
            {
                throw new DeviceControlException(Properties.Resources.VJOY_STICK_LEFT_FATAL);
            }
            // 右アナログスティック←→
            result = joystick.GetVJDAxisExist(rID, HID_USAGES.HID_USAGE_Z);
            if (result == false)
            {
                throw new DeviceControlException(Properties.Resources.VJOY_STICK_RIGHT_FATAL);
            }
            // 右アナログスティック↑↓
            result = joystick.GetVJDAxisExist(rID, HID_USAGES.HID_USAGE_RZ);
            if (result == false)
            {
                throw new DeviceControlException(Properties.Resources.VJOY_STICK_RIGHT_FATAL);
            }

            joystick.GetVJDAxisMax(rID, HID_USAGES.HID_USAGE_X, ref m_nAxisMax);
            joystick.GetVJDAxisMin(rID, HID_USAGES.HID_USAGE_X, ref m_nAxisMin);

            // 接続
            joystick.AcquireVJD(rID);

            joystick.ResetVJD(rID);
        }
Esempio n. 9
0
        public void initializeJoystick()
        {
            if (joystick == null)
            {
                joystick = new vJoy();
            }

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

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

            switch (status)
            {
            case VjdStat.VJD_STAT_OWN:
                NotifyStatusMessage(String.Format("vJoy Device {0} is already owned by this feeder", jID));
                break;

            case VjdStat.VJD_STAT_FREE:
                NotifyStatusMessage(String.Format("vJoy Device {0} is free", jID));
                break;

            case VjdStat.VJD_STAT_BUSY:
                NotifyStatusMessage(String.Format("vJoy Device {0} is already owned by another feeder. Cannot continue", jID));
                return;

            case VjdStat.VJD_STAT_MISS:
                NotifyStatusMessage(String.Format("vJoy Device {0} is not installed or disabled. Cannot continue", jID));
                return;

            default:
                NotifyStatusMessage(String.Format("vJoy Device {0} general error. Cannot continue", jID));
                return;
            }
            ;

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

            // Print results
            NotifyStatusMessage(String.Format("vJoy Device {0} capabilities:", jID));
            NotifyStatusMessage(String.Format("Numner of buttons\t{0}", nButtons));
            NotifyStatusMessage(String.Format("Numner of Continuous POVs\t{0}", ContPovNumber));
            NotifyStatusMessage(String.Format("Numner of Descrete POVs\t{0}", DiscPovNumber));
            NotifyStatusMessage(String.Format("Axis X\t\t{0}", AxisX ? "Yes" : "No"));
            NotifyStatusMessage(String.Format("Axis Y\t\t{0}", AxisX ? "Yes" : "No"));
            NotifyStatusMessage(String.Format("Axis Z\t\t{0}", AxisX ? "Yes" : "No"));
            NotifyStatusMessage(String.Format("Axis Rx\t\t{0}", AxisRX ? "Yes" : "No"));
            NotifyStatusMessage(String.Format("Axis Rz\t\t{0}", AxisRZ ? "Yes" : "No"));

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

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

            // Acquire the target
            if ((status == VjdStat.VJD_STAT_OWN) || (status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(jID)))
            {
                NotifyStatusMessage(String.Format("Failed to acquire vJoy device number {0}.", jID));
                return;
            }
            else
            {
                NotifyStatusMessage(String.Format("Acquired: vJoy device number {0}.", jID));
            }
        }
Esempio n. 10
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]);

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] != null && args[i] != "")
                {
                    switch (args[i][0])
                    {
                    case 'i':
                        if (!UInt32.TryParse(args[i].Substring(1, args[i].Length - 1), out id))
                        {
                            id = 1;
                        }
                        break;

                    case 's':
                        try
                        {
                            portname = args[i].Substring(1, args[i].Length - 1);
                        }
                        catch (Exception ex)
                        {
                            portname = "COM1";
                        }
                        break;

                    default:
                        break;
                    }
                }
            }

            Console.WriteLine("Command line arguments parsed.");
            //Console.ReadLine();

            if (id <= 0 || id > 16)
            {
                Console.WriteLine("Illegal device ID {0}\nExit!", id);
                Console.ReadLine();
                return;
            }

            string[] ports     = System.IO.Ports.SerialPort.GetPortNames();
            bool     portfound = false;

            for (int i = 0; i < ports.Length; i++)
            {
                Console.WriteLine(ports[i]);
                if (portname == ports[i])
                {
                    portfound = true;
                }
            }
            if (!portfound)
            {
                Console.WriteLine("Port {0} not found\nExit!", id);
                Console.ReadLine();
            }

            Console.WriteLine("Device ID and port name checked.");
            //Console.ReadLine();

            // Get the driver attributes (Vendor ID, Product ID, Version Number)
            if (!joystick.vJoyEnabled())
            {
                Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n");
                Console.ReadLine();
                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);
                Console.ReadLine();
                return;

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

            default:
                Console.WriteLine("vJoy Device {0} general error\nCannot continue\n", id);
                Console.ReadLine();
                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);
                Console.ReadLine();
                return;
            }
            else
            {
                Console.WriteLine("Acquired: vJoy device number {0}.\n", id);
            }

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

            Console.WriteLine("Feeding controller inputs...");

            //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);

            using (Process p = Process.GetCurrentProcess())
            {
                try
                {
                    p.PriorityClass = ProcessPriorityClass.RealTime;
                }
                catch (Exception ex1)
                {
                    Console.WriteLine("Failed to set realtime priority.");

                    try
                    {
                        p.PriorityClass = ProcessPriorityClass.High;
                    }
                    catch (Exception ex2)
                    {
                        Console.WriteLine("Failed to set high priority. Running at normal priority.");
                    }
                }

                p.ProcessorAffinity = (IntPtr)(1 << (Environment.ProcessorCount - 1));
            }

            byte[] oldinputs = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            byte[] cosinputs = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

            using (System.IO.Ports.SerialPort port = new System.IO.Ports.SerialPort(portname, 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One))
            {
                port.WriteTimeout = 1000;
                port.ReadTimeout  = 1000;
                port.Open();

                // Feed the device in endless loop
                while (true)
                {
                    byte[] inputs = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

                    try
                    {
                        byte[] test = new byte[1];

                        do
                        {
                            port.Read(test, 0, 1);
                        } while (test[0] != 0xFF);

                        for (int i = 0; i < 16; i++)
                        {
                            int inbyte;

                            do
                            {
                                inbyte = port.ReadByte();
                            }while (inbyte < 0);

                            inputs[i] = (byte)inbyte;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Exception reading joystick port: " + ex.Message);
                    }

                    //16 byte packet - supports 8 SNES-style controllers simultaneously
                    //2 byte - player 1
                    //2 byte - player 2
                    //2 byte - player 3
                    //2 byte - player 4
                    //2 byte - player 5
                    //2 byte - player 6
                    //2 byte - player 7
                    //2 byte - player 8

                    for (int i = 0; i < inputs.Length; i++)
                    {
                        cosinputs[i] = (byte)(inputs[i] ^ oldinputs[i]);

                        for (int j = 0; j < 8; j++)
                        {
                            //change: try to only send new status on change-of-state to reduce input events
                            if ((cosinputs[i] & (1 << j)) != 0)
                            {
                                res = joystick.SetBtn((inputs[i] & (1 << j)) != 0, id, (uint)(((i * 8) + j) + 1));
                            }
                        }
                    }

                    //copy current over old
                    oldinputs = inputs;
                } // While (Robust)
            }
        }         // Main
Esempio n. 11
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);
        }
        private void init(uint id)
        {
            this.id  = id;
            joystick = new vJoy();
            iReport  = new vJoy.JoystickState();

            // Device ID can only be in the range 1-16
            if (id <= 0 || id > 16)
            {
                err(String.Format("Illegal device ID {0} (1-16)", id));
            }

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

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

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

            case VjdStat.VJD_STAT_BUSY:
                err(String.Format("vJoy Device {0} is already owned by another feeder.", id));
                return;

            case VjdStat.VJD_STAT_MISS:
                err(String.Format("vJoy Device {0} is not installed or disabled.", id));
                return;

            default:
                err(String.Format("vJoy Device {0} general error.", 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:", id);
             * Console.WriteLine("Numner of buttons\t\t{0}", nButtons);
             * Console.WriteLine("Numner of Continuous POVs\t{0}", ContPovNumber);
             * Console.WriteLine("Numner of Descrete POVs\t\t{0}", DiscPovNumber);
             * Console.WriteLine("Axis X\t\t{0}", AxisX ? "Yes" : "No");
             * Console.WriteLine("Axis Y\t\t{0}", AxisX ? "Yes" : "No");
             * Console.WriteLine("Axis Z\t\t{0}", AxisX ? "Yes" : "No");
             * Console.WriteLine("Axis Rx\t\t{0}", AxisRX ? "Yes" : "No");
             * Console.WriteLine("Axis Rz\t\t{0}", 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})", DllVer);
            }
            else
            {
                Console.WriteLine("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})", DrvVer, DllVer);
            }
            // Acquire the target
            if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id))))
            {
                err(String.Format("Failed to acquire vJoy device number {0}.", id));
                return;
            }
            else
            {
                Console.WriteLine("Acquired: vJoy device number {0}.", id);
            }

            initAxes();
        }
Esempio n. 13
0
        public bool activateVJoy()
        {
            VjdStat status = joystick.GetVJDStatus(id);

            switch (status)
            {
            case VjdStat.VJD_STAT_OWN:
                context.logmMssage("vJoy Device " + id + " Connected Successfully");
                break;

            case VjdStat.VJD_STAT_FREE:
                context.logmMssage("vJoy Device " + id + " Connected Successfully");
                break;

            case VjdStat.VJD_STAT_BUSY:
                context.logmMssage("vJoy Device " + id + " is already owned by another feeder\nCannot continue\n");
                return(false);

            case VjdStat.VJD_STAT_MISS:
                context.logmMssage("vJoy Device is not installed or disabled\nCannot continue\n");
                return(false);

            default:
                context.logmMssage("vJoy Device general error\nCannot continue\n");
                return(false);
            }
            ;

            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
            nButtons      = joystick.GetVJDButtonNumber(id);
            ContPovNumber = joystick.GetVJDContPovNumber(id);
            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");


            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))))
            {
                context.logmMssage("Failed to acquire vJoy device number " + id);
                return(false);
            }
            else
            {
                context.logmMssage("Acquired: vJoy device number " + id);
            }

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

            Console.WriteLine("max val is: " + joyStickMaxval);

            iReport.bDevice = (byte)id;

            joystick.ResetVJD(id);


            OperateJoyStick(0, 0);
            operatePOV(0xFFFFFFFF);

            joystick.UpdateVJD(id, ref iReport);


            return(true);
        }
Esempio n. 14
0
        public void TestVjoy()
        {
            // Create one joystick object and a position structure.

            // Device ID can only be in the range 1-16
            if (_id <= 0 || _id > 16)
            {
                _logger.WriteLog($"Illegal device ID {_id}\nExit!");
                return;
            }

            // Get the driver attributes (Vendor ID, Product ID, Version Number)
            if (!_joystick.vJoyEnabled())
            {
                _logger.WriteLog($"vJoy driver not enabled: Failed Getting vJoy attributes.\n");
                return;
            }
            else
            {
                _logger.WriteLog($"Vendor: {_joystick.GetvJoyManufacturerString()}\nProduct :{_joystick.GetvJoyProductString()}\nVersion Number:{_joystick.GetvJoySerialNumberString()}\n");
            }

            // Get the state of the requested device
            VjdStat status = _joystick.GetVJDStatus(_id);

            switch (status)
            {
            case VjdStat.VJD_STAT_OWN:
                _logger.WriteLog($"vJoy Device {_id} is already owned by this feeder");
                break;

            case VjdStat.VJD_STAT_FREE:
                _logger.WriteLog($"vJoy Device {_id} is free");
                break;

            case VjdStat.VJD_STAT_BUSY:
                _logger.WriteLog($"vJoy Device {_id} is already owned by another feeder\nCannot continue");
                return;

            case VjdStat.VJD_STAT_MISS:
                _logger.WriteLog($"vJoy Device {_id} is not installed or disabled\nCannot continue");
                return;

            default:
                _logger.WriteLog($"vJoy Device {_id} general error\nCannot continue");
                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 switchessupported by this vJoy device
            int nButtons      = _joystick.GetVJDButtonNumber(_id);
            int ContPovNumber = _joystick.GetVJDContPovNumber(_id);
            int DiscPovNumber = _joystick.GetVJDDiscPovNumber(_id);

            // Print results
            _logger.WriteLog($"\nvJoy Device {_id} capabilities:");
            _logger.WriteLog($"Numner of buttons\t\t{nButtons}");
            _logger.WriteLog($"Numner of Continuous POVs\t{ContPovNumber}");
            _logger.WriteLog($"Numner of Descrete POVs\t\t{DiscPovNumber}");
            _logger.WriteLog($"Axis X\t\t{AxisX.ToString()}");
            _logger.WriteLog($"Axis Y\t\t{AxisY.ToString()}");
            _logger.WriteLog($"Axis Z\t\t{AxisZ.ToString()}");
            _logger.WriteLog($"Axis Rx\t\t{AxisRX.ToString()}");
            _logger.WriteLog($"Axis Ry\t\t{AxisRY.ToString()}");
            _logger.WriteLog($"Axis Rz\t\t{AxisRZ.ToString()}");

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

            if (match)
            {
                _logger.WriteLog($"Version of Driver Matches DLL Version ({DllVer:X})");
            }
            else
            {
                _logger.WriteLog($"Version of Driver ({DrvVer:X}) does NOT match DLL Version ({DllVer:X})");
            }

            // Acquire the target
            if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!_joystick.AcquireVJD(_id))))
            {
                _logger.WriteLog($"Failed to acquire vJoy device number {_id}");
                return;
            }
            else
            {
                _logger.WriteLog($"Acquired: vJoy device number {_id}");
            }

            _logger.WriteLog($"\npress enter to stat feeding");
        }
        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
        public TesterForm()
        {
            InitializeComponent();
            joystick = new vJoy();
            position = new vJoy.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;

            /////	vJoy Device properties
            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;

            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 vJoy 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);
        }
Esempio n. 17
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)
        }
Esempio n. 18
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);
                }
            }
        }
Esempio n. 19
0
 public int GetDeviceNumContPovs(uint deviceID)
 {
     return(joystick.GetVJDContPovNumber(deviceID));
 }
Esempio n. 20
0
        static void Main(string[] args)
        {
            // Create one joystick object and a position structure.
            joystick = new vJoy();
            iReport  = new vJoy.JoystickState();

            Verbose = args.Any(l => l.ToLower().Equals("v"));
            SerialStates.CenterInsensibility = args.Any(l => l.ToLower().Equals("i"));

            // Device ID can only be in the range 1-16
            if (args.Length > 1 && !String.IsNullOrEmpty(args[0]) && !String.IsNullOrEmpty(args[1]))
            {
                id         = Convert.ToUInt32(args[0]);
                serialLink = new SerialLink(Convert.ToInt32(args[1]));
            }
            else
            {
                Console.WriteLine($"Input parameter vJoy id and com port!");
                return;
            }
            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 AxisRY = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RY);
            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", AxisY ? "Yes" : "No");
            Console.WriteLine("Axis Z\t\t{0}\n", AxisZ ? "Yes" : "No");
            Console.WriteLine("Axis Rx\t\t{0}\n", AxisRX ? "Yes" : "No");
            Console.WriteLine("Axis Ry\t\t{0}\n", AxisRY ? "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);
            }



            joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref SerialStates.AxeMaxVal);

            serialLink.OpenPortAndRead();
        }
Esempio n. 21
0
        /**
         * Code is just reference from vJoy.
         */
        public void setupVjoy()
        {
            // 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())
            {
                writeMessage(String.Format("vJoy driver not enabled: Failed Getting vJoy attributes."));
                return;
            }
            else
            {
                writeMessage(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:
                writeMessage(String.Format("vJoy Device {0} is already owned by this feeder\n", id));
                break;

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

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

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

            default:
                writeMessage(String.Format("vJoy Device {0} general error\nCannot continue", 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
            nButtons      = joystick.GetVJDButtonNumber(id);
            ContPovNumber = joystick.GetVJDContPovNumber(id);
            DiscPovNumber = joystick.GetVJDDiscPovNumber(id);

            // Print results

            /*
             * writeMessage(String.Format("vJoy Device {0} capabilities:", id));
             * writeMessage(String.Format("Numner of buttons\t\t{0}", nButtons));
             * writeMessage(String.Format("Numner of Continuous POVs\t{0}", ContPovNumber));
             * writeMessage(String.Format("Numner of Descrete POVs\t\t{0}", DiscPovNumber));
             * writeMessage(String.Format("Axis X\t\t{0}", AxisX ? "Yes" : "No"));
             * writeMessage(String.Format("Axis Y\t\t{0}", AxisX ? "Yes" : "No"));
             * writeMessage(String.Format("Axis Z\t\t{0}", AxisX ? "Yes" : "No"));
             * writeMessage(String.Format("Axis Rx\t\t{0}", AxisRX ? "Yes" : "No"));
             * writeMessage(String.Format("Axis Rz\t\t{0}", 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);
            }


            maxval = 0;

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

            joystick.ResetAll();
        }
Esempio n. 22
0
        public void Init(string[] args)
        {
            // Create one joystick object and a position structure.
            joystick = new vJoy();
            iReport  = new vJoy.JoystickState();

            Console.WriteLine("App started\n");
            // 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)
            try
            {
                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());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString() + "\n====================================\n程序出现错误,即将退出");
                Console.ReadKey();
                return;
            }

            // 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", id);
                break;

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

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

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

            default:
                Console.WriteLine("vJoy Device {0} general error\nCannot continue", 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:", id);
            Console.WriteLine("Numner of buttons\t\t{0}", nButtons);
            Console.WriteLine("Numner of Continuous POVs\t{0}", ContPovNumber);
            Console.WriteLine("Numner of Descrete POVs\t\t{0}", DiscPovNumber);
            Console.WriteLine("Axis X\t\t{0}", AxisX ? "Yes" : "No");
            Console.WriteLine("Axis Y\t\t{0}", AxisX ? "Yes" : "No");
            Console.WriteLine("Axis Z\t\t{0}", AxisX ? "Yes" : "No");
            Console.WriteLine("Axis Rx\t\t{0}", AxisRX ? "Yes" : "No");
            Console.WriteLine("Axis Rz\t\t{0}", 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})", DllVer);
            }
            else
            {
                Console.WriteLine("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})", 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}.", id);
                return;
            }
            else
            {
                Console.WriteLine("Acquired: vJoy device number {0}.", id);
            }

            Console.WriteLine("虚拟手柄成功加载\n========================================");

            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);
            joystick.SetAxis(16384, id, HID_USAGES.HID_USAGE_Z);

            /*#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
             */
        }
Esempio n. 23
0
        public VJoyGlobalHolder(uint index)
        {
            Index              = index;
            Global             = new VJoyGlobal(this);
            setPressedStrategy = new SetPressedStrategy(b => SetButton(b, true), b => SetButton(b, false));

            joystick = new vJoy();
            if (index < 1 || index > 16)
            {
                throw new ArgumentException(string.Format("Illegal joystick device id: {0}", index));
            }

            if (!joystick.vJoyEnabled())
            {
                throw new Exception("vJoy driver not enabled: Failed Getting vJoy attributes");
            }

            uint apiVersion    = 0;
            uint driverVersion = 0;
            bool match         = joystick.DriverMatch(ref apiVersion, ref driverVersion);

            if (!match)
            {
                Console.WriteLine("vJoy version of Driver ({0:X}) does NOT match DLL Version ({1:X})", driverVersion, apiVersion);
            }

            Version = new VjoyVersionGlobal(apiVersion, driverVersion);

            var status = joystick.GetVJDStatus(index);


            string error = null;

            switch (status)
            {
            case VjdStat.VJD_STAT_BUSY:
                error = "vJoy Device {0} is already owned by another feeder";
                break;

            case VjdStat.VJD_STAT_MISS:
                error = "vJoy Device {0} is not installed or disabled";
                break;

            case VjdStat.VJD_STAT_UNKN:
                error = ("vJoy Device {0} general error");
                break;
            }

            if (error == null && !joystick.AcquireVJD(index))
            {
                error = "Failed to acquire vJoy device number {0}";
            }

            if (error != null)
            {
                throw new Exception(string.Format(error, index));
            }

            long max = 0;

            joystick.GetVJDAxisMax(index, HID_USAGES.HID_USAGE_X, ref max);
            AxisMax = (int)max / 2 - 1;

            enabledAxis = new Dictionary <HID_USAGES, bool>();
            foreach (HID_USAGES axis in Enum.GetValues(typeof(HID_USAGES)))
            {
                enabledAxis[axis] = joystick.GetVJDAxisExist(index, axis);
            }

            maxButtons       = joystick.GetVJDButtonNumber(index);
            maxDirPov        = joystick.GetVJDDiscPovNumber(index);
            maxContinuousPov = joystick.GetVJDContPovNumber(index);

            currentAxisValue = new Dictionary <HID_USAGES, int>();

            joystick.ResetVJD(index);
        }
Esempio n. 24
0
        static public int InitializeFeeder(/*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(-1);
            }

            // 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(-1);
            }
            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;
                return(-1);

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

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

            // 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;
                return(-1);
            }
            else
            {
                Console.WriteLine("Acquired: vJoy device number {0}.\n", id);
                stat = "On!";
            }

            joystick.ResetVJD(id);

            return(0);
        }
Esempio n. 25
0
        public static bool VjoyStart()
        {
            //string[] args = Environment.GetCommandLineArgs();
            //Create one joystick object and a position structure.
            joystick = new vJoy();
            iReport  = new vJoy.JoystickState();
            joystick.ResetVJD(id);

            // 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)
            {
                Debug.Log(string.Format("Illegal device ID {0}\nExit!", id));
                return(false);
            }

            // Get the driver attributes (Vendor ID, Product ID, Version Number)
            if (!joystick.vJoyEnabled())
            {
                Debug.Log(string.Format("vJoy driver not enabled: Failed Getting vJoy attributes.\n"));
                return(false);
            }
            else
            {
                Debug.Log(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:
                Debug.Log(string.Format("vJoy Device {0} is already owned by this feeder\n", id));
                break;

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

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

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

            default:
                Debug.Log(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 switchessupported by this vJoy device
            int nButtons      = joystick.GetVJDButtonNumber(id);
            int ContPovNumber = joystick.GetVJDContPovNumber(id);
            int DiscPovNumber = joystick.GetVJDDiscPovNumber(id);

            // Print results
            Debug.Log(string.Format("\nvJoy Device {0} capabilities:\n", id));
            Debug.Log(string.Format("Numner of buttons\t\t{0}\n", nButtons));
            Debug.Log(string.Format("Numner of Continuous POVs\t{0}\n", ContPovNumber));
            Debug.Log(string.Format("Numner of Descrete POVs\t\t{0}\n", DiscPovNumber));
            Debug.Log(string.Format("Axis X\t\t{0}\n", AxisX ? "Yes" : "No"));
            Debug.Log(string.Format("Axis Y\t\t{0}\n", AxisX ? "Yes" : "No"));
            Debug.Log(string.Format("Axis Z\t\t{0}\n", AxisX ? "Yes" : "No"));
            Debug.Log(string.Format("Axis Rx\t\t{0}\n", AxisRX ? "Yes" : "No"));
            Debug.Log(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)
            {
                Debug.Log(string.Format("Version of Driver Matches DLL Version ({0:X})\n", DllVer));
            }
            else
            {
                Debug.Log(string.Format("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})\n", DrvVer, DllVer));
            }


            // Acquire the target
            bool stat = ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE)));
            bool acq  = (!joystick.AcquireVJD(id));

            if (stat && acq)
            {
                Debug.Log(string.Format("Failed to acquire vJoy device number {0}.\n", id));
                return(false);
            }
            else
            {
                Debug.Log(string.Format("Acquired: vJoy device number {0}.\n", id));
            }

            //Debug.Log(string.Format("\npress enter to stat feeding");
            //Console.ReadKey(true);
            return(true);
        } // Main
Esempio n. 26
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
Esempio n. 27
0
        public void Init(MainForm parent)
        {
            mainForm = parent;
            ClearDevices();
            // Create one joystick object and a position structure.
            input       = new DirectInput();
            joystick    = new vJoy();
            iReport     = new vJoy.JoystickState();
            vjoyEnabled = false;


            // Get the driver attributes (Vendor ID, Product ID, Version Number)
            if (!joystick.vJoyEnabled())
            {
                MessageBox.Show("vJoy driver not enabled: Failed Getting vJoy attributes.\n", "Error");
                return;
            }

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

            switch (status)
            {
            case VjdStat.VJD_STAT_OWN:
            case VjdStat.VJD_STAT_FREE:
                break;

            case VjdStat.VJD_STAT_BUSY:
                MessageBox.Show("vJoy Device is already owned by another feeder. Cannot continue", "Error");
                return;

            case VjdStat.VJD_STAT_MISS:
                MessageBox.Show("vJoy Device is not installed or disabled. Cannot continue", "Error");
                return;

            default:
                MessageBox.Show("vJoy Device general error. Cannot continue", "Error");
                return;
            }
            ;

            // Make sure all needed axes and buttons are supported
            bool AxisX         = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X);
            bool AxisY         = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y);
            bool AxisRX        = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX);
            bool AxisRZ        = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RZ);
            int  nButtons      = joystick.GetVJDButtonNumber(id);
            int  ContPovNumber = joystick.GetVJDContPovNumber(id);

            if (!AxisX || !AxisY || !AxisRX || !AxisRZ || nButtons < 28 || ContPovNumber < 3)
            {
                MessageBox.Show("vJoy Device is not configured correctly. Must have X,Y,Rx,Ry analog axis, 28 buttons and 3 Analog POVs. Cannot continue\n", "Error");
                return;
            }

            if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id))))
            {
                MessageBox.Show("Failed to acquire vJoy device number", "Error");
                return;
            }

            long maxval = 0;

            joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval);
            axisScale = (double)maxval / 65536.0;
            mainForm.LblVjoyStat.Text = "Found. Ver: " + joystick.GetvJoySerialNumberString();
            vjoyEnabled = true;
        }
Esempio n. 28
0
        public Form1()
        {
            InitializeComponent();


            // ******************************************* **** *********************************************
            // **************************************** start_Vjoy ******************************************
            // ******************************************* **** *********************************************


            // Create one joystick object and a position structure.
            joystick = new vJoy();
            iReport  = new vJoy.JoystickState();


            // 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 AxisRY = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RY);
            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("Number of buttons\t\t{0}\n", nButtons);
            Console.WriteLine("Number of Continuous POVs\t{0}\n", ContPovNumber);
            Console.WriteLine("Number 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", AxisY ? "Yes" : "No");
            Console.WriteLine("Axis Z\t\t{0}\n", AxisZ ? "Yes" : "No");
            Console.WriteLine("Axis Rx\t\t{0}\n", AxisRX ? "Yes" : "No");
            Console.WriteLine("Axis Rx\t\t{0}\n", AxisRY ? "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);
            }

            joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxvalue);
            Console.WriteLine("Max value X: {0}.\n", maxvalue);
            joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_Y, ref maxvalue);
            Console.WriteLine("Max value Y: {0}.\n", maxvalue);
            joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_RX, ref maxvalue);
            Console.WriteLine("Max value RX: {0}.\n", maxvalue);
            joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_RY, ref maxvalue);
            Console.WriteLine("Max value RY: {0}.\n", maxvalue);

            joystick.GetVJDAxisMin(id, HID_USAGES.HID_USAGE_X, ref minvalue);
            Console.WriteLine("Min value X: {0}.\n", minvalue);
            joystick.GetVJDAxisMin(id, HID_USAGES.HID_USAGE_Y, ref minvalue);
            Console.WriteLine("Min value Y: {0}.\n", minvalue);
            joystick.GetVJDAxisMin(id, HID_USAGES.HID_USAGE_RX, ref minvalue);
            Console.WriteLine("Min value RX: {0}.\n", minvalue);
            joystick.GetVJDAxisMin(id, HID_USAGES.HID_USAGE_RY, ref minvalue);
            Console.WriteLine("Min value RY: {0}.\n", minvalue);

            this.minValJOY.Text = minvalue.ToString();
            this.maxValJOY.Text = maxvalue.ToString();

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

            yawProg.Minimum    = (int)minvalue;
            yawProg.Maximum    = (int)maxvalue;
            rollProg.Minimum   = (int)minvalue;
            rollProg.Maximum   = (int)maxvalue;
            pitchProg.Minimum  = (int)minvalue;
            pitchProg.Maximum  = (int)maxvalue;
            heightProg.Minimum = (int)minvalue;
            heightProg.Maximum = (int)maxvalue;

            rollChart.ChartAreas[0].AxisY.Maximum   = maxvalue;
            rollChart.ChartAreas[0].AxisY.Minimum   = minvalue;
            pitchChart.ChartAreas[0].AxisY.Maximum  = maxvalue;
            pitchChart.ChartAreas[0].AxisY.Minimum  = minvalue;
            heightChart.ChartAreas[0].AxisY.Maximum = maxvalue;
            heightChart.ChartAreas[0].AxisY.Minimum = minvalue;
            yawChart.ChartAreas[0].AxisY.Maximum    = maxvalue;
            yawChart.ChartAreas[0].AxisY.Minimum    = minvalue;

            myCircularBuff = new CircularBuffer <HandValue>(2000);

            myLog = new Logger();

            t = new Thread(joyThread);
            t.Start();

            tS = new Thread(serialThread);
            tS.Start();

            // ******************************************* **** *********************************************
            // ***************************************** end_Vjoy *******************************************
            // ******************************************* **** *********************************************

            controller.EventContext        = WindowsFormsSynchronizationContext.Current;
            controller.FrameReady         += newFrameHandler;
            controller.ImageReady         += onImageReady;
            controller.ImageRequestFailed += onImageRequestFailed;

            //set greyscale palette for image Bitmap object
            ColorPalette grayscale = bitmap.Palette;

            for (int i = 0; i < 256; i++)
            {
                grayscale.Entries[i] = Color.FromArgb((int)255, i, i, i);
            }
            bitmap.Palette = grayscale;
        }
Esempio n. 29
0
        public void Feed(PhoneData data)
        {
            // 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);



            long maxval = 0;

            _joystick.GetVJDAxisMax(_id, HID_USAGES.HID_USAGE_X, ref maxval);

            _axisX = data.AxisX; if (_axisX > maxval)
            {
                _axisX = (int)maxval;
            }
            if (_axisX < 0)
            {
                _axisX = 0;
            }
            _axisY = data.AxisY; if (_axisY > maxval)
            {
                _axisY = (int)maxval;
            }
            if (_axisY < 0)
            {
                _axisY = 0;
            }
            _axisZ = data.AxisZ; if (_axisZ > maxval)
            {
                _axisZ = (int)maxval;
            }
            if (_axisZ < 0)
            {
                _axisZ = 0;
            }

            uint count = 0;

            byte[] pov = new byte[4];

            _joystickState.bDevice = (byte)_id;
            _joystickState.AxisX   = _axisX;
            _joystickState.AxisY   = _axisY;
            _joystickState.AxisZ   = _axisZ;

            var btn1 = data.Button1 == 0 ? 0 : 1;
            var btn2 = data.Button2 == 0 ? 0 : 2;
            var btn3 = data.Button3 == 0 ? 0 : 4;
            var btn4 = data.Button4 == 0 ? 0 : 8;

            _joystickState.Buttons = (uint)(btn1 | btn2 | btn3 | btn4);

            if (contPovNumber > 0)
            {
                _joystickState.bHats    = 0xFFFFFFFF;  // Neutral state
                _joystickState.bHatsEx1 = 0xFFFFFFFF;  // Neutral state
                _joystickState.bHatsEx2 = 0xFFFFFFFF;  // Neutral state
                _joystickState.bHatsEx3 = 0xFFFFFFFF;  // Neutral state
            }
            else
            {
                _joystickState.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 _joystickState))
            {
                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;
            }
        }
Esempio n. 30
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
        }