//TODO DarthAffe 07.07.2018: DAP is a fan right now, that's most likely wrong
        /// <inheritdoc />
        /// <summary>
        /// Internal constructor of managed <see cref="T:RGB.NET.Devices.Corsair.CorsairCustomRGBDeviceInfo" />.
        /// </summary>
        /// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Corsair.CorsairCustomRGBDevice" />.</param>
        /// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
        /// <param name="channelDeviceInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairChannelDeviceInfo"/> representing this device.</param>
        /// <param name="referenceCorsairLed">The id of the first led of this device.</param>
        /// <param name="modelCounter">A dictionary containing counters to create unique names for equal devices models.</param>
        internal CorsairCustomRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, _CorsairChannelDeviceInfo channelDeviceInfo,
                                            CorsairLedId referenceCorsairLed, Dictionary <string, int> modelCounter)
            : base(deviceIndex, GetDeviceType(channelDeviceInfo.type), nativeInfo,
                   GetModelName(channelDeviceInfo.type), modelCounter)
        {
            this.ReferenceCorsairLed = referenceCorsairLed;

            LedCount = channelDeviceInfo.deviceLedCount;
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes the device.
        /// </summary>
        public void Initialize(CorsairDeviceUpdateQueue deviceUpdateQueue)
        {
            DeviceUpdateQueue = deviceUpdateQueue;

            InitializeLayout();

            foreach (Led led in LedMapping.Values)
            {
                CorsairLedId ledId = (CorsairLedId)led.CustomData;
                if (ledId != CorsairLedId.Invalid)
                {
                    InternalLedMapping.Add(ledId, led);
                }
            }

            if (Size == Size.Invalid)
            {
                Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
                Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Tests whether the specified object is a <see cref="CorsairLedId" /> and is equivalent to this <see cref="CorsairLedId" />.
        /// </summary>
        /// <param name="obj">The object to test.</param>
        /// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="CorsairLedId" /> equivalent to this <see cref="CorsairLedId" />; otherwise, <c>false</c>.</returns>
        public override bool Equals(object obj)
        {
            CorsairLedId compareLedId = obj as CorsairLedId;

            if (ReferenceEquals(compareLedId, null))
            {
                return(false);
            }

            if (ReferenceEquals(this, compareLedId))
            {
                return(true);
            }

            if (GetType() != compareLedId.GetType())
            {
                return(false);
            }

            return(compareLedId.LedId == LedId);
        }
        private static IEnumerable <ICorsairRGBDevice> GetRGBDevice(CorsairRGBDeviceInfo info, int i, _CorsairDeviceInfo nativeDeviceInfo, Dictionary <string, int> modelCounter)
        {
            switch (info.CorsairDeviceType)
            {
            case CorsairDeviceType.Keyboard:
                yield return(new CorsairKeyboardRGBDevice(new CorsairKeyboardRGBDeviceInfo(i, nativeDeviceInfo, modelCounter)));

                break;

            case CorsairDeviceType.Mouse:
                yield return(new CorsairMouseRGBDevice(new CorsairMouseRGBDeviceInfo(i, nativeDeviceInfo, modelCounter)));

                break;

            case CorsairDeviceType.Headset:
                yield return(new CorsairHeadsetRGBDevice(new CorsairHeadsetRGBDeviceInfo(i, nativeDeviceInfo, modelCounter)));

                break;

            case CorsairDeviceType.Mousepad:
                yield return(new CorsairMousepadRGBDevice(new CorsairMousepadRGBDeviceInfo(i, nativeDeviceInfo, modelCounter)));

                break;

            case CorsairDeviceType.HeadsetStand:
                yield return(new CorsairHeadsetStandRGBDevice(new CorsairHeadsetStandRGBDeviceInfo(i, nativeDeviceInfo, modelCounter)));

                break;

            case CorsairDeviceType.MemoryModule:
                yield return(new CorsairMemoryRGBDevice(new CorsairMemoryRGBDeviceInfo(i, nativeDeviceInfo, modelCounter)));

                break;

            case CorsairDeviceType.Cooler:
            case CorsairDeviceType.CommanderPro:
            case CorsairDeviceType.LightningNodePro:
                _CorsairChannelsInfo channelsInfo = nativeDeviceInfo.channels;
                if (channelsInfo != null)
                {
                    IntPtr channelInfoPtr = channelsInfo.channels;

                    for (int channel = 0; channel < channelsInfo.channelsCount; channel++)
                    {
                        CorsairLedId referenceLed = channel == 0 ? CorsairLedId.CustomDeviceChannel1Led1 : CorsairLedId.CustomDeviceChannel2Led1;

                        _CorsairChannelInfo channelInfo = (_CorsairChannelInfo)Marshal.PtrToStructure(channelInfoPtr, typeof(_CorsairChannelInfo));

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

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

                            yield return(new CorsairCustomRGBDevice(new CorsairCustomRGBDeviceInfo(info.CorsairDeviceIndex, nativeDeviceInfo, channelDeviceInfo, referenceLed, modelCounter)));

                            referenceLed += channelDeviceInfo.deviceLedCount;

                            channelDeviceInfoPtr = new IntPtr(channelDeviceInfoPtr.ToInt64() + channelDeviceInfoStructSize);
                        }

                        int channelInfoStructSize = Marshal.SizeOf(typeof(_CorsairChannelInfo));
                        channelInfoPtr = new IntPtr(channelInfoPtr.ToInt64() + channelInfoStructSize);
                    }
                }

                break;


            // ReSharper disable once RedundantCaseLabel
            case CorsairDeviceType.Unknown:
            default:
                throw new RGBDeviceException("Unknown Device-Type");
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Gets the <see cref="Led"/> with the specified <see cref="CorsairLedId"/>.
 /// </summary>
 /// <param name="ledId">The <see cref="CorsairLedId"/> of the <see cref="Led"/> to get.</param>
 /// <returns>The <see cref="Led"/> with the specified <see cref="CorsairLedId"/> or null if no <see cref="Led"/> is found.</returns>
 // ReSharper disable once MemberCanBePrivate.Global
 public Led this[CorsairLedId ledId] => InternalLedMapping.TryGetValue(ledId, out Led led) ? led : null;