Beispiel #1
0
        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);
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
        public List <ControlDevice> GetDevices()
        {
            List <ControlDevice>     devices      = new List <ControlDevice>();
            Dictionary <string, int> modelCounter = new Dictionary <string, int>();

            int deviceCount = _CUESDK.CorsairGetDeviceCount();

            var imgDict = new Dictionary <string, string>()
            {
                //Keyboards
                { "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" },

                //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 RGB Wireless", "Virtuoso" },
                { "Corsair VIRTUOSO SE RGB Wireless", "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++)
            {
                var tst = _CUESDK.CorsairGetDeviceInfo(i);
                _CorsairDeviceInfo nativeDeviceInfo = (_CorsairDeviceInfo)Marshal.PtrToStructure(tst, typeof(_CorsairDeviceInfo));
                Debug.WriteLine(nativeDeviceInfo.ledsCount + " leds");
                CorsairRGBDeviceInfo info = new CorsairRGBDeviceInfo(i, DeviceTypes.Other, nativeDeviceInfo, modelCounter);
                string friendlyName       = info.DeviceName.Replace("Corsair", "");
                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);
                }

                Debug.WriteLine(info.DeviceName);

                /*using (StreamWriter sw = File.AppendText((Path.Combine(docPath, "Devices.txt"))))
                 * {
                 *  sw.WriteLine("name: " + info.DeviceName);
                 * }*/

                string imageKey;

                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";
                        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,
                    ProductImage       = GetImage(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++)
                        {
                            _CorsairChannelInfo channelInfo = (_CorsairChannelInfo)Marshal.PtrToStructure(channelInfoPtr, typeof(_CorsairChannelInfo));

                            int    channelDeviceInfoStructSize = Marshal.SizeOf(typeof(_CorsairChannelDeviceInfo));
                            IntPtr channelDeviceInfoPtr        = channelInfo.devices;

                            for (int dev = 0; dev < channelInfo.devicesCount; dev++)
                            {
                                _CorsairChannelDeviceInfo channelDeviceInfo = (_CorsairChannelDeviceInfo)Marshal.PtrToStructure(channelDeviceInfoPtr, typeof(_CorsairChannelDeviceInfo));

                                CorsairLedId channelReferenceLed = GetChannelReferenceId(info.CorsairDeviceType, channel);
                                CorsairLedId referenceLed        = channelReferenceLed + (dev * channelDeviceInfo.deviceLedCount);

                                List <ControlDevice.LedUnit> leds = new List <ControlDevice.LedUnit>();

                                string subDeviceName = "Invalid";
                                string subDeviceType = DeviceTypes.Other;
                                string subImageKey   = "CorsairPlaceholder";

                                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";
                                    break;

                                case CorsairChannelDeviceType.FanSP:
                                    subDeviceName = "SP Fan";
                                    subDeviceType = DeviceTypes.Fan;
                                    subImageKey   = "SPFan";
                                    break;

                                case CorsairChannelDeviceType.FanML:
                                    subDeviceName = "ML Fan";
                                    subDeviceType = DeviceTypes.Fan;
                                    subImageKey   = "MLFan";
                                    break;

                                case CorsairChannelDeviceType.FanLL:
                                    subDeviceName = "LL Fan";
                                    subDeviceType = DeviceTypes.Fan;
                                    subImageKey   = "LLFan";
                                    break;

                                case CorsairChannelDeviceType.Strip:
                                    subDeviceType = DeviceTypes.LedStrip;
                                    if (channelDeviceInfo.deviceLedCount > 10)
                                    {
                                        subDeviceName = "LS100 LED Strip";
                                        subImageKey   = "LS100";
                                    }
                                    else
                                    {
                                        subDeviceName = "Internal LED Strip";
                                        subImageKey   = "LedStrip";
                                    }
                                    break;

                                case CorsairChannelDeviceType.DAP:
                                    subDeviceName = "DAP??";
                                    subDeviceType = DeviceTypes.Other;
                                    break;

                                case CorsairChannelDeviceType.FanQL:
                                    subDeviceName = "QL Fan";
                                    subDeviceType = DeviceTypes.Fan;
                                    subImageKey   = "QLFan";
                                    break;

                                default:
                                    subDeviceName = "Unknown";
                                    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
                                    ProductImage       = GetImage(subImageKey),
                                    CorsairDeviceIndex = info.CorsairDeviceIndex,
                                    DeviceType         = subDeviceType
                                };

                                for (int devLed = 0; devLed < channelDeviceInfo.deviceLedCount; devLed++)
                                {
                                    //Fanman's ugly code for LED mapping. Abandon hope all ye who have to troublshoot this dumpster-fire of magic numbers.
                                    CorsairLedId corsairLedId;
                                    if (channelDeviceInfo.deviceLedCount > 30)
                                    {
                                        if ((int)referenceLed > 369 && (int)referenceLed != 350 && (int)referenceLed != 384 && (int)referenceLed != 418 && (int)referenceLed != 452 && (int)referenceLed != 486)
                                        {
                                            corsairLedId = referenceLed + 562 + devLed;
                                        }
                                        else if ((int)referenceLed > 335 && (int)referenceLed != 350 && (int)referenceLed != 384 && (int)referenceLed != 418 && (int)referenceLed != 452 && (int)referenceLed != 486)
                                        {
                                            if (devLed < 14)
                                            {
                                                corsairLedId = referenceLed + devLed;
                                            }
                                            else
                                            {
                                                corsairLedId = referenceLed + 562 + devLed;
                                            }
                                        }
                                        //ch2
                                        else if ((int)referenceLed >= 486)
                                        {
                                            if (devLed < 14)
                                            {
                                                corsairLedId = referenceLed + devLed;
                                            }
                                            else
                                            {
                                                corsairLedId = referenceLed + 562 + devLed;
                                            }
                                        }
                                        else
                                        {
                                            corsairLedId = referenceLed + devLed;
                                        }
                                    }
                                    else
                                    {
                                        corsairLedId = referenceLed + devLed;
                                    }



                                    leds.Add(new ControlDevice.LedUnit()
                                    {
                                        Data = new CorsairLedData
                                        {
                                            LEDNumber    = devLed,
                                            CorsairLedId = (int)corsairLedId
                                        },
                                        LEDName = device.Name + " " + devLed
                                    });
                                }
                                subDevice.LEDs = leds.ToArray();
                                devices.Add(subDevice);
                            }
                        }
                    }
                    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
                            });
                        }

                        //for (int l = 0; l < nativeDeviceInfo.ledsCount; l++)
                        //{
                        //    leds.Add(new ControlDevice.LedUnit
                        //    {
                        //        Data = new ControlDevice.LEDData { LEDNumber = l },
                        //        LEDName = "LED " + l,

                        //    });
                        //}

                        device.LEDs = leds.ToArray();
                    }
                    if (info.CorsairDeviceType == CorsairDeviceType.CommanderPro || info.CorsairDeviceType == CorsairDeviceType.LightningNodePro) //filter out pointless devices
                    {
                        continue;
                    }
                    else
                    {
                        devices.Add(device);
                    }
                }
            }

            Debug.WriteLine("Done : " + LastError);
            return(devices);
        }