Beispiel #1
0
        /// <inheritdoc />
        /// <summary>
        /// Internal constructor of managed <see cref="T:RGB.NET.Devices.Corsair.CorsairMouseRGBDeviceInfo" />.
        /// </summary>
        /// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Corsair.CorsairMouseRGBDevice" />.</param>
        /// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
        internal CorsairMouseRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
            : base(deviceIndex, RGBDeviceType.Mouse, nativeInfo)
        {
            this.PhysicalLayout = (CorsairPhysicalMouseLayout)nativeInfo.physicalLayout;

            Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Corsair\Mice\{Model.Replace(" ", string.Empty).ToUpper()}.png"), UriKind.Absolute);
        }
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>
 internal CorsairRGBDeviceInfo(int deviceIndex, RGBDeviceType deviceType, _CorsairDeviceInfo nativeInfo)
 {
     this.CorsairDeviceIndex = deviceIndex;
     this.DeviceType         = deviceType;
     this.CorsairDeviceType  = nativeInfo.type;
     this.Model    = nativeInfo.model == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(nativeInfo.model);
     this.CapsMask = (CorsairDeviceCaps)nativeInfo.capsMask;
 }
        //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;
        }
Beispiel #4
0
        /// <inheritdoc />
        /// <summary>
        /// Internal constructor of managed <see cref="T:RGB.NET.Devices.Corsair.CorsairKeyboardRGBDeviceInfo" />.
        /// </summary>
        /// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Corsair.CorsairKeyboardRGBDevice" />.</param>
        /// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
        internal CorsairKeyboardRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
            : base(deviceIndex, RGBDeviceType.Keyboard, nativeInfo)
        {
            this.PhysicalLayout = (CorsairPhysicalKeyboardLayout)nativeInfo.physicalLayout;
            this.LogicalLayout  = (CorsairLogicalKeyboardLayout)nativeInfo.logicalLayout;

            string model = Model.Replace(" ", string.Empty).ToUpper();

            Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Corsair\Keyboards\{model}.png"), UriKind.Absolute);
        }
        /// <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, RGBDeviceType 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);
        }
        /// <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="modelName">The name of the device-model (overwrites the one provided with the device info).</param>
        /// <param name="modelCounter">A dictionary containing counters to create unique names for equal devices models.</param>
        internal CorsairRGBDeviceInfo(int deviceIndex, RGBDeviceType 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 #7
0
        /// <summary>
        /// Initializes the headset stand.
        /// </summary>
        public override void Initialize()
        {
            int deviceCount = _CUESDK.CorsairGetDeviceCount();

            // Get headset stand device index
            int MemoryModuleIndex = -1;

            for (int i = 0; i < deviceCount; i++)
            {
                _CorsairDeviceInfo nativeDeviceInfo = (_CorsairDeviceInfo)Marshal.PtrToStructure(_CUESDK.CorsairGetDeviceInfo(i), typeof(_CorsairDeviceInfo));
                GenericDeviceInfo  info             = new GenericDeviceInfo(nativeDeviceInfo);
                if (info.Type != CorsairDeviceType.MemoryModule)
                {
                    continue;
                }

                MemoryModuleIndex = i;
                break;
            }
            if (MemoryModuleIndex < 0)
            {
                throw new WrapperException("Can't determine headset stand device index");
            }

            _CorsairLedPositions nativeLedPositions = (_CorsairLedPositions)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositionsByDeviceIndex(MemoryModuleIndex), typeof(_CorsairLedPositions));
            int    structSize = Marshal.SizeOf(typeof(_CorsairLedPosition));
            IntPtr ptr        = nativeLedPositions.pLedPosition;

            // Put the positions in an array for sorting later on
            List <_CorsairLedPosition> positions = new List <_CorsairLedPosition>();

            for (int i = 0; i < nativeLedPositions.numberOfLed; i++)
            {
                _CorsairLedPosition ledPosition = (_CorsairLedPosition)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition));
                ptr = new IntPtr(ptr.ToInt64() + structSize);
                positions.Add(ledPosition);
            }

            // Sort for easy iteration by clients
            foreach (_CorsairLedPosition ledPosition in positions.OrderBy(p => p.ledId))
            {
                InitializeLed(ledPosition.ledId, new RectangleF((float)ledPosition.left, (float)ledPosition.top, (float)ledPosition.width, (float)ledPosition.height));
            }

            base.Initialize();
        }
