public static async Task InitializeAsync() { var hidFactory = new FilterDeviceDefinition( LogitechVid, LogitechPowerPlayPid, LogitechPowerPlayUsagePage, LogitechPowerPlaFriendlyName) .CreateWindowsHidDeviceFactory(); // The correct device var powerPlayDeviceDefinition = (await hidFactory.GetConnectedDeviceDefinitionsAsync().ConfigureAwait(false)).FirstOrDefault(d => d.Usage == LogitechPowerPlayPage); var powerPlayDevice = await hidFactory.GetDeviceAsync(powerPlayDeviceDefinition).ConfigureAwait(false); if (powerPlayDeviceDefinition == null || powerPlayDevice == null) { IsInitialized = false; return; } powerPlayDevice.InitializeAsync().Wait(); MouseController = new PowerPlayController(powerPlayDevice, 0x01, 0x07); MatController = new PowerPlayController(powerPlayDevice, 0x07, 0x0B); // We assume the mouse exists because there is no way of know if there is a paired device. IsInitialized = true; }
public async Task TestFindSTMDFUModeWithFactory() { var deviceFactory = new FilterDeviceDefinition(StmDfuVendorId, StmDfuProductId) .CreateWindowsUsbDeviceFactory(classGuid: WindowsDeviceConstants.GUID_DEVINTERFACE_USB_DEVICE); var devices = await deviceFactory.GetConnectedDeviceDefinitionsAsync(); Assert.IsTrue(devices.Any()); }
internal static async Task <Scxi> Create(AppConfig config) { var hidFactory = new FilterDeviceDefinition(vendorId: 10462, productId: 4418, label: "Steam Controller") .CreateWindowsHidDeviceFactory(); var deviceDefinitions = await hidFactory.GetConnectedDeviceDefinitionsAsync(); var device = await hidFactory.GetDeviceAsync(deviceDefinitions.Single(d => d.DeviceId.Contains("mi_01"))); await device.InitializeAsync(); return(new Scxi((IHidDevice)device, XboxControllerAdapter.Create(), config)); }
public async Task FindUsbDevice() { var deviceFactory = new FilterDeviceDefinition(VENDOR_ID, PRODUCT_ID) .CreateWindowsUsbDeviceFactory(classGuid: WindowsDeviceConstants.GUID_DEVINTERFACE_USB_DEVICE); var devices = await deviceFactory.GetConnectedDeviceDefinitionsAsync(); //Get the first available device var deviceDefinition = devices.FirstOrDefault(); const string deviceID = @"\\?\usb#vid_0483&pid_5716#338a39613338#{a5dcbf10-6530-11d2-901f-00c04fb951ed}"; var windowsUsbDevice = new UsbDevice(deviceID, new WindowsUsbInterfaceManager(deviceID)); await windowsUsbDevice.InitializeAsync(); Console.WriteLine("test"); }
public async Task TestCreateWindowsHidDeviceFactory() { var result = new List <ConnectedDeviceDefinition> { new ConnectedDeviceDefinition("123", DeviceType.Hid) }; var deviceFactory = new FilterDeviceDefinition().CreateWindowsHidDeviceFactory( getConnectedDeviceDefinitionsAsync: (c) => { return(Task.FromResult <IEnumerable <ConnectedDeviceDefinition> >(result)); }); var deviceDefinitions = await deviceFactory.GetConnectedDeviceDefinitionsAsync(); Assert.AreEqual(deviceDefinitions.Count(), deviceDefinitions.Count()); Assert.AreEqual(deviceDefinitions.First().DeviceId, deviceDefinitions.First().DeviceId); }
public async Task Run(Target target) { Devices = new List <Device> { }; var logger = Logger.Instance(); if (target == Target.stm32) { var deviceFactory = new FilterDeviceDefinition(0x0483, 0xDF11) // STM32 Bootloader .CreateWindowsUsbDeviceFactory(classGuid: WindowsDeviceConstants.GUID_DEVINTERFACE_USB_DEVICE); var devices = await deviceFactory.GetConnectedDeviceDefinitionsAsync(); var device = devices.FirstOrDefault(); if (device != null) { Devices.Add(new Device(device)); } } if (target == Target.teensy) { var deviceFactory = new FilterDeviceDefinition(0x16C0, 0x0478) // Teensy Bootloader .CreateWindowsHidDeviceFactory(classGuid: WindowsDeviceConstants.GUID_DEVINTERFACE_HID); var devices = await deviceFactory.GetConnectedDeviceDefinitionsAsync(); var device = devices.FirstOrDefault(); if (device != null) { Devices.Add(new Device(device)); } } if (target == Target.all) { var hidGuid = WindowsDeviceConstants.GUID_DEVINTERFACE_HID; var usbGuid = WindowsDeviceConstants.GUID_DEVINTERFACE_USB_DEVICE; var deviceFactories = new List <IDeviceFactory> { new FilterDeviceDefinition(0x16C0, 0x0478) // Teensy Bootloader .CreateWindowsHidDeviceFactory(classGuid: hidGuid), new FilterDeviceDefinition(0x0483, 0xDF11) // STM32 Bootloader .CreateWindowsUsbDeviceFactory(classGuid: usbGuid), new FilterDeviceDefinition(0xFEED, 0x1307) // Legacy Ids Ergodox EZ .CreateWindowsHidDeviceFactory(classGuid: hidGuid), new FilterDeviceDefinition(0xFEED, 0x6060) // Legacy Ids Planck EZ .CreateWindowsHidDeviceFactory(classGuid: hidGuid), new FilterDeviceDefinition(0x3297, 0x1969) // Moonlander MK1 .CreateWindowsHidDeviceFactory(classGuid: hidGuid), new FilterDeviceDefinition(0x3297, 0x4974) // Ergodox EZ Standard .CreateWindowsHidDeviceFactory(classGuid: hidGuid), new FilterDeviceDefinition(0x3297, 0x4975) // Ergodox EZ Shine .CreateWindowsHidDeviceFactory(classGuid: hidGuid), new FilterDeviceDefinition(0x3297, 0x4976) // Ergodox EZ Glow .CreateWindowsHidDeviceFactory(classGuid: hidGuid), new FilterDeviceDefinition(0x3297, 0xC6CE) // Planck EZ Standard .CreateWindowsHidDeviceFactory(classGuid: hidGuid), new FilterDeviceDefinition(0x3297, 0xC6CF) // Planck EZ Glow .CreateWindowsHidDeviceFactory(classGuid: hidGuid), }; var deviceManager = new DeviceManager(deviceFactories, null); var devices = await deviceManager.GetConnectedDeviceDefinitionsAsync(); // The device manager returns an entry for each endpoints // as a result duplicates are removed by checking against // the pid / vid of previously enumerated devices. foreach (var device in devices) { var match = Devices.FindIndex((_dev) => _dev.Info.VendorId == device.VendorId && _dev.Info.ProductId == device.ProductId); if (match == -1) { Devices.Add(new Device(device)); } } } }