Exemplo n.º 1
0
        public static void setJoystick(ref vJoy joystick, ControllerState input, uint joystickID, ControllerDeadZones deadZones)
        {
            bool res;
            var multiplier = 127;

            if (!deadZones.analogStick.inDeadZone(input.StickX, input.StickY))
            {
                res = joystick.SetAxis(multiplier * input.StickX, joystickID, HID_USAGES.HID_USAGE_X);
                res = joystick.SetAxis(multiplier * (255 - input.StickY), joystickID, HID_USAGES.HID_USAGE_Y);
            }
            else
            {
                res = joystick.SetAxis(multiplier * 129, joystickID, HID_USAGES.HID_USAGE_X);
                res = joystick.SetAxis(multiplier * 129, joystickID, HID_USAGES.HID_USAGE_Y);
            }
            
            if (!deadZones.cStick.inDeadZone(input.CX, input.CY))
            {
                res = joystick.SetAxis(multiplier * input.CX, joystickID, HID_USAGES.HID_USAGE_RX);
                res = joystick.SetAxis(multiplier * (255 - input.CY), joystickID, HID_USAGES.HID_USAGE_RY);
            }
            else
            {
                res = joystick.SetAxis(multiplier * 129, joystickID, HID_USAGES.HID_USAGE_RX);
                res = joystick.SetAxis(multiplier * 129, joystickID, HID_USAGES.HID_USAGE_RY);
            }
            
            if (!deadZones.LTrigger.inDeadZone(input.LAnalog))
            {
                res = joystick.SetAxis(multiplier * input.LAnalog, joystickID, HID_USAGES.HID_USAGE_Z);
            }
            else
            {
                res = joystick.SetAxis(0, joystickID, HID_USAGES.HID_USAGE_Z);
            }
            if (!deadZones.RTrigger.inDeadZone(input.RAnalog))
            {
                res = joystick.SetAxis(multiplier * input.RAnalog, joystickID, HID_USAGES.HID_USAGE_RZ);
            }
            else
            {
                res = joystick.SetAxis(0, joystickID, HID_USAGES.HID_USAGE_RZ);
            }

            //dpad button mode for DDR pad support
            res = joystick.SetBtn(input.DUp, joystickID, 9);
            res = joystick.SetBtn(input.DDown, joystickID, 10);
            res = joystick.SetBtn(input.DLeft, joystickID, 11);
            res = joystick.SetBtn(input.DRight, joystickID, 12);

            //buttons
            res = joystick.SetBtn(input.A, joystickID, 1);
            res = joystick.SetBtn(input.B, joystickID, 2);
            res = joystick.SetBtn(input.X, joystickID, 3);
            res = joystick.SetBtn(input.Y, joystickID, 4);
            res = joystick.SetBtn(input.Z, joystickID, 5);
            res = joystick.SetBtn(input.RDigital, joystickID, 6);
            res = joystick.SetBtn(input.LDigital, joystickID, 7);
            res = joystick.SetBtn(input.Start, joystickID, 8);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
 public override void Init()
 {
     minMaxAxis = new Dictionary<HID_USAGES, int[]>();
     lastValue = new Dictionary<HID_USAGES, int>();
     isAcquired = false;
     _joystick = new vJoy();
 }
Exemplo n.º 4
0
 /// <summary>
 /// Finds and updates a state of joystick identified and authorized by token.
 /// </summary>
 /// <param name="joyState">Struct with updated values of joystick axes, buttons, etc.</param>
 /// <param name="token">Authorizes the request</param>
 public void PostCurrentJoystickState(vJoy.JoystickState joyState, Guid token)
 {
     foreach (var joy in _joystics.Where(joy => joy.IsBusy && joy.Capabilities.Token == token))
     {
         joy.PostCurrentState(joyState);
         return;
     }
 }
Exemplo n.º 5
0
        public JoystickFeeder()
        {
            _joy = new vJoy();
            joystickStates = new ConcurrentDictionary<uint, JoystickAxisState>();

            _joy.GetVJDAxisMax(1, HID_USAGES.HID_USAGE_X, ref maxval);
            percentage = maxval / 100;
        }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a new instance of joystick
 /// </summary>
 /// <param name="joyId">Id of simulated joystick between (1,16). It have to exists in system before the invokation.</param>
 public JoyControl(uint joyId)
 {
     if(!joyId.Between(1,16, true))
         throw new Exception(String.Format("Illegal device ID {0}", joyId));
     IsBusy = false;
     _joyId = joyId;
     _joystick = new vJoy();
 }
Exemplo n.º 7
0
 //feeder application constructor, setup joystick instance and acquire the joystick driver installed on machine.
 public vJoyFeeder()
 {
     joystick = new vJoyInterfaceWrap.vJoy();
     // if there is a missing .dll error here, make sure both vJoyInterface.dll and vJoyInterfaceWrap.dll is added to the project and also added
     // in the same folder as the debug or release .exe, often times only the vJoyInterfaceWrap.dll is there.
     bool result = joystick.AcquireVJD(id); // this is the code that actually acquires the driver
     inputRawCoords(0.0, 0.0);// set default coordinates upon construction
 }
Exemplo n.º 8
0
        //feeder application constructor, setup joystick instance and acquire the joystick driver installed on machine.
        public vJoyFeeder()
        {
            joystick = new vJoyInterfaceWrap.vJoy();

            // if there is a missing .dll error here, make sure both vJoyInterface.dll and vJoyInterfaceWrap.dll is added to the project and also added
            // in the same folder as the debug or release .exe, often times only the vJoyInterfaceWrap.dll is there.
            joystick.AcquireVJD(id);  // this is the code that actually acquires the driver
            inputRawCoords(0.0, 0.0); // set default coordinates upon construction
        }
Exemplo n.º 9
0
 public vJoyVibrate(vJoy parVJoy)
 {
     joystick = parVJoy;
     for (int x = 1; x <= SCPConstants.MAX_XINPUT_DEVICES; x++)
     {
         devices[x - 1] = new FFBDevice();
         devices[x - 1].ClearBlocks();
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Updates a state of joystick (values of buttons, axes, etc.) using a JoystickState struct
        /// </summary>
        /// <param name="joyState">Struct storing updated values of joystick state</param>
        public void PostCurrentState(vJoy.JoystickState joyState)
        {
            if(!IsBusy)
                throw new Exception("You cannot change a state of a joystick which isn't connected.");

            if (!_joystick.UpdateVJD(_joyId, ref joyState))
            {
                Disconnect();
            }
        }
Exemplo n.º 11
0
        static void Main()
        {
            Joystick = new vJoy();

            if (!Joystick.vJoyEnabled())
            {
                MessageBox.Show("vJoy is not enabled. You'll need to install vJoy before you can use this program.", "MIDIFeeder", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
Exemplo n.º 12
0
        public static IEnumerable <uint> GetFreeIds(this vJoy vjoy)
        {
            var result = new List <uint>();

            for (uint i = 1; i <= MaxVJoyId; i++)
            {
                if (vjoy.GetVJDStatus(i) == VjdStat.VJD_STAT_FREE)
                {
                    result.Add(i);
                }
            }

            return(result);
        }
Exemplo n.º 13
0
        public FfbInterface(TesterForm dialog)
        {
            dlg = dialog;
            joystick = dialog.joystick;
            // FFB
            #if false
            #pragma warning disable 0618
            if (!joystick.FfbStart(id))
                throw new Exception(String.Format("Failed to start Forcefeedback on device {0}", id));
            #pragma warning restore 0618

            // Convert Form to pointer and pass it as user data to the callback function
            GCHandle h = GCHandle.Alloc(dialog);
            IntPtr parameter = (IntPtr)h;
            // joystick.FfbRegisterGenCB(OnEffect, parameter);
            joystick.FfbRegisterGenCB(OnEffectObj, dialog);
             #endif
        }
Exemplo n.º 14
0
        public InputHandler()
        {
            player1 = new vJoy();
            player2 = new vJoy();
            ///// Write access to vJoy Device - Basic
            VjdStat status = player1.GetVJDStatus(1);

            // Acquire the target
            string prt;
            if ((status == VjdStat.VJD_STAT_OWN) ||
            ((status == VjdStat.VJD_STAT_FREE) && (!player1.AcquireVJD(1))))
                prt = String.Format("Failed to acquire vJoy device number {0}.", 1);
            else
                prt = String.Format("Acquired: vJoy device number {0}.", 1);
            MessageBox.Show(prt);

            status = player2.GetVJDStatus(2);

            // Acquire the target
            if ((status == VjdStat.VJD_STAT_OWN) ||
            ((status == VjdStat.VJD_STAT_FREE) && (!player2.AcquireVJD(2))))
                prt = String.Format("Failed to acquire vJoy device number {0}.", 2);
            else
                prt = String.Format("Acquired: vJoy device number {0}.", 2);

            MessageBox.Show(prt);
            usersList = new Dictionary<string, uint>();
            commands = new Dictionary<string, Delegate>();
            commands["left"] = new Func<uint, vJoy,  bool>(Left);
            commands["right"] = new Func<uint, vJoy, bool>(Right);
            commands["up"] = new Func<uint, vJoy, bool>(Up);
            commands["down"] = new Func<uint, vJoy, bool>(Down);
            commands["a"] = new Func<uint, vJoy, bool>(A);
            commands["b"] = new Func<uint, vJoy, bool>(B);
            commands["start"] = new Func<uint, vJoy, bool>(Start);
            commands["c1"] = commands["z"] = new Func<uint, vJoy, bool>(C1);
            commands["c2"] = new Func<uint, vJoy, bool>(C2);
            commands["c3"] = new Func<uint, vJoy, bool>(C3);
            commands["c4"] = new Func<uint, vJoy, bool>(C4);
            commands["rb"] = new Func<uint, vJoy, bool>(RB);
            commands["lb"] = new Func<uint, vJoy, bool>(LB);
            commands["none"] = new Func<uint, vJoy, bool>(None);
        }
Exemplo n.º 15
0
        public Gamepad()
        {
            vjoy = new vJoy();

            if (!vjoy.vJoyEnabled())
            {
                throw new System.IO.IOException("Failed to get vJoy device, driver not enabled?");
            }

            vjoyID = findAvailableDeviceID();
            bool gotDevice = vjoy.AcquireVJD(vjoyID);

            if (!gotDevice)
            {
                throw new System.IO.IOException("Failed to get vJoy device " + vjoyID);
            }

            releaseAll();

            rng = new Random();
        }
Exemplo n.º 16
0
        public static bool checkJoystick(ref vJoy joystick, uint id)
        {
            bool checker = false;
            if (joystick.vJoyEnabled())
            {
                VjdStat status = joystick.GetVJDStatus(id);

                switch (status)
                {
                    case VjdStat.VJD_STAT_OWN:
                        JoystickLog(null, new Logging.LogEventArgs($"Port {id} is already owned by this feeder (OK)."));
                        checker = true;
                        break;
                    case VjdStat.VJD_STAT_FREE:
                        JoystickLog(null, new Logging.LogEventArgs($"Port {id} is detected (OK)."));
                        checker = true;
                        break;
                    case VjdStat.VJD_STAT_BUSY:
                        JoystickLog(null, new Logging.LogEventArgs(
                            $"Port {id} is already owned by another feeder, cannot continue."));
                        checker = false;
                        return checker;
                    case VjdStat.VJD_STAT_MISS:
                        JoystickLog(null, new Logging.LogEventArgs($"Port {id} is not detected."));
                        checker = false;
                        return checker;
                    default:
                        JoystickLog(null, new Logging.LogEventArgs($"Port {id} general error, cannot continue."));
                        checker = false;
                        return checker;
                }

                //fix missing buttons, if the count is off.
                if (joystick.GetVJDButtonNumber(id) != 12)
                {
                    SystemHelper.CreateJoystick(id);
                }
            }
            return checker;
        }
Exemplo n.º 17
0
        public double DeadZone; //0 to 1

        #endregion Fields

        #region Methods

        public override void Apply(ref vJoy.JoystickState state)
        {
            double axis = 0;
            double maxValue = 0;
            switch (AType)
            {
                case AxisType.Stick:
                    axis = GetValue(ref state, Axis) - vJoyConstants.HALF_AXIS_VALUE - 0.5;
                    maxValue = vJoyConstants.HALF_AXIS_VALUE + 0.5;
                    break;
                case AxisType.Trigger:
                    axis = GetValue(ref state, Axis);
                    maxValue = vJoyConstants.MAX_AXIS_VALUE;
                    break;
            }

            double acturalDeadZone = maxValue * DeadZone;

            if (Math.Abs(axis) < acturalDeadZone)
            {
                axis = 0;
            }
            else
            {
                if (axis > 0)
                    axis = maxValue * ((axis - acturalDeadZone) / (maxValue - acturalDeadZone));
                else
                    axis = maxValue * ((axis + acturalDeadZone) / (maxValue - acturalDeadZone));
            }
            switch (AType)
            {
                case AxisType.Stick:
                    axis += vJoyConstants.HALF_AXIS_VALUE + 0.5;
                    break;
                case AxisType.Trigger:
                    break;
            }
            SetValue(ref state, Axis, (int)axis);
        }
Exemplo n.º 18
0
 protected int GetValue(ref vJoy.JoystickState joyReport, HID_USAGES hid)
 {
     switch (hid)
     {
         case HID_USAGES.HID_USAGE_X:
             return joyReport.AxisX;
         case HID_USAGES.HID_USAGE_Y:
             return joyReport.AxisY;
         case HID_USAGES.HID_USAGE_Z:
             return joyReport.AxisZ;
         case HID_USAGES.HID_USAGE_RX:
             return joyReport.AxisXRot;
         case HID_USAGES.HID_USAGE_RY:
             return joyReport.AxisYRot;
         case HID_USAGES.HID_USAGE_RZ:
             return joyReport.AxisZRot;
         case HID_USAGES.HID_USAGE_SL0:
             return joyReport.Slider;
         case HID_USAGES.HID_USAGE_SL1:
             return joyReport.Dial;
         default:
             return 0;
     }
 }
Exemplo n.º 19
0
        //initializer
        public JoyControl()
        {
            joystick = new vJoy();

            iReport = new vJoy.JoystickState();
            if (!joystick.vJoyEnabled())
            {
                sta="vJoy driver not enabled: Failed Getting vJoy attributes.";
                return;
            }
            else
                sta= "Vendor: " + joystick.GetvJoyManufacturerString() + "\nProduct :" + joystick.GetvJoyProductString() + "\nVersion Number:" + joystick.GetvJoySerialNumberString();

            iReport.AxisXRot = 16500;
            iReport.AxisYRot = 16500;
            iReport.AxisZRot = 16500;
            iReport.AxisX = 16500;
            iReport.AxisY = 16500;
            iReport.AxisZ = 16500;
            if (!joystick.UpdateVJD(id, ref iReport))
            {
                joystick.AcquireVJD(id);
            }
        }
Exemplo n.º 20
0
 private bool Down(uint player, vJoy playa)
 {
     return playa.SetDiscPov(2, player, 1);
 }
Exemplo n.º 21
0
 private bool Up(uint player, vJoy playa)
 {
     return playa.SetDiscPov(0, player, 1);
 }
Exemplo n.º 22
0
 private bool Start(uint player, vJoy playa)
 {
     return playa.SetBtn(true, player, 5);
 }
Exemplo n.º 23
0
 private bool Right(uint player, vJoy playa)
 {
     return playa.SetDiscPov(1, player, 1);
 }
Exemplo n.º 24
0
        private void Reset(uint player, vJoy playa)
        {
            bool code = false;
            code = playa.SetDiscPov(-1, player, 2);
            for (uint i = 1; i <= 5; i++)
                code = playa.SetBtn(false, player, i);

            System.Threading.Thread.Sleep(50);
        }
Exemplo n.º 25
0
 private bool RB(uint player, vJoy playa)
 {
     return playa.SetBtn(true, player, 3);
 }
Exemplo n.º 26
0
        private vJoy initVjoy(uint id)
        {
            var joystick = new vJoy();
            var iReport = new vJoy.JoystickState();

            // Get the state of the requested device
            VjdStat status = joystick.GetVJDStatus(id);
            /*switch (status)
            {
                case VjdStat.VJD_STAT_OWN:
                    MessageBox.Show(string.Format("vJoy Device {0} is already owned by this feeder\n", id));
                    break;
                case VjdStat.VJD_STAT_FREE:
                    MessageBox.Show(string.Format("vJoy Device {0} is free\n", id));
                    break;
                case VjdStat.VJD_STAT_BUSY:
                    MessageBox.Show(string.Format("vJoy Device {0} is already owned by another feeder\nCannot continue\n", id));
                    return joystick;
                case VjdStat.VJD_STAT_MISS:
                    MessageBox.Show(string.Format("vJoy Device {0} is not installed or disabled\nCannot continue\n", id));
                    return joystick;
                default:
                    MessageBox.Show(string.Format("vJoy Device {0} general error\nCannot continue\n", id));
                    return joystick;
            }*/
            bool AxisX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X);
            if (joystick.AcquireVJD(id) == false)
                MessageBox.Show("Could not acquire vJoy " + id);
            Console.WriteLine(AxisX);
            return joystick;
        }
Exemplo n.º 27
0
 private bool C4(uint player, vJoy playa)
 {
     return playa.SetDiscPov(2, player, 2);
 }
Exemplo n.º 28
0
        public void Initialize()
        {
            // 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(deviceId);
            switch (status)
            {
                case VjdStat.VJD_STAT_OWN:
                    Console.WriteLine("vJoy Device {0} is already owned by this feeder\n", deviceId);
                    break;
                case VjdStat.VJD_STAT_FREE:
                    Console.WriteLine("vJoy Device {0} is free\n", deviceId);
                    break;
                case VjdStat.VJD_STAT_BUSY:
                    Console.WriteLine("vJoy Device {0} is already owned by another feeder\nCannot continue\n", deviceId);
                    return;
                case VjdStat.VJD_STAT_MISS:
                    Console.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue\n", deviceId);
                    return;
                default:
                    Console.WriteLine("vJoy Device {0} general error\nCannot continue\n", deviceId);
                    return;
            };

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

            // Print results
            Console.WriteLine("\nvJoy Device {0} capabilities:\n", deviceId);
            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);

            System.Threading.Thread.Sleep(500);

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

            joystick.GetVJDAxisMax(deviceId, HID_USAGES.HID_USAGE_X, ref xMaxVal);
            joystick.GetVJDAxisMin(deviceId, HID_USAGES.HID_USAGE_X, ref xMinVal);
            joystick.GetVJDAxisMax(deviceId, HID_USAGES.HID_USAGE_Y, ref yMaxVal);
            joystick.GetVJDAxisMin(deviceId, HID_USAGES.HID_USAGE_Y, ref yMinVal);
        }
Exemplo n.º 29
0
 public JoystickOutput()
 {
     int id = 1;
     ID = (uint)id;
     joy = initVjoy(ID);
 }
Exemplo n.º 30
0
 private bool Left(uint player, vJoy playa)
 {
     return playa.SetDiscPov(3, player, 1);
 }
Exemplo n.º 31
0
        static void Main(string[] args)
        {
            try
            {
                joystick = new vJoy();
                iReport = new vJoy.JoystickState();
            }
            catch
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("vJoy error,please reinstall vjoy.");
                return;
            }

            if (!joystick.vJoyEnabled())
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n");
                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\n", id);
                    break;
                case VjdStat.VJD_STAT_FREE:
                    Console.WriteLine("vJoy Device {0} is free\n", id);
                    break;
                case VjdStat.VJD_STAT_BUSY:
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("vJoy Device {0} is already owned by another feeder\nCannot continue\n", id);
                    return;
                case VjdStat.VJD_STAT_MISS:
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue\n", id);
                    return;
                default:
                    Console.ForegroundColor = ConsoleColor.Red;
                    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_RX);
            bool AxisRZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RZ);
            bool AxisSL0 = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_SL0);
            bool AxisSL1 = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_SL1);
            // 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("vJoy Device {0}", id);
            Console.WriteLine("Checking...Numner of buttons\t\t{0}\tPass", nButtons);
            Console.WriteLine("Checking...Numner of Continuous POVs\t{0}\tPass", ContPovNumber);
            Console.WriteLine("Checking...Numner of Descrete POVs\t{0}\tPass", DiscPovNumber);
            if (ContPovNumber > DiscPovNumber)
                isPovCon = true;
            Console.WriteLine("Checking...Axis X\t\t\t{0}\tPass", AxisX ? "Yes" : "No");
            Console.WriteLine("Checking...Axis Y\t\t\t{0}\tPass", AxisX ? "Yes" : "No");
            Console.WriteLine("Checking...Axis Z\t\t\t{0}\tPass", AxisX ? "Yes" : "No");
            Console.WriteLine("Checking...Axis Rx\t\t\t{0}\tPass", AxisRX ? "Yes" : "No");
            Console.WriteLine("Checking...Axis Ry\t\t\t{0}\tPass", AxisRY ? "Yes" : "No");
            Console.WriteLine("Checking...Axis Rz\t\t\t{0}\tPass", AxisRZ ? "Yes" : "No");
            Console.WriteLine("Checking...Axis SL0\t\t\t{0}\tPass", AxisSL0 ? "Yes" : "No");
            Console.WriteLine("Checking...Axis SL1\t\t\t{0}\tPass", AxisSL1 ? "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("Checking...Version of Driver Matches DLL Version ({0:X})\n", DllVer);
            else
                Console.WriteLine("Checking...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.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Failed to acquire vJoy device number {0}.\n", id);
                return;
            }
            else
                Console.WriteLine("Acquired: vJoy device number {0}.\n", id);

            joystick.ResetAll();
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("System All Green.Now Start...");
            Console.ForegroundColor = ConsoleColor.White;

            readConfig();
            printHello();

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

            UdpState axisUdpState = new UdpState();
            axisUdpState.ipEndPoint = new IPEndPoint(IPAddress.Any, AxisPort);
            axisUdpState.udpClient = new UdpClient(AxisPort);
            axisUdpState.udpClient.BeginReceive(AxisUDPRecieved, axisUdpState);

            UdpState ctlUdpState = new UdpState();
            ctlUdpState.ipEndPoint = new IPEndPoint(IPAddress.Any, CtlPort);
            ctlUdpState.udpClient = new UdpClient(CtlPort);
            ctlUdpState.udpClient.BeginReceive(CtlUDPRecieved, ctlUdpState);

            try
            {
                NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
                foreach (NetworkInterface adapter in nics)
                {
                    if (adapter.OperationalStatus != OperationalStatus.Up) //filter unavaliable interface
                        continue;
                    if (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet | adapter.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)
                    {
                        IPInterfaceProperties ip = adapter.GetIPProperties();
                        UnicastIPAddressInformationCollection ipCollection = ip.UnicastAddresses;
                        foreach (UnicastIPAddressInformation ipadd in ipCollection)
                        {
                            if (ipadd.Address.AddressFamily == AddressFamily.InterNetwork)
                                //判断是否为ipv4
                                Console.WriteLine(adapter.Name + " : " + ipadd.Address.ToString());//获取ip
                        }
                    }
                }
            }
            catch (System.Security.SecurityException)
            {
                Console.WriteLine("firewall banned application.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            while (true) Thread.Sleep(1000000);
        }
Exemplo n.º 32
0
 private bool None(uint player, vJoy playa)
 {
     return playa.SetDiscPov(-1, player, 1);
 }