Beispiel #8
0
        /// <inheritdoc />
        /// <exception cref="RGBDeviceException">Thrown if the SDK is already initialized or if the SDK is not compatible to CUE.</exception>
        /// <exception cref="CUEException">Thrown if the CUE-SDK provides an error.</exception>
        public bool Initialize(bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
        {
            IsInitialized = false;

            try
            {
                _CUESDK.Reload();

                ProtocolDetails = new CorsairProtocolDetails(_CUESDK.CorsairPerformProtocolHandshake());

                CorsairError error = LastError;
                if (error != CorsairError.Success)
                {
                    throw new CUEException(error);
                }

                if (ProtocolDetails.BreakingChanges)
                {
                    throw new RGBDeviceException("The SDK currently used isn't compatible with the installed version of CUE.\r\n"
                                                 + $"CUE-Version: {ProtocolDetails.ServerVersion} (Protocol {ProtocolDetails.ServerProtocolVersion})\r\n"
                                                 + $"SDK-Version: {ProtocolDetails.SdkVersion} (Protocol {ProtocolDetails.SdkProtocolVersion})");
                }

                if (exclusiveAccessIfPossible)
                {
                    if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl))
                    {
                        throw new CUEException(LastError);
                    }

                    HasExclusiveAccess = true;
                }
                else
                {
                    HasExclusiveAccess = false;
                }

                IList <IRGBDevice> devices = new List <IRGBDevice>();
                int deviceCount            = _CUESDK.CorsairGetDeviceCount();
                for (int i = 0; i < deviceCount; i++)
                {
                    try
                    {
                        _CorsairDeviceInfo   nativeDeviceInfo = (_CorsairDeviceInfo)Marshal.PtrToStructure(_CUESDK.CorsairGetDeviceInfo(i), typeof(_CorsairDeviceInfo));
                        CorsairRGBDeviceInfo info             = new CorsairRGBDeviceInfo(i, RGBDeviceType.Unknown, nativeDeviceInfo);
                        if (!info.CapsMask.HasFlag(CorsairDeviceCaps.Lighting))
                        {
                            continue; // Everything that doesn't support lighting control is useless
                        }
                        ICorsairRGBDevice device;
                        switch (info.CorsairDeviceType)
                        {
                        case CorsairDeviceType.Keyboard:
                            device = new CorsairKeyboardRGBDevice(new CorsairKeyboardRGBDeviceInfo(i, nativeDeviceInfo));
                            break;

                        case CorsairDeviceType.Mouse:
                            device = new CorsairMouseRGBDevice(new CorsairMouseRGBDeviceInfo(i, nativeDeviceInfo));
                            break;

                        case CorsairDeviceType.Headset:
                            device = new CorsairHeadsetRGBDevice(new CorsairHeadsetRGBDeviceInfo(i, nativeDeviceInfo));
                            break;

                        case CorsairDeviceType.Mousepad:
                            device = new CorsairMousepadRGBDevice(new CorsairMousepadRGBDeviceInfo(i, nativeDeviceInfo));
                            break;

                        case CorsairDeviceType.HeadsetStand:
                            device = new CorsairHeadsetStandRGBDevice(new CorsairHeadsetStandRGBDeviceInfo(i, nativeDeviceInfo));
                            break;

                        // ReSharper disable once RedundantCaseLabel
                        case CorsairDeviceType.Unknown:
                        default:
                            throw new RGBDeviceException("Unknown Device-Type");
                        }
                        device.Initialize();
                        AddSpecialParts(device);

                        error = LastError;
                        if (error != CorsairError.Success)
                        {
                            throw new CUEException(error);
                        }

                        devices.Add(device);
                    }
                    catch { if (throwExceptions)
                            {
                                throw;
                            }
                    }
                }

                Devices       = new ReadOnlyCollection <IRGBDevice>(devices);
                IsInitialized = true;
            }
            catch
            {
                Reset();
                if (throwExceptions)
                {
                    throw;
                }
                return(false);
            }

            return(true);
        }
 /// <inheritdoc />
 /// <summary>
 /// Internal constructor of managed <see cref="T:RGB.NET.Devices.Corsair.CorsairKeyboardRGBDeviceInfo" />.
 /// </summary>
 /// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Corsair.CorsairKeyboardRGBDevice" />.</param>
 /// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
 /// <param name="modelCounter">A dictionary containing counters to create unique names for equal devices models.</param>
 internal CorsairKeyboardRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, Dictionary <string, int> modelCounter)
     : base(deviceIndex, RGBDeviceType.Keyboard, nativeInfo, modelCounter)
 {
     this.PhysicalLayout = (CorsairPhysicalKeyboardLayout)nativeInfo.physicalLayout;
     this.LogicalLayout  = (CorsairLogicalKeyboardLayout)nativeInfo.logicalLayout;
 }
 /// <summary>
 /// Internal constructor of managed <see cref="CorsairCoolerDeviceInfo" />.
 /// </summary>
 /// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param>
 internal CorsairCoolerDeviceInfo(_CorsairDeviceInfo nativeInfo)
     : base(nativeInfo)
 {
 }
 /// <inheritdoc />
 /// <summary>
 /// Internal constructor of managed <see cref="T:RGB.NET.Devices.Corsair.CorsairKeyboardRGBDeviceInfo" />.
 /// </summary>
 /// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Corsair.CorsairKeyboardRGBDevice" />.</param>
 /// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
 internal CorsairKeyboardRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
     : base(deviceIndex, RGBDeviceType.Keyboard, nativeInfo)
 {
     this.PhysicalLayout = (CorsairPhysicalKeyboardLayout)nativeInfo.physicalLayout;
     this.LogicalLayout  = (CorsairLogicalKeyboardLayout)nativeInfo.logicalLayout;
 }
        /// <inheritdoc />
        /// <exception cref="RGBDeviceException">Thrown if the SDK is already initialized or if the SDK is not compatible to CUE.</exception>
        /// <exception cref="CUEException">Thrown if the CUE-SDK provides an error.</exception>
        public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
        {
            IsInitialized = false;

            try
            {
                UpdateTrigger?.Stop();

                _CUESDK.Reload();

                ProtocolDetails = new CorsairProtocolDetails(_CUESDK.CorsairPerformProtocolHandshake());

                CorsairError error = LastError;
                if (error != CorsairError.Success)
                {
                    throw new CUEException(error);
                }

                if (ProtocolDetails.BreakingChanges)
                {
                    throw new RGBDeviceException("The SDK currently used isn't compatible with the installed version of CUE.\r\n"
                                                 + $"CUE-Version: {ProtocolDetails.ServerVersion} (Protocol {ProtocolDetails.ServerProtocolVersion})\r\n"
                                                 + $"SDK-Version: {ProtocolDetails.SdkVersion} (Protocol {ProtocolDetails.SdkProtocolVersion})");
                }

                if (exclusiveAccessIfPossible)
                {
                    if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl))
                    {
                        throw new CUEException(LastError);
                    }

                    HasExclusiveAccess = true;
                }
                else
                {
                    HasExclusiveAccess = false;
                }

                // DarthAffe 07.07.2018: 127 is CUE, we want to directly compete with it as in older versions.
                if (!_CUESDK.CorsairSetLayerPriority(127))
                {
                    throw new CUEException(LastError);
                }

                Dictionary <string, int> modelCounter = new Dictionary <string, int>();
                IList <IRGBDevice>       devices      = new List <IRGBDevice>();
                int deviceCount = _CUESDK.CorsairGetDeviceCount();
                for (int i = 0; i < deviceCount; i++)
                {
                    try
                    {
                        _CorsairDeviceInfo   nativeDeviceInfo = (_CorsairDeviceInfo)Marshal.PtrToStructure(_CUESDK.CorsairGetDeviceInfo(i), typeof(_CorsairDeviceInfo));
                        CorsairRGBDeviceInfo info             = new CorsairRGBDeviceInfo(i, RGBDeviceType.Unknown, nativeDeviceInfo, modelCounter);
                        if (!info.CapsMask.HasFlag(CorsairDeviceCaps.Lighting))
                        {
                            continue; // Everything that doesn't support lighting control is useless
                        }
                        CorsairDeviceUpdateQueue deviceUpdateQueue = null;
                        foreach (ICorsairRGBDevice device in GetRGBDevice(info, i, nativeDeviceInfo, modelCounter))
                        {
                            if ((device == null) || !loadFilter.HasFlag(device.DeviceInfo.DeviceType))
                            {
                                continue;
                            }

                            if (deviceUpdateQueue == null)
                            {
                                deviceUpdateQueue = new CorsairDeviceUpdateQueue(UpdateTrigger, info.CorsairDeviceIndex);
                            }

                            device.Initialize(deviceUpdateQueue);
                            AddSpecialParts(device);

                            error = LastError;
                            if (error != CorsairError.Success)
                            {
                                throw new CUEException(error);
                            }

                            devices.Add(device);
                        }
                    }
                    catch { if (throwExceptions)
                            {
                                throw;
                            }
                    }
                }

                UpdateTrigger?.Start();

                Devices       = new ReadOnlyCollection <IRGBDevice>(devices);
                IsInitialized = true;
            }
            catch
            {
                Reset();
                if (throwExceptions)
                {
                    throw;
                }
                return(false);
            }

            return(true);
        }
