internal CorsairRGBDeviceInfo(int deviceIndex, string deviceType, _CorsairDeviceInfo nativeInfo, string modelName, Dictionary <string, int> modelCounter) { this.CorsairDeviceIndex = deviceIndex; this.DeviceType = deviceType; this.CorsairDeviceType = nativeInfo.type; this.Model = modelName; this.CapsMask = (CorsairDeviceCaps)nativeInfo.capsMask; DeviceName = GetUniqueModelName(modelCounter); }
/// <summary> /// Internal constructor of managed <see cref="CorsairRGBDeviceInfo"/>. /// </summary> /// <param name="deviceIndex">The index of the <see cref="CorsairRGBDevice{TDeviceInfo}"/>.</param> /// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param> /// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param> /// <param name="modelCounter">A dictionary containing counters to create unique names for equal devices models.</param> internal CorsairRGBDeviceInfo(int deviceIndex, string deviceType, _CorsairDeviceInfo nativeInfo, Dictionary <string, int> modelCounter) { this.CorsairDeviceIndex = deviceIndex; this.DeviceType = deviceType; this.CorsairDeviceType = nativeInfo.type; this.Model = nativeInfo.model == IntPtr.Zero ? null : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase); this.CapsMask = (CorsairDeviceCaps)nativeInfo.capsMask; DeviceName = GetUniqueModelName(modelCounter); }
public List <ControlDevice> GetDevices() { if (!okayToUseCue) { return(new List <ControlDevice>()); } List <ControlDevice> devices = new List <ControlDevice>(); Dictionary <string, int> modelCounter = new Dictionary <string, int>(); if (IsICUERunning()) { int deviceCount = _CUESDK.CorsairGetDeviceCount(); var imgDict = new Dictionary <string, string>() { //Keyboards { "Corsair K60 RGB PRO", "K60" }, { "Corsair K60 RGB PRO SE", "K60" }, { "Corsair K65 RGB", "K65" }, { "Corsair K65 LUX RGB", "K65" }, { "Corsair K68 RGB", "K68" }, { "Corsair STRAFE RGB", "Strafe" }, { "Corsair K70 RGB", "K70" }, { "Corsair K70 LUX RGB", "K70" }, { "Corsair K95 RGB", "K95" }, { "Corsair K70 RGB MK.2", "K70v2" }, { "Corsair K70 RGB MK.2 LP", "K70v2" }, { "Corsair K70 RGB MK.2 SE", "K70v2SE" }, { "Corsair STRAFE RGB MK.2", "Strafev2" }, { "Corsair K95 RGB PLATINUM", "K95Plat" }, { "Corsair K95 RGB PLATINUM XT", "K95Plat" }, { "Corsair K100 RGB", "K100" }, //Mice { "Corsair HARPOON RGB", "Harpoon" }, { "Corsair HARPOON RGB PRO", "Harpoon" }, { "Corsair HARPOON RGB WIRELESS", "Harpoon" }, { "Corsair M55 RGB", "M55" }, { "Corsair M65 RGB", "M65" }, { "Corsair M65 PRO RGB", "M65" }, { "Corsair M65 RGB ELITE", "M65" }, { "Corsair SCIMITAR RGB", "Scimitar" }, { "Corsair SCIMITAR PRO RGB", "Scimitar" }, { "Corsair SCIMITAR ELITE RGB", "Scimitar" }, { "Corsair IRONCLAW RGB", "Ironclaw" }, { "Corsair IRONCLAW RGB WIRELESS", "Ironclaw" }, { "Corsair GLAIVE RGB", "Glaive" }, { "Corsair GLAIVE RGB PRO", "Glaive" }, { "Corsair NIGHTSWORD RGB", "Nightsword" }, { "Corsair DARK CORE RGB", "DarkCore" }, { "Corsair DARK CORE RGB SE", "DarkCore" }, { "Corsair DARK CORE PRO RGB", "DarkCore" }, { "Corsair DARK CORE PRO RGB SE", "DarkCore" }, //Mousepads { "Corsair MM800RGB", "MM800" }, { "Corsair MM800CRGB", "MM800" }, //Headset Stands { "Corsair ST100RGB", "ST100" }, //Headsets { "Corsair VOID Wireless", "Void" }, { "Corsair VOID PRO Wireless", "Void" }, { "Corsair VOID ELITE Wireless", "Void" }, { "Corsair VIRTUOSO", "Virtuoso" }, { "Corsair VIRTUOSO SE", "Virtuoso" }, //DRAM { "Corsair VENGEANCE RGB PRO", "VengeancePro" }, { "Corsair VENGEANCE RGB PRO 2", "VengeancePro" }, { "Corsair VENGEANCE RGB PRO 3", "VengeancePro" }, { "Corsair VENGEANCE RGB PRO 4", "VengeancePro" }, { "Corsair VENGEANCE RGB PRO 5", "VengeancePro" }, { "Corsair VENGEANCE RGB PRO 6", "VengeancePro" }, { "Corsair VENGEANCE RGB PRO 7", "VengeancePro" }, { "Corsair VENGEANCE RGB PRO 8", "VengeancePro" }, { "Corsair DOMINATOR PLATINUM RGB", "DomPlat" }, { "Corsair DOMINATOR PLATINUM RGB 2", "DomPlat" }, { "Corsair DOMINATOR PLATINUM RGB 3", "DomPlat" }, { "Corsair DOMINATOR PLATINUM RGB 4", "DomPlat" }, { "Corsair DOMINATOR PLATINUM RGB 5", "DomPlat" }, { "Corsair DOMINATOR PLATINUM RGB 6", "DomPlat" }, { "Corsair DOMINATOR PLATINUM RGB 7", "DomPlat" }, { "Corsair DOMINATOR PLATINUM RGB 8", "DomPlat" } }; for (int i = 0; i < deviceCount; i++) { try { var tst = _CUESDK.CorsairGetDeviceInfo(i); _CorsairDeviceInfo nativeDeviceInfo = (_CorsairDeviceInfo)Marshal.PtrToStructure(tst, typeof(_CorsairDeviceInfo)); CorsairRGBDeviceInfo info = new CorsairRGBDeviceInfo(i, DeviceTypes.Other, nativeDeviceInfo, modelCounter); string friendlyName = info.DeviceName.Replace("Corsair", "").Trim(); if (!info.CapsMask.HasFlag(CorsairDeviceCaps.Lighting)) { continue; // Everything that doesn't support lighting control is useless } var nativeLedPositions = (_CorsairLedPositions)Marshal.PtrToStructure( _CUESDK.CorsairGetLedPositionsByDeviceIndex(info.CorsairDeviceIndex), typeof(_CorsairLedPositions)); int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition)); IntPtr ptr = nativeLedPositions.pLedPosition; List <_CorsairLedPosition> positions = new List <_CorsairLedPosition>(); for (int ii = 0; ii < nativeLedPositions.numberOfLed; ii++) { _CorsairLedPosition ledPosition = (_CorsairLedPosition)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition)); ptr = new IntPtr(ptr.ToInt64() + structSize); positions.Add(ledPosition); } /*using (StreamWriter sw = File.AppendText((Path.Combine(docPath, "Devices.txt")))) * { * sw.WriteLine("name: " + info.DeviceName); * }*/ string imageKey; CustomDeviceSpecification deviceSpec = null; if (imgDict.ContainsKey(info.DeviceName)) { imageKey = imgDict[info.DeviceName]; } else { switch (GetDeviceType(info.CorsairDeviceType)) { case DeviceTypes.Keyboard: imageKey = "K95Plat"; break; case DeviceTypes.Mouse: imageKey = "Scimitar"; break; case DeviceTypes.MousePad: imageKey = "MM800"; deviceSpec = new CustomDevices.MM800RGBPolaris(); break; case DeviceTypes.Headset: imageKey = "Void"; break; case DeviceTypes.HeadsetStand: imageKey = "ST100"; break; case DeviceTypes.MotherBoard: imageKey = "Motherboard"; break; case DeviceTypes.GPU: imageKey = "GPU"; break; case DeviceTypes.Cooler: imageKey = "AIO"; break; case DeviceTypes.Fan: imageKey = "QLFan"; break; case DeviceTypes.LedStrip: imageKey = "LedStrip"; break; case DeviceTypes.Memory: imageKey = "VengeancePro"; break; default: imageKey = "CorsairPlaceholder"; break; } } CorsairDevice device = new CorsairDevice { Driver = this, Name = friendlyName, ImageKey = imageKey, CorsairDeviceIndex = info.CorsairDeviceIndex, DeviceType = GetDeviceType(info.CorsairDeviceType) }; var channelsInfo = (nativeDeviceInfo.channels); if (channelsInfo != null) { IntPtr channelInfoPtr = channelsInfo.channels; if (channelsInfo.channelsCount > 0) { for (int channel = 0; channel < channelsInfo.channelsCount; channel++) { CorsairLedId channelReferenceLed = GetChannelReferenceId(info.CorsairDeviceType, channel); if (channelReferenceLed == CorsairLedId.Invalid) { continue; } _CorsairChannelInfo channelInfo = (_CorsairChannelInfo)Marshal.PtrToStructure(channelInfoPtr, typeof(_CorsairChannelInfo)); int channelDeviceInfoStructSize = Marshal.SizeOf(typeof(_CorsairChannelDeviceInfo)); IntPtr channelDeviceInfoPtr = channelInfo.devices; _CorsairChannelDeviceInfo channelDeviceInfo = (_CorsairChannelDeviceInfo)Marshal.PtrToStructure(channelDeviceInfoPtr, typeof(_CorsairChannelDeviceInfo)); if (info.CorsairDeviceType == CorsairDeviceType.Cooler && channel == 0) { //aio pump device CorsairDevice aioPumpDevice = new CorsairDevice { Driver = this, Name = "AIO Pump", ConnectedTo = "Channel " + (channel + 1), TitleOverride = info.DeviceName, ImageKey = imageKey, CorsairDeviceIndex = info.CorsairDeviceIndex, DeviceType = GetDeviceType(info.CorsairDeviceType) }; List <ControlDevice.LedUnit> leds = new List <ControlDevice.LedUnit>(); for (int devLed = 0; devLed < channelDeviceInfo.deviceLedCount; devLed++) { CorsairLedId corsairLedId = channelReferenceLed + devLed; leds.Add(new ControlDevice.LedUnit() { Data = new CorsairLedData { LEDNumber = devLed, CorsairLedId = (int)corsairLedId }, LEDName = "Pump " + devLed }); } aioPumpDevice.LEDs = leds.ToArray(); devices.Add(aioPumpDevice); } else { for (int dev = 0; dev < channelInfo.devicesCount; dev++) { CorsairLedId referenceLed = channelReferenceLed + (dev * channelDeviceInfo.deviceLedCount); string subDeviceName = "Invalid"; string subDeviceType = DeviceTypes.Other; string subImageKey = "CorsairPlaceholder"; CustomDeviceSpecification cds = null; switch (channelDeviceInfo.type) { case CorsairChannelDeviceType.Invalid: if (channelDeviceInfo.deviceLedCount == 27) { subDeviceName = "LT100RGB"; subDeviceType = DeviceTypes.LedStrip; subImageKey = "LT100"; } else { subDeviceName = "Unknown"; subDeviceType = DeviceTypes.Other; } break; case CorsairChannelDeviceType.FanHD: subDeviceName = "HD Fan"; subDeviceType = DeviceTypes.Fan; subImageKey = "HDFan"; cds = new CorsairHDFan(channelDeviceInfo.deviceLedCount); break; case CorsairChannelDeviceType.FanSP: subDeviceName = "SP Fan"; subDeviceType = DeviceTypes.Fan; subImageKey = "SPFan"; cds = new CorsairSPFan(channelDeviceInfo.deviceLedCount); break; case CorsairChannelDeviceType.FanML: subDeviceName = "ML Fan"; subDeviceType = DeviceTypes.Fan; subImageKey = "MLFan"; cds = new CorsairMLFan(channelDeviceInfo.deviceLedCount); break; case CorsairChannelDeviceType.FanLL: subDeviceName = "LL Fan"; subDeviceType = DeviceTypes.Fan; subImageKey = "LLFan"; cds = new CorsairLLFan(channelDeviceInfo.deviceLedCount); break; case CorsairChannelDeviceType.Strip: subDeviceType = DeviceTypes.LedStrip; if (channelDeviceInfo.deviceLedCount == 15) { subDeviceName = "250mm LED Strip"; subImageKey = "LS100-250mm"; cds = new CorsairLS100_250mm(channelDeviceInfo.deviceLedCount); } else if (channelDeviceInfo.deviceLedCount == 21) { subDeviceName = "350mm LED Strip"; subImageKey = "LS100-350mm"; cds = new CorsairLS100_350mm(channelDeviceInfo.deviceLedCount); } else if (channelDeviceInfo.deviceLedCount == 27) { subDeviceName = "450mm LED Strip"; subImageKey = "LS100-450mm"; cds = new CorsairLS100_450mm(channelDeviceInfo.deviceLedCount); } else if (channelDeviceInfo.deviceLedCount > 80) { subDeviceName = "1.4M LED Strip"; subImageKey = "LS100-1M"; cds = new CorsairLS100_1M(channelDeviceInfo.deviceLedCount); } else { subDeviceName = "LED Strip"; subImageKey = "LedStrip"; cds = new CorsairInternalLEDStrip(channelDeviceInfo.deviceLedCount); } break; case CorsairChannelDeviceType.DAP: subDeviceName = "DAP??"; subDeviceType = DeviceTypes.Other; cds = new GenericOther(channelDeviceInfo.deviceLedCount); break; case CorsairChannelDeviceType.FanQL: subDeviceName = "QL Fan"; subDeviceType = DeviceTypes.Fan; subImageKey = "QLFan"; cds = new CorsairQLFan(channelDeviceInfo.deviceLedCount); break; case CorsairChannelDeviceType.FanSPPro: subDeviceName = "SP PRO Fan"; subDeviceType = DeviceTypes.Fan; subImageKey = "SPProFan"; cds = new CorsairSPProFan(channelDeviceInfo.deviceLedCount); break; case CorsairChannelDeviceType.WaterBlock: subDeviceName = "HydroX Device"; subDeviceType = DeviceTypes.Cooler; subImageKey = "HydroX"; cds = new GenericOther(channelDeviceInfo.deviceLedCount); break; default: subDeviceName = "Unknown"; cds = new GenericOther(channelDeviceInfo.deviceLedCount); break; } CorsairDevice subDevice = new CorsairDevice { Driver = this, Name = subDeviceName + " " + (dev + 1) .ToString(), //make device id start at 1 not 0 because normal people use this program ConnectedTo = "Channel " + (channel + 1), TitleOverride = info.DeviceName, //ProductImage = GetImage(subImageKey), ImageKey = subImageKey, CorsairDeviceIndex = info.CorsairDeviceIndex, DeviceType = subDeviceType, CustomDeviceSpecification = deviceSpec, ChannelInfo = channelDeviceInfo, referenceLed = referenceLed }; if (cds != null) { subDevice.CustomDeviceSpecification = cds; subDevice.OverrideSupport = OverrideSupport.All; } SetDeviceOverride(subDevice, subDevice.CustomDeviceSpecification); devices.Add(subDevice); } } int channelInfoStructSize = Marshal.SizeOf(typeof(_CorsairChannelInfo)); channelInfoPtr = new IntPtr(channelInfoPtr.ToInt64() + channelInfoStructSize); } } else if (info.CorsairDeviceType == CorsairDeviceType.Keyboard) { List <ControlDevice.LedUnit> leds = new List <ControlDevice.LedUnit>(); int ctr = 0; foreach (var lp in positions.OrderBy(x => x.LedId)) { leds.Add(new ControlDevice.LedUnit() { Data = new CorsairPositionalLEDData() { LEDNumber = ctr, CorsairLedId = lp.LedId, X = (int)lp.left, Y = Math.Max(0, ((int)lp.top - 38)), }, LEDName = device.Name + " " + ctr }); ctr++; } if (positions.Any()) { int largestX = (int)positions.Max(x => x.left); int largestY = (int)positions.Max(x => x.top); device.GridHeight = largestY; device.GridWidth = largestX; device.LEDs = leds.ToArray(); } } else { List <ControlDevice.LedUnit> leds = new List <ControlDevice.LedUnit>(); int ctr = 0; foreach (var lp in positions.OrderBy(x => x.top + x.left)) { leds.Add(new ControlDevice.LedUnit() { Data = new CorsairLedData() { LEDNumber = ctr, CorsairLedId = lp.LedId }, LEDName = device.Name + " " + ctr }); ctr++; } device.LEDs = leds.ToArray(); } if (info.CorsairDeviceType == CorsairDeviceType.CommanderPro || info.CorsairDeviceType == CorsairDeviceType.LightningNodePro || info.CorsairDeviceType == CorsairDeviceType.Cooler) //filter out pointless devices { continue; //devices.Add(device); } else { devices.Add(device); } } } catch { } } foreach (ControlDevice controlDevice in devices.Where(t => t.TitleOverride != null)) { controlDevice.TitleOverride = controlDevice.TitleOverride.Replace("Corsair ", ""); } var gp = devices.GroupBy(x => x.Name); foreach (var gpx in gp) { if (gpx.ToList().Count > 1) { int ct = 0; foreach (ControlDevice controlDevice in gpx) { ct++; controlDevice.Name = controlDevice.Name + " (" + ct + ")"; } } } Debug.WriteLine("Done : " + LastError); } return(devices); }