public void InterestedUSBChange(int VID, int PID, bool connected) { if (!connected) { var dev = devices.First(x => x is HyperXAlloyRgbControlDevice hx && hx.HID == PID); devices.Remove(dev); DeviceRemoved?.Invoke(this, new Events.DeviceChangeEventArgs(dev)); } else { var sdevice = supportedDevices.First(x => x.Pid == PID); HyperXKeyboardSupport hyperX = new HyperXKeyboardSupport(sdevice.Vid, sdevice.Pid, sdevice.Usb); dv = new HyperXAlloyRgbControlDevice { Name = sdevice.Name, DeviceType = DeviceTypes.Keyboard, Driver = this, ProductImage = Assembly.GetExecutingAssembly().GetEmbeddedImage("Driver.HyperXAlloy.RGB." + sdevice.Name + ".png"), HyperXSupport = hyperX, GridHeight = 6, GridWidth = 23, Has2DSupport = true, HID = sdevice.Pid }; KeyboardHelper.AddKeyboardWatcher(sdevice.Vid, sdevice.Pid, dv.HandleInput); List <ControlDevice.LedUnit> leds = new List <ControlDevice.LedUnit>(); int ctt = 0; var tled = new ControlDevice.LedUnit[106]; int ct = 0; foreach (var tp in hyperX.humm) { var ld = new ControlDevice.LedUnit { LEDName = HyperXKeyboardSupport.KeyNames[tp.Order], Data = new ControlDevice.PositionalLEDData { LEDNumber = Array.IndexOf(hyperX.humm, tp), X = tp.X, Y = tp.Y }, }; leds.Add(ld); } dv.LEDs = leds.OrderBy(p => ((ControlDevice.PositionalLEDData)p.Data).X + ((ControlDevice.PositionalLEDData)p.Data).Y).ToArray(); devices.Add(dv); DeviceAdded?.Invoke(this, new Events.DeviceChangeEventArgs(dv)); } }
public List <ControlDevice> GetDevices() { List <ControlDevice> devices = new List <ControlDevice>(); var connectedKeyboards = SLSManager.GetSupportedDevices(supportedKeyboards); var connectedMice = SLSManager.GetSupportedDevices(supportedMice); var connectedMouseMats = SLSManager.GetSupportedDevices(supportedMouseMats); var connectedKeypads = SLSManager.GetSupportedDevices(supportedKeypads); var connectedHeadsets = SLSManager.GetSupportedDevices(supportedHeadsets); if (!configModel.ShowOnlyConnected || connectedKeyboards.Any()) { KeyboardDevice keyboard = new KeyboardDevice(uri, this); if (connectedKeyboards.Any()) { USBDevice first = connectedKeyboards.First(); keyboard.Name = first.DevicePrettyName; if (first.HID.HasValue) { KeyboardHelper.AddKeyboardWatcher(first.VID, first.HID.Value, keyboard.HandleInput); } } devices.Add(keyboard); } if (!configModel.ShowOnlyConnected || connectedMice.Any()) { MouseDevice mouse = new MouseDevice(uri, this); if (connectedMice.Any()) { USBDevice first = connectedMice.First(); mouse.Name = first.DevicePrettyName; } devices.Add(mouse); } if (!configModel.ShowOnlyConnected || connectedMouseMats.Any()) { MousepadDevice mousePad = new MousepadDevice(uri, this); if (connectedMouseMats.Any()) { USBDevice first = connectedMouseMats.First(); mousePad.Name = first.DevicePrettyName; } devices.Add(mousePad); } if (!configModel.ShowOnlyConnected || connectedKeypads.Any()) { KeypadDevice keypad = new KeypadDevice(uri, this); if (connectedKeypads.Any()) { USBDevice first = connectedKeypads.First(); keypad.Name = first.DevicePrettyName; } devices.Add(keypad); } if (!configModel.ShowOnlyConnected || connectedHeadsets.Any()) { HeadSetDevice headset = new HeadSetDevice(uri, this); if (connectedHeadsets.Any()) { USBDevice first = connectedHeadsets.First(); headset.Name = first.DevicePrettyName; } devices.Add(headset); } //Chroma links could be anything - always show this one ChromaLinkDevice chromaLink = new ChromaLinkDevice(uri, this); devices.Add(chromaLink); return(devices); }