Beispiel #13
0
 /// <summary>
 /// Internal constructor of managed <see cref="CorsairMouseDeviceInfo" />.
 /// </summary>
 /// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param>
 internal CorsairMouseDeviceInfo(_CorsairDeviceInfo nativeInfo)
     : base(nativeInfo)
 {
     this.PhysicalLayout = (CorsairPhysicalMouseLayout)nativeInfo.physicalLayout;
 }
Beispiel #14
0
 /// <inheritdoc />
 /// <summary>
 /// Internal constructor of managed <see cref="T:RGB.NET.Devices.Corsair.CorsairHeadsetStandRGBDeviceInfo" />.
 /// </summary>
 /// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Corsair.CorsairHeadsetStandRGBDevice" />.</param>
 /// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
 /// <param name="modelCounter">A dictionary containing counters to create unique names for equal devices models.</param>
 internal CorsairHeadsetStandRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, Dictionary <string, int> modelCounter)
     : base(deviceIndex, RGBDeviceType.HeadsetStand, nativeInfo, modelCounter)
 {
 }
 /// <inheritdoc />
 /// <summary>
 /// Internal constructor of managed <see cref="T:RGB.NET.Devices.Corsair.CorsairMousepadRGBDeviceInfo" />.
 /// </summary>
 /// <param name="deviceIndex">The index if the <see cref="T:RGB.NET.Devices.Corsair.CorsairMousepadRGBDevice" />.</param>
 /// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
 internal CorsairMousepadRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
     : base(deviceIndex, RGBDeviceType.Mousepad, nativeInfo)
 {
 }
 /// <summary>
 /// Internal constructor of managed <see cref="CorsairMemoryModuleDeviceInfo" />.
 /// </summary>
 /// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param>
 internal CorsairMemoryModuleDeviceInfo(_CorsairDeviceInfo nativeInfo)
     : base(nativeInfo)
 {
 }
