Esempio n. 1
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. 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);
        }