コード例 #1
0
        private static void Main(string[] args)
        {
            var client = new ViGEmClient();

#if X360
            var x360 = new Xbox360Controller(client);

            x360.FeedbackReceived +=
                (sender, eventArgs) => Console.WriteLine(
                    $"LM: {eventArgs.LargeMotor}, " +
                    $"SM: {eventArgs.SmallMotor}, " +
                    $"LED: {eventArgs.LedNumber}");

            x360.Connect();

            var report = new Xbox360Report();
            report.SetButtons(Xbox360Buttons.A, Xbox360Buttons.B);
            report.SetAxis(Xbox360Axes.LeftTrigger, 0xFF);
            report.SetAxis(Xbox360Axes.RightTrigger, 0xFF);

            x360.SendReport(report);
#endif

            var ds4 = new DualShock4Controller(client);

            ds4.Connect();

            var report = new DualShock4Report();
            report.SetButtons(DualShock4Buttons.Cross);

            ds4.SendReport(report);

            /*
             * var x360 = new Xbox360Controller();
             * x360.FeedbackReceived +=
             *  (sender, eventArgs) => Console.WriteLine(
             *      $"LM: {eventArgs.LargeMotor}, " +
             *      $"SM: {eventArgs.SmallMotor}, " +
             *      $"LED: {eventArgs.LedNumber}");
             * x360.PlugIn();
             *
             * var report = new Xbox360Report();
             * report.SetButtons(Xbox360Buttons.A, Xbox360Buttons.B);
             * report.SetAxis(Xbox360Axes.LeftTrigger, 0xFF);
             * report.SetAxis(Xbox360Axes.RightTrigger, 0xFF);
             *
             * x360.SendReport(report);
             *
             * Console.ReadKey();
             *
             * var ds4 = new DualShock4Controller();
             * ds4.FeedbackReceived +=
             *  (sender, eventArgs) => Console.WriteLine(
             *      $"LM: {eventArgs.LargeMotor}, " +
             *      $"SM: {eventArgs.SmallMotor}, ");
             * ds4.PlugIn();
             */

            Console.ReadKey();
        }
コード例 #2
0
        private static void Main(string[] args)
        {
            var x360 = new Xbox360Controller();

            x360.FeedbackReceived +=
                (sender, eventArgs) => Console.WriteLine(
                    $"LM: {eventArgs.LargeMotor}, " +
                    $"SM: {eventArgs.SmallMotor}, " +
                    $"LED: {eventArgs.LedNumber}");
            x360.PlugIn();

            var report = new Xbox360Report();

            report.SetButtons(Xbox360Buttons.A, Xbox360Buttons.B);
            report.SetAxis(Xbox360Axes.LeftTrigger, 0xFF);
            report.SetAxis(Xbox360Axes.RightTrigger, 0xFF);

            x360.SendReport(report);

            Console.ReadKey();

            var ds4 = new DualShock4Controller();

            ds4.FeedbackReceived +=
                (sender, eventArgs) => Console.WriteLine(
                    $"LM: {eventArgs.LargeMotor}, " +
                    $"SM: {eventArgs.SmallMotor}, ");
            ds4.PlugIn();

            Console.ReadKey();
        }
コード例 #3
0
ファイル: ViGEmSink.cs プロジェクト: x3n1ty/Shibari
        public void DeviceArrived(IDualShockDevice device)
        {
            Log.Information("Device {Device} got attached", device);

            var target = new DualShock4Controller(_client);

            _deviceMap.Add(device, target);

            target.FeedbackReceived += (sender, args) =>
            {
                var source = _deviceMap.First(m => m.Value.Equals(sender)).Key;

                RumbleRequestReceived?.Invoke(source, new RumbleRequestEventArgs(args.LargeMotor, args.SmallMotor));
            };

            try
            {
                Log.Information("Connecting ViGEm target {Target}", target);
                target.Connect();
                Log.Information("ViGEm target {Target} connected successfully", target);
            }
            catch (Exception ex)
            {
                Log.Error("Failed to connect target {@Target}: {Exception}", target, ex);
            }
        }
コード例 #4
0
        public string RemoveDevice(string UniqueKey)
        {
            lock (Controllers)
            {
                if (!DeviceToControllerKeyMap.ContainsKey(UniqueKey))
                {
                    return(null);
                }

                Guid DeviceParent = DeviceToControllerKeyMap[UniqueKey];

                foreach (string DeviceKey in ControllerToDeviceKeyMap[DeviceParent])
                {
                    if (DeviceToControllerKeyMap.ContainsKey(DeviceKey))
                    {
                        DeviceToControllerKeyMap.Remove(DeviceKey);
                    }
                }

                DualShock4Controller ctrl = Controllers[DeviceParent];
                string UniqueControllerId = ctrl.ConnectionUniqueID;

                ctrl.DeInitalize();
                ctrl.Dispose();
                Controllers.Remove(DeviceParent);
                ControllerToDeviceKeyMap.Remove(DeviceParent);

                return(UniqueControllerId);
            }
        }
