ResetAll() public method

public ResetAll ( ) : bool
return bool
Esempio n. 1
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);
        }