Beispiel #17
0
        // ReSharper disable once ExceptionNotThrown
        /// <summary>
        /// Initializes the CUE-SDK. This method should be called exactly ONE time, before anything else is done.
        /// </summary>
        /// <param name="exclusiveAccess">Specifies whether the application should request exclusive access or not.</param>
        /// <exception cref="WrapperException">Thrown if the SDK is already initialized, the SDK is not compatible to CUE or if CUE returns unknown devices.</exception>
        /// <exception cref="CUEException">Thrown if the CUE-SDK provides an error.</exception>
        public static void Initialize(bool exclusiveAccess = false)
        {
            if (IsInitialized)
            {
                throw new WrapperException("CueSDK is already initialized.");
            }

            _CUESDK.Reload();

            ProtocolDetails = new CorsairProtocolDetails(_CUESDK.CorsairPerformProtocolHandshake());

            CorsairError error = LastError;

            if (error != CorsairError.Success)
            {
                Throw(error, true);
            }

            if (ProtocolDetails.BreakingChanges)
            {
                throw new WrapperException("The SDK currently used isn't compatible with the installed version of CUE.\r\n"
                                           + $"CUE-Version: {ProtocolDetails.ServerVersion} (Protocol {ProtocolDetails.ServerProtocolVersion})\r\n"
                                           + $"SDK-Version: {ProtocolDetails.SdkVersion} (Protocol {ProtocolDetails.SdkProtocolVersion})");
            }

            if (exclusiveAccess)
            {
                if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl))
                {
                    Throw(LastError, true);
                }

                HasExclusiveAccess = true;
            }

            IList <ICueDevice> devices = new List <ICueDevice>();
            int deviceCount            = _CUESDK.CorsairGetDeviceCount();

            for (int i = 0; i < deviceCount; i++)
            {
                _CorsairDeviceInfo nativeDeviceInfo = (_CorsairDeviceInfo)Marshal.PtrToStructure(_CUESDK.CorsairGetDeviceInfo(i), typeof(_CorsairDeviceInfo));
                GenericDeviceInfo  info             = new GenericDeviceInfo(nativeDeviceInfo);
                if (!info.CapsMask.HasFlag(CorsairDeviceCaps.Lighting))
                {
                    continue; // Everything that doesn't support lighting control is useless
                }
                ICueDevice device;
                switch (info.Type)
                {
                case CorsairDeviceType.Keyboard:
                    device = KeyboardSDK = new CorsairKeyboard(new CorsairKeyboardDeviceInfo(nativeDeviceInfo));
                    break;

                case CorsairDeviceType.Mouse:
                    device = MouseSDK = new CorsairMouse(new CorsairMouseDeviceInfo(nativeDeviceInfo));
                    break;

                case CorsairDeviceType.Headset:
                    device = HeadsetSDK = new CorsairHeadset(new CorsairHeadsetDeviceInfo(nativeDeviceInfo));
                    break;

                case CorsairDeviceType.Mousemat:
                    device = MousematSDK = new CorsairMousemat(new CorsairMousematDeviceInfo(nativeDeviceInfo));
                    break;

                case CorsairDeviceType.HeadsetStand:
                    device = HeadsetStandSDK = new CorsairHeadsetStand(new CorsairHeadsetStandDeviceInfo(nativeDeviceInfo));
                    break;

                // ReSharper disable once RedundantCaseLabel
                case CorsairDeviceType.Unknown:
                default:
                    throw new WrapperException("Unknown Device-Type");
                }

                device.Initialize();
                devices.Add(device);

                error = LastError;
                if (error != CorsairError.Success)
                {
                    Throw(error, true);
                }
            }

            error = LastError;
            if (error != CorsairError.Success)
            {
                Throw(error, false);
            }

            InitializedDevices = new ReadOnlyCollection <ICueDevice>(devices);

            IsInitialized = true;
        }