コード例 #5
0
        public override void Disconnect()
        {
            if (forceFeedbackCall != null)
            {
                cont.FeedbackReceived -= forceFeedbackCall;
                forceFeedbackCall      = null;
            }

            cont.Disconnect();
            cont.Dispose();
            cont = null;
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: psyke83/ViGEm
        static void Main(string[] args)
        {
            var x360 = new Xbox360Controller();

            x360.PlugIn();

            Console.ReadKey();

            var ds4 = new DualShock4Controller();

            ds4.PlugIn();

            Console.ReadKey();
        }
コード例 #7
0
ファイル: DS4OutDevice.cs プロジェクト: David-DFT/DS4Windows
 public DS4OutDevice(ViGEmClient client)
 {
     Controller = new DualShock4Controller(client);
     report     = new DualShock4Report();
 }
コード例 #8
0
        public static void FindControllers()
        {
            lock (HidGameControllers.devices)             // TODO will this be called by multiple threads? why?
            {
                var hidGameControllers = HidGameControllers.EnumerateHidControllersMatching(vendorIdProductIdInfoArray: HidGameControllers.dualShock4CompatibleDevices);
                hidGameControllers = hidGameControllers
                                     .Where(hidController => IsRealDS4(hidController))
                                     .OrderBy <HidDevice, ConnectionType>((HidDevice hidGameController) =>
                {                         // Sort Bluetooth first in case USB is also connected on the same controller.
                    return(DualShock4Controller.HidConnectionType(hidGameController));
                });

                var tempHidGameControllers = hidGameControllers.ToList();                 // TODO it's already an IEnumerable, why tolist()?? Just to create a copy? Why creating a copy?
                // TODO purgeHiddenExclusiveDevices();
                tempHidGameControllers.AddRange(HidGameControllers.disabledDevices);
                int    hidGameControllersCount = tempHidGameControllers.Count();
                string devicePlural            = "device" + (hidGameControllersCount == 0 || hidGameControllersCount > 1 ? "s" : "");
                //Log.LogToGui("Found " + hidGameControllersCount + " possible " + devicePlural + ". Examining " + devicePlural + ".", false);

                for (int i = 0; i < hidGameControllersCount; i++)
                //foreach (HidDevice hDevice in hDevices)
                {
                    var tempHidGameController = tempHidGameControllers[i];
                    if (tempHidGameController.Description == "HID-compliant vendor-defined device")
                    {
                        continue;                         // ignore the Nacon Revolution Pro programming interface
                    }

                    if (HidGameControllers.devicePaths.Contains(tempHidGameController.DevicePath))
                    {
                        continue;                         // BT/USB endpoint already opened once
                    }

                    if (!tempHidGameController.IsOpen)
                    {
                        tempHidGameController.OpenDevice(HidGameControllers.isExclusiveMode);
                        if (!tempHidGameController.IsOpen && HidGameControllers.isExclusiveMode)
                        {
                            try
                            {
                                // Check if running with elevated permissions // FIXME why check this at each iteration??
                                WindowsIdentity  identity  = WindowsIdentity.GetCurrent();
                                WindowsPrincipal principal = new WindowsPrincipal(identity);
                                bool             elevated  = principal.IsInRole(WindowsBuiltInRole.Administrator);

                                if (!elevated)
                                {
                                    // Tell the client to launch routine to re-enable a device
                                    RequestElevationArgs eleArgs = new RequestElevationArgs(HidGameControllers.DevicePathToInstanceId(tempHidGameController.DevicePath));
                                    RequestElevation?.Invoke(eleArgs);
                                    if (eleArgs.StatusCode == RequestElevationArgs.STATUS_SUCCESS)
                                    {
                                        tempHidGameController.OpenDevice(HidGameControllers.isExclusiveMode);
                                    }
                                }
                                else
                                {
                                    HidGameControllers.ReEnableDevice(HidGameControllers.DevicePathToInstanceId(tempHidGameController.DevicePath));
                                    tempHidGameController.OpenDevice(HidGameControllers.isExclusiveMode);
                                }
                            }
                            catch (Exception)
                            {
                                // FIXME log this!
                            }
                        }

                        // TODO in exclusive mode, try to hold both open when both are connected
                        if (HidGameControllers.isExclusiveMode && !tempHidGameController.IsOpen)
                        {
                            tempHidGameController.OpenDevice(isExclusive: false);
                        }
                    }

                    if (tempHidGameController.IsOpen)
                    {
                        string serial      = tempHidGameController.ReadSerial();
                        bool   validSerial = !serial.Equals(HidDevice.blankSerial);
                        if (validSerial && deviceSerials.Contains(serial))
                        {
                            // happens when the BT endpoint already is open and the USB is plugged into the same host
                            if (HidGameControllers.isExclusiveMode && tempHidGameController.IsExclusive &&
                                !HidGameControllers.disabledDevices.Contains(tempHidGameController))
                            {
                                // Grab reference to exclusively opened HidDevice so device
                                // stays hidden to other processes
                                HidGameControllers.disabledDevices.Add(tempHidGameController);
                                //DevicePaths.Add(tempHidGameController.DevicePath);
                            }

                            continue;
                        }
                        else
                        {
                            var vendorIdProductIdInfo = dualShock4CompatibleDevices.Single(
                                x => x.vendorId == tempHidGameController.Attributes.VendorId &&
                                x.productId == tempHidGameController.Attributes.ProductId
                                );

                            var ds4Device = new DualShock4Controller(tempHidGameController, vendorIdProductIdInfo.name, vendorIdProductIdInfo.featureSet);
                            //ds4Device.Removal += On_Removal;
                            if (!ds4Device.ExitOutputThread)
                            {
                                HidGameControllers.devices.Add(tempHidGameController.DevicePath, ds4Device);
                                HidGameControllers.devicePaths.Add(tempHidGameController.DevicePath);
                                HidGameControllers.deviceSerials.Add(serial);
                            }
                        }
                    }
                }
            }
        }
コード例 #9
0
        private static void Main(string[] args)
        {
            var client = new ViGEmClient();

#if X360
            var x360 = new Xbox360Controller(client);

            x360.FeedbackReceived +=
                (sender, eventArgs) => Console.WriteLine(
                    $"LM: {eventArgs.LargeMotor}, " +
                    $"SM: {eventArgs.SmallMotor}, " +
                    $"LED: {eventArgs.LedNumber}");

            x360.Connect();

            var report = new Xbox360Report();
            report.SetButtons(Xbox360Buttons.A, Xbox360Buttons.B);
            report.SetAxis(Xbox360Axes.LeftTrigger, 0xFF);
            report.SetAxis(Xbox360Axes.RightTrigger, 0xFF);

            x360.SendReport(report);
#endif

            Console.Title = "ViGEm Benchmark - CLOSE THIS WINDOW TO STOP!";
            Console.WriteLine(Console.Title);

            var controllers = new ObservableCollection <DualShock4Controller>();

            controllers.CollectionChanged += (sender, eventArgs) =>
            {
                switch (eventArgs.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    Console.WriteLine("Added Controller");
                    break;

                case NotifyCollectionChangedAction.Remove:
                    Console.WriteLine("Removed Controller");

                    if (((ObservableCollection <DualShock4Controller>)sender).Count == 0)
                    {
                        Console.WriteLine(" > Finished! Press any key to exit!");
                    }

                    break;
                }
            };

            for (int i = 0; i < 500; i++)
            {
                Console.WriteLine($" > Spawning device {i}");

                Task.Run(() =>
                {
                    var ds4 = new DualShock4Controller(client);

                    try
                    {
                        lock (controllers)
                            controllers.Add(ds4);

                        ds4.Connect();

                        var report = new DualShock4Report();
                        report.SetButtons(DualShock4Buttons.Cross);
                        ds4.SendReport(report);

                        Thread.Sleep(1000);
                        ds4.Disconnect();
                    }
                    finally
                    {
                        lock (controllers)
                            controllers.Remove(ds4);
                    }
                });

                Thread.Sleep(20);
            }

            /*
             * var x360 = new Xbox360Controller();
             * x360.FeedbackReceived +=
             *  (sender, eventArgs) => Console.WriteLine(
             *      $"LM: {eventArgs.LargeMotor}, " +
             *      $"SM: {eventArgs.SmallMotor}, " +
             *      $"LED: {eventArgs.LedNumber}");
             * x360.PlugIn();
             *
             * var report = new Xbox360Report();
             * report.SetButtons(Xbox360Buttons.A, Xbox360Buttons.B);
             * report.SetAxis(Xbox360Axes.LeftTrigger, 0xFF);
             * report.SetAxis(Xbox360Axes.RightTrigger, 0xFF);
             *
             * x360.SendReport(report);
             *
             * Console.ReadKey();
             *
             * var ds4 = new DualShock4Controller();
             * ds4.FeedbackReceived +=
             *  (sender, eventArgs) => Console.WriteLine(
             *      $"LM: {eventArgs.LargeMotor}, " +
             *      $"SM: {eventArgs.SmallMotor}, ");
             * ds4.PlugIn();
             */

            Console.ReadKey();
        }
コード例 #10
0
ファイル: Ds4.cs プロジェクト: evilC/AHK-ViGEm-Bus
 public Ds4()
 {
     _controller = new DualShock4Controller(Client.ViGEmClient);
     _report     = new DualShock4Report();
     _controller.Connect();
 }
コード例 #11
0
        public IController NewDevice(IDevice device)
        {
            HidDevice _device = device as HidDevice;

            if (_device == null)
            {
                return(null);
            }

            if (_device.VendorId == DualShock4Controller.VENDOR_SONY)
            {
                if (!new int[] {
                    DualShock4Controller.PRODUCT_SONY_DONGLE,
                    DualShock4Controller.PRODUCT_SONY_DS4V1,
                    DualShock4Controller.PRODUCT_SONY_DS4V2,
                }.Contains(_device.ProductId))
                {
                    return(null);
                }
            }
            else if (_device.VendorId == DualShock4Controller.VENDOR_BROOK)
            {
                if (_device.ProductId == DualShock4Controller.PRODUCT_BROOK_MARS)
                {
                    if (_device.DevicePath.Contains(@"&col01"))
                    {
                        DualShock4Controller ctrl = new DualShock4Controller(_device, EConnectionType.USB);
                        return(ctrl);
                    }
                }
                return(null);
            }
            else
            {
                return(null);
            }

            string deviceInstanceId = DevPKey.PnpDevicePropertyAPI.devicePathToInstanceId(_device.DevicePath);
            bool   IsVigem          = DevPKey.PnpDevicePropertyAPI.GetDeviceUINumber(deviceInstanceId).HasValue;
            bool   IsReWasd         = DevPKey.PnpDevicePropertyAPI.GetDeviceContainerId(deviceInstanceId) == CONTAINER_ID_REWASD_VIRTUAL_DS4;

            string bt_hid_id = @"00001124-0000-1000-8000-00805f9b34fb";

            string devicePath = _device.DevicePath.ToString();

            EConnectionType ConType = EConnectionType.Unknown;

            DualShock4Controller.DS4VirtualType VirtualType = DualShock4Controller.DS4VirtualType.NotVirtual;
            if (IsVigem)
            {
                ConType     = EConnectionType.Virtual;
                VirtualType = DualShock4Controller.DS4VirtualType.ViGEm;
            }
            else if (IsReWasd)
            {
                ConType     = EConnectionType.Virtual;
                VirtualType = DualShock4Controller.DS4VirtualType.reWASD;
            }
            else
            {
                switch (_device.ProductId)
                {
                case DualShock4Controller.PRODUCT_SONY_DS4V1:
                case DualShock4Controller.PRODUCT_SONY_DS4V2:
                    if (devicePath.Contains(bt_hid_id))
                    {
                        ConType = EConnectionType.Bluetooth;
                    }
                    else
                    {
                        ConType = EConnectionType.USB;
                    }
                    break;

                case DualShock4Controller.PRODUCT_SONY_DONGLE:
                    ConType = EConnectionType.Dongle;
                    break;
                }
            }

            {
                Guid?ContrainerID = DevPKey.PnpDevicePropertyAPI.GetDeviceContainerId(deviceInstanceId);
                if (ContrainerID.HasValue)
                {
                    lock (Controllers)
                    {
                        DualShock4Controller ctrl = null;
                        if (Controllers.ContainsKey(ContrainerID.Value))
                        {
                            // TODO handle subdevices, such as the audio device
                            //ctrl = Controllers[ContrainerID.Value];
                            //ctrl.AddDevice(_device);
                        }
                        else
                        {
                            Controllers[ContrainerID.Value] = new DualShock4Controller(_device, ConType, VirtualType);
                            ctrl = Controllers[ContrainerID.Value];
                        }

                        DeviceToControllerKeyMap[device.UniqueKey] = ContrainerID.Value;
                        if (!ControllerToDeviceKeyMap.ContainsKey(ContrainerID.Value))
                        {
                            ControllerToDeviceKeyMap[ContrainerID.Value] = new HashSet <string>();
                        }
                        ControllerToDeviceKeyMap[ContrainerID.Value].Add(device.UniqueKey);
                        return(ctrl);
                    }
                }
            }

            return(null);
        }