Exemple #1
0
        static void Main(string[] args)
        {
            ScpBus scpBus = new ScpBus();

            scpBus.UnplugAll();
            global_scpBus = scpBus;

            handler = new ConsoleEventDelegate(ConsoleEventCallback);
            SetConsoleCtrlHandler(handler, true);

            Thread.Sleep(400);

            Xiaomi_gamepad[] gamepads = new Xiaomi_gamepad[4];
            int index             = 1;
            var compatibleDevices = HidDevices.Enumerate(0x2717, 0x3144).ToList();

            foreach (var deviceInstance in compatibleDevices)
            {
                Console.WriteLine(deviceInstance);
                HidDevice Device = deviceInstance;
                try {
                    Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive);
                } catch (Exception exception)
                {
                    Console.WriteLine("Could not open gamepad in exclusive mode. Please close anything that could be using the controller\nAttempting to open it in shared mode.");
                    Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                }

                byte[] Vibration = { 0x20, 0x00, 0x00 };
                if (Device.WriteFeatureData(Vibration) == false)
                {
                    Console.WriteLine("Could not write to gamepad (is it closed?), skipping");
                    Device.CloseDevice();
                    continue;
                }

                byte[] serialNumber;
                byte[] product;
                Device.ReadSerialNumber(out serialNumber);
                Device.ReadProduct(out product);


                gamepads[index - 1] = new Xiaomi_gamepad(Device, scpBus, index);
                ++index;

                if (index >= 5)
                {
                    break;
                }
            }

            Console.WriteLine("{0} controllers connected", index - 1);

            while (true)
            {
                Thread.Sleep(1000);
            }
        }
Exemple #2
0
        private void Connect()
        {
            ScpBus scpBus = new ScpBus();

            scpBus.UnplugAll();
            global_scpBus = scpBus;

            gamepads = new Xiaomi_gamepad[4];
            int index             = 1;
            var compatibleDevices = HidDevices.Enumerate(0x2717, 0x3144).ToList();

            foreach (var deviceInstance in compatibleDevices)
            {
                //Console.WriteLine(deviceInstance);
                textBox.AppendText(deviceInstance + Environment.NewLine);
                HidDevice Device = deviceInstance;
                global_device = deviceInstance;
                try
                {
                    Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive);
                }
                catch (Exception exception)
                {
                    //Console.WriteLine("Could not open gamepad in exclusive mode. Please close anything that could be using the controller\nAttempting to open it in shared mode.");
                    textBox.AppendText("Could not open gamepad in exclusive mode.Please close anything that could be using the controller" + Environment.NewLine + "Attempting to open it in shared mode." + Environment.NewLine);
                    Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                }

                byte[] Vibration = { 0x20, 0x00, 0x00 };
                if (Device.WriteFeatureData(Vibration) == false)
                {
                    //Console.WriteLine("Could not write to gamepad (is it closed?), skipping");
                    textBox.AppendText("Could not write to gamepad (is it closed?), skipping" + Environment.NewLine);
                    Device.CloseDevice();
                    continue;
                }

                byte[] serialNumber;
                byte[] product;
                Device.ReadSerialNumber(out serialNumber);
                Device.ReadProduct(out product);


                gamepads[index - 1] = new Xiaomi_gamepad(Device, scpBus, index);
                ++index;

                if (index >= 5)
                {
                    break;
                }
            }

            //Console.WriteLine("{0} controllers connected", index - 1);
            textBox.AppendText(index - 1 + " controllers connected" + Environment.NewLine);

            connected_controllers = index - 1;
        }
