Example #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();
        }
Example #2
0
        public void InputReportReceived(IDualShockDevice device, IInputReport report)
        {
            switch (device.DeviceType)
            {
            case DualShockDeviceType.DualShock3:

                var target = _deviceMap[device];

                var ds3Report = (DualShock3InputReport)report;
                var ds4Report = new DualShock4Report();

                ds4Report.SetAxis(DualShock4Axes.LeftThumbX, ds3Report[DualShock3Axes.LeftThumbX]);
                ds4Report.SetAxis(DualShock4Axes.LeftThumbY, ds3Report[DualShock3Axes.LeftThumbY]);
                ds4Report.SetAxis(DualShock4Axes.RightThumbX, ds3Report[DualShock3Axes.RightThumbX]);
                ds4Report.SetAxis(DualShock4Axes.RightThumbY, ds3Report[DualShock3Axes.RightThumbY]);
                ds4Report.SetAxis(DualShock4Axes.LeftTrigger, ds3Report[DualShock3Axes.LeftTrigger]);
                ds4Report.SetAxis(DualShock4Axes.RightTrigger, ds3Report[DualShock3Axes.RightTrigger]);

                ds4Report.SetButtons(_btnMap.Where(m => ds3Report.EngagedButtons.Contains(m.Key))
                                     .Select(m => m.Value).ToArray());

                if (ds3Report.EngagedButtons.Contains(DualShock3Buttons.DPadUp))
                {
                    ds4Report.SetDPad(DualShock4DPadValues.North);
                }
                if (ds3Report.EngagedButtons.Contains(DualShock3Buttons.DPadRight))
                {
                    ds4Report.SetDPad(DualShock4DPadValues.East);
                }
                if (ds3Report.EngagedButtons.Contains(DualShock3Buttons.DPadDown))
                {
                    ds4Report.SetDPad(DualShock4DPadValues.South);
                }
                if (ds3Report.EngagedButtons.Contains(DualShock3Buttons.DPadLeft))
                {
                    ds4Report.SetDPad(DualShock4DPadValues.West);
                }

                if (ds3Report.EngagedButtons.Contains(DualShock3Buttons.DPadUp) &&
                    ds3Report.EngagedButtons.Contains(DualShock3Buttons.DPadRight))
                {
                    ds4Report.SetDPad(DualShock4DPadValues.Northeast);
                }
                if (ds3Report.EngagedButtons.Contains(DualShock3Buttons.DPadRight) &&
                    ds3Report.EngagedButtons.Contains(DualShock3Buttons.DPadDown))
                {
                    ds4Report.SetDPad(DualShock4DPadValues.Southeast);
                }
                if (ds3Report.EngagedButtons.Contains(DualShock3Buttons.DPadDown) &&
                    ds3Report.EngagedButtons.Contains(DualShock3Buttons.DPadLeft))
                {
                    ds4Report.SetDPad(DualShock4DPadValues.Southwest);
                }
                if (ds3Report.EngagedButtons.Contains(DualShock3Buttons.DPadLeft) &&
                    ds3Report.EngagedButtons.Contains(DualShock3Buttons.DPadUp))
                {
                    ds4Report.SetDPad(DualShock4DPadValues.Northwest);
                }

                if (ds3Report.EngagedButtons.Contains(DualShock3Buttons.Ps))
                {
                    ds4Report.SetSpecialButtons(DualShock4SpecialButtons.Ps);
                }

                target.SendReport(ds4Report);

                break;
            }
        }
Example #3
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();
        }