Beispiel #18
0
 /// <inheritdoc />
 /// <summary>
 /// Internal constructor of managed <see cref="T:RGB.NET.Devices.Corsair.CorsairMouseRGBDeviceInfo" />.
 /// </summary>
 /// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Corsair.CorsairMouseRGBDevice" />.</param>
 /// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
 /// <param name="modelCounter">A dictionary containing counters to create unique names for equal devices models.</param>
 internal CorsairMouseRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, Dictionary <string, int> modelCounter)
     : base(deviceIndex, RGBDeviceType.Mouse, nativeInfo, modelCounter)
 {
     this.PhysicalLayout = (CorsairPhysicalMouseLayout)nativeInfo.physicalLayout;
 }
 /// <summary>
 /// Internal constructor of managed <see cref="CorsairCommanderProDeviceInfo" />.
 /// </summary>
 /// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param>
 internal CorsairCommanderProDeviceInfo(_CorsairDeviceInfo nativeInfo)
     : base(nativeInfo)
 {
 }
 /// <summary>
 /// Internal constructor of managed <see cref="CorsairHeadsetStandDeviceInfo" />.
 /// </summary>
 /// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param>
 internal CorsairHeadsetStandDeviceInfo(_CorsairDeviceInfo nativeInfo)
     : base(nativeInfo)
 {
 }
 /// <summary>
 /// Internal constructor of managed <see cref="CorsairLightingNodeProDeviceInfo" />.
 /// </summary>
 /// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param>
 internal CorsairLightingNodeProDeviceInfo(_CorsairDeviceInfo nativeInfo)
     : base(nativeInfo)
 {
 }