Exemple #3
0
        static void Main(string[] args)
        {
            ScpBus scpBus = new ScpBus();

            scpBus.UnplugAll();
            global_scpBus = scpBus;

            handler = new ConsoleEventDelegate(ConsoleEventCallback);
            SetConsoleCtrlHandler(handler, true);

            Thread.Sleep(400);

            Xiaomi_gamepad[] gamepads = new Xiaomi_gamepad[4];
            int index             = 1;
            var compatibleDevices = HidDevices.Enumerate(0x2717, 0x3144).ToList();

            foreach (var deviceInstance in compatibleDevices)
            {
                Console.WriteLine(deviceInstance);
                HidDevice Device = deviceInstance;
                Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive);
                byte[] serialNumber;
                byte[] product;
                Device.ReadSerialNumber(out serialNumber);
                Device.ReadProduct(out product);


                gamepads[index - 1] = new Xiaomi_gamepad(Device, scpBus, index);
                ++index;

                if (index >= 5)
                {
                    break;
                }
            }

            Console.WriteLine("{0} controllers connected", index - 1);

            while (true)
            {
                Thread.Sleep(1000);
            }
        }
        public MainForm()
        {
            InitializeComponent();
            ScpBus scpBus = new ScpBus();

            scpBus.UnplugAll();
            global_scpBus = scpBus;

            Thread.Sleep(400);

            Xiaomi_gamepad[] gamepads = new Xiaomi_gamepad[4];
            int index             = 1;
            var compatibleDevices = HidDevices.Enumerate(0x2717, 0x3144).ToList();

            foreach (var deviceInstance in compatibleDevices)
            {
                Log(deviceInstance.ToString());
                HidDevice Device = deviceInstance;
                try
                {
                    Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive);
                }
                catch
                {
                    Log("Could not open gamepad in exclusive mode. Try re-enable device.");
                    var instanceId = devicePathToInstanceId(deviceInstance.DevicePath);
                    if (TryReEnableDevice(instanceId))
                    {
                        try
                        {
                            Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive);
                            Log("Opened in exclusive mode.");
                        }
                        catch
                        {
                            Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                            Log("Opened in shared mode.");
                        }
                    }
                    else
                    {
                        Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                        Log("Opened in shared mode.");
                    }
                }

                byte[] Vibration = { 0x20, 0x00, 0x00 };
                if (Device.WriteFeatureData(Vibration) == false)
                {
                    Log("Could not write to gamepad (is it closed?), skipping");
                    Device.CloseDevice();
                    continue;
                }

                byte[] serialNumber;
                byte[] product;
                Device.ReadSerialNumber(out serialNumber);
                Device.ReadProduct(out product);


                gamepads[index - 1] = new Xiaomi_gamepad(Device, scpBus, index);
                ++index;

                if (index >= 5)
                {
                    break;
                }
            }
            Log(index - 1 + " controllers connected");
        }
Exemple #5
0
        static void Main(string[] args)
        {
            ScpBus scpBus = new ScpBus();

            scpBus.UnplugAll();
            global_scpBus = scpBus;

            handler = new ConsoleEventDelegate(ConsoleEventCallback);
            SetConsoleCtrlHandler(handler, true);

            Thread.Sleep(400);

            Xiaomi_gamepad[] gamepads = new Xiaomi_gamepad[4];
            int index = 1;

            string[] connectedDevices = new string[4];
            while (true)
            {
                var compatibleDevices = HidDevices.Enumerate(0x2717, 0x3144).ToList();
                foreach (var deviceInstance in compatibleDevices)
                {
                    if (index >= 5 || connectedDevices.Contains(deviceInstance.DevicePath))
                    {
                        continue;
                    }

                    HidDevice Device = deviceInstance;
                    try
                    {
                        Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive);
                    }
                    catch
                    {
                        Console.WriteLine("Could not open gamepad in exclusive mode. Try re-enable device.");
                        var instanceId = devicePathToInstanceId(deviceInstance.DevicePath);
                        if (TryReEnableDevice(instanceId))
                        {
                            try
                            {
                                Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive);
                                Console.WriteLine("Opened in exclusive mode.");
                            }
                            catch
                            {
                                Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                                Console.WriteLine("Opened in shared mode.");
                            }
                        }
                        else
                        {
                            Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                            Console.WriteLine("Opened in shared mode.");
                        }
                    }

                    byte[] Vibration = { 0x20, 0x00, 0x00 };
                    if (Device.WriteFeatureData(Vibration) == false)
                    {
                        Device.CloseDevice();
                        continue;
                    }

                    byte[] serialNumber;
                    byte[] product;
                    Device.ReadSerialNumber(out serialNumber);
                    Device.ReadProduct(out product);

                    gamepads[index - 1] = new Xiaomi_gamepad(Device, scpBus, index);
                    ++index;

                    Console.WriteLine(deviceInstance);
                    Console.WriteLine("Added new device.");
                    connectedDevices[index - 1] = deviceInstance.DevicePath;
                }

                Thread.Sleep(5000);
            }
        }