예제 #1
0
파일: VJoyPlugin.cs 프로젝트: tagaf/FreePIE
        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);
        }
예제 #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);
        }
예제 #3
0
 public VJoyGlobalHolder(int index)
 {
     Index = index;
     Center();
     Global = new VJoyGlobal(this);
     setPressedStrategy = new SetPressedStrategy(OnPress, OnRelease);
 }