Example #1
0
        public void Initialize(string devicePath)
        {
            var joystick = new Usb.GameControllers.Thrustmaster.Warthog.Throttle.Joystick(devicePath, Logger);

            MapControls(joystick);
            MapLights(joystick);
            joystick.Initialize();
        }
Example #2
0
        /// <summary>
        /// Just testing things...
        /// </summary>
        /// <param name="args"></param>
        private static void Main(string[] args)
        {
            try
            {
                const ushort TTC_VENDORID           = 0xF00F;
                const ushort TTC_PRODUCTID_KEYBOARD = 0x00000003;
                // \\?\hid#hidclass#1&1731f3ea&1&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd
                var test = Usb.Hid.Connection.Devices.RetrieveAllDevicePath(TTC_VENDORID, TTC_PRODUCTID_KEYBOARD).FirstOrDefault();

                var list = Usb.Hid.Connection.Devices.RetrieveAllDevicePath().ToList();

                var controller0 = new Controller(@"\\?\hid#hidclass#1&1731f3ea&1&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd", new NullLogger <LogTest>());



                // A lot of commented out calls to different part of the code to determine that the libraries are doing what I want them to do.

                //var paths = Devices.RetrieveAllDevicePath(
                //    Usb.GameControllers.LeoBodnar.BBI32.Joystick.VendorId,
                //    Usb.GameControllers.LeoBodnar.BBI32.Joystick.ProductId);

                //var paths = Devices.RetrieveAllDevicePath(
                //   Usb.GameControllers.Microsoft.Sidewinder.StrategicCommander.Joystick.VendorId,
                //    Usb.GameControllers.Microsoft.Sidewinder.StrategicCommander.Joystick.ProductId);

                var paths = Devices.RetrieveAllDevicePath(
                    Usb.GameControllers.Thrustmaster.Warthog.Throttle.Joystick.VendorId,
                    Usb.GameControllers.Thrustmaster.Warthog.Throttle.Joystick.ProductId);

                //var paths = Devices.RetrieveAllDevicePath(
                //    Usb.GameControllers.CHProducts.ProPedals.Joystick.VendorId,
                //    Usb.GameControllers.CHProducts.ProPedals.Joystick.ProductId);

                //var paths = Devices.RetrieveAllDevicePath(
                //   Usb.GameControllers.Pioneer.DDJSB2.Joystick.VendorId,
                //   Usb.GameControllers.Pioneer.DDJSB2.Joystick.ProductId);

                //                int idVendor = 0x0C45;
                //              int ipProduct = 0x760A;

                //int idVendor = 0x2B73;
                //int ipProduct = 0x0001;

                // \\?\hid#vid_0c45&pid_760a&mi_01&col06#b&146a75ad&0&0005#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd
                // \\?\hid#vid_0c45&pid_760a&mi_00#b&279a91eb&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd
                // \\?\hid#vid_0c45&pid_760a&mi_01&col04#b&146a75ad&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd
                // \\?\hid#vid_0c45&pid_760a&mi_01&col01#b&146a75ad&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}       //mute vol+ vol-
                // \\?\hid#vid_0c45&pid_760a&mi_01&col02#b&146a75ad&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}
                // \\?\hid#vid_0c45&pid_760a&mi_01&col03#b&146a75ad&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}
                // \\?\hid#vid_0c45&pid_760a&mi_01&col05#b&146a75ad&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}\kbd

                //idVendor: 0x0C45(Sonix Technology Co., Ltd.)
                //idProduct: 0x760A

                //var paths = Devices.RetrieveAllDevicePath(idVendor, ipProduct).ToList();
                //Usb.GameControllers.Microsoft.Sidewinder.ForceFeedback2.Joystick.VendorId,
                //Usb.GameControllers.Microsoft.Sidewinder.ForceFeedback2.Joystick.ProductId);

                //var usb = new Usb.Hid.Connection.Controller(paths[6]);

                //usb.ContinuousUsb = true;
                //usb.ContinuousUsbReportSize = 15;
                //usb.ContinuousUsbDebounce = true;
                //usb.ContinuousUsbDebounceButtonsIndex = 1;
                if (false)
                {
                    var bbi32Paths = Devices.RetrieveAllDevicePath(
                        Usb.GameControllers.LeoBodnar.BBI32.Joystick.VendorId,
                        Usb.GameControllers.LeoBodnar.BBI32.Joystick.ProductId);

                    var usb = new Usb.Hid.Connection.Controller(bbi32Paths.First(), null);
                    usb.Subscribe(x => Console.WriteLine($"bbi32: {DateTime.Now}"));
                    usb.Initialize();
                    usb.ProcessInputReport().Wait();
                }
                if (false)
                {
                    using (ILoggerFactory loggerFactory =
                               LoggerFactory.Create(builder => builder.AddSimpleConsole(options =>
                                                                                        { options.SingleLine = true; options.TimestampFormat = "hh:mm:ss "; }).SetMinimumLevel(LogLevel.Debug)))
                    {
                        ILogger <Usb.GameControllers.Thrustmaster.Warthog.Throttle.Joystick> logger
                            = loggerFactory.CreateLogger <Usb.GameControllers.Thrustmaster.Warthog.Throttle.Joystick>();

                        var warthog = Devices.RetrieveAllDevicePath(
                            Usb.GameControllers.Thrustmaster.Warthog.Throttle.Joystick.VendorId,
                            Usb.GameControllers.Thrustmaster.Warthog.Throttle.Joystick.ProductId);

                        var usb = new Usb.Hid.Connection.Controller(warthog.First(), logger)
                        {
                            ContinuousUsb = true,
                            // Warthog returns raw vales starting at 16.  Only look for changes before that.
                            ContinuousUsbReportSize = 15,

                            // Debounce the buttons
                            ContinuousUsbDebounce = true,
                            // Button data is bytes 1-4
                            ContinuousUsbDebounceButtonsIndex = 1,
                        };

                        usb.Subscribe(x => Console.WriteLine($"warthog: {DateTime.Now}"));
                        usb.Initialize();
                        //usb.ProcessInputReport().Wait();

                        Console.ReadKey();

                        usb.Stop();
                    }
                }
                if (true)
                {
                    using (ILoggerFactory loggerFactory =
                               LoggerFactory.Create(builder => builder.AddSimpleConsole(options =>
                                                                                        { options.SingleLine = true; options.TimestampFormat = "hh:mm:ss "; }).SetMinimumLevel(LogLevel.Debug)))
                    {
                        ILogger <Usb.GameControllers.Thrustmaster.Warthog.Throttle.Joystick> logger
                            = loggerFactory.CreateLogger <Usb.GameControllers.Thrustmaster.Warthog.Throttle.Joystick>();

                        var controller = new Usb.GameControllers.Thrustmaster.Warthog.Throttle.Joystick(paths.First(), logger);

                        controller.Subscribe(x => Console.WriteLine($"warthog: {DateTime.Now}"));

                        controller.Initialize();

                        //var test = controller.Controller.GetInputReport();

                        controller.Lights = (byte)Usb.GameControllers.Thrustmaster.Warthog.Throttle.Models.Light.LED1;
                        System.Threading.Thread.Sleep(500);

                        controller.Lights = (byte)Usb.GameControllers.Thrustmaster.Warthog.Throttle.Models.Light.LED2;
                        System.Threading.Thread.Sleep(500);

                        controller.Lights = (byte)Usb.GameControllers.Thrustmaster.Warthog.Throttle.Models.Light.LED3;
                        System.Threading.Thread.Sleep(500);
                        //usb.ProcessSerialMessage(test.Length, test, test.Length, 0).Wait();

                        Console.ReadKey();
                    }
                }
                if (false)
                {
                    var controller = new Usb.GameControllers.CHProducts.ProPedals.Joystick(paths.First(), null);

                    controller.Initialize();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            while (true)
            {
                ;
            }
            Console.ReadKey();
        }