Beispiel #22
0
        private static ICorsairRGBDevice GetRGBDevice(CorsairRGBDeviceInfo info, int i, _CorsairDeviceInfo nativeDeviceInfo)
        {
            switch (info.CorsairDeviceType)
            {
            case CorsairDeviceType.Keyboard:
                return(new CorsairKeyboardRGBDevice(new CorsairKeyboardRGBDeviceInfo(i, nativeDeviceInfo)));

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

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

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

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

            // ReSharper disable once RedundantCaseLabel
            case CorsairDeviceType.Unknown:
            default:
                throw new RGBDeviceException("Unknown Device-Type");
            }
        }
Beispiel #23
0
 /// <inheritdoc />
 /// <summary>
 /// Internal constructor of managed <see cref="T:RGB.NET.Devices.Corsair.CorsairMouseRGBDeviceInfo" />.
 /// </summary>
 /// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Corsair.CorsairMouseRGBDevice" />.</param>
 /// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
 internal CorsairMouseRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
     : base(deviceIndex, RGBDeviceType.Mouse, nativeInfo)
 {
     this.PhysicalLayout = (CorsairPhysicalMouseLayout)nativeInfo.physicalLayout;
 }
Beispiel #24
0
 /// <inheritdoc />
 /// <summary>
 /// Internal constructor of managed <see cref="T:RGB.NET.Devices.Corsair.CorsairHeadsetRGBDeviceInfo" />.
 /// </summary>
 /// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Corsair.CorsairHeadsetRGBDevice" />.</param>
 /// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
 internal CorsairHeadsetRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
     : base(deviceIndex, RGBDeviceType.Headset, nativeInfo)
 {
     Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Corsair\Headsets\{Model.Replace(" ", string.Empty).ToUpper()}.png"), UriKind.Absolute);
 }
Beispiel #25
0
 /// <summary>
 /// Internal constructor of managed CorsairDeviceInfo.
 /// </summary>
 /// <param name="nativeInfo">The native CorsairDeviceInfo-struct</param>
 internal CorsairKeyboardDeviceInfo(_CorsairDeviceInfo nativeInfo)
     : base(nativeInfo)
 {
     this.PhysicalLayout = (CorsairPhysicalKeyboardLayout)nativeInfo.physicalLayout;
     this.LogicalLayout  = (CorsairLogicalKeyboardLayout)nativeInfo.logicalLayout;
 }
Beispiel #26
0
 /// <summary>
 ///   Internal constructor of managed <see cref="CorsairMousematDeviceInfo" />.
 /// </summary>
 /// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param>
 internal CorsairMousematDeviceInfo(_CorsairDeviceInfo nativeInfo) : base(nativeInfo)
 {
 }
Beispiel #27
0
 /// <summary>
 ///   Internal constructor of managed <see cref="GenericDeviceInfo" />.
 /// </summary>
 /// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param>
 internal GenericDeviceInfo(_CorsairDeviceInfo nativeInfo)
 {
     Type     = nativeInfo.type;
     Model    = nativeInfo.model == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(nativeInfo.model);
     CapsMask = (CorsairDeviceCaps)nativeInfo.capsMask;
 }
 /// <inheritdoc />
 /// <summary>
 /// Internal constructor of managed <see cref="T:RGB.NET.Devices.Corsair.CorsairHeadsetRGBDeviceInfo" />.
 /// </summary>
 /// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Corsair.CorsairHeadsetRGBDevice" />.</param>
 /// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
 internal CorsairHeadsetRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
     : base(deviceIndex, RGBDeviceType.Headset, nativeInfo)
 {
 }
        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");
            }
        }
Beispiel #30
0
 /// <inheritdoc />
 /// <summary>
 /// Internal constructor of managed <see cref="T:RGB.NET.Devices.Corsair.CorsairMemoryRGBDeviceInfo" />.
 /// </summary>
 /// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Corsair.CorsairMemoryRGBDevice" />.</param>
 /// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
 /// <param name="modelCounter">A dictionary containing counters to create unique names for equal devices models.</param>
 internal CorsairMemoryRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, Dictionary <string, int> modelCounter)
     : base(deviceIndex, RGBDeviceType.DRAM, nativeInfo, modelCounter)
 {
 }