Example #1
0
        /// <inheritdoc />
        public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
        {
            IsInitialized = false;

            try
            {
                UpdateTrigger?.Stop();

                _CoolerMasterSDK.Reload();
                if (_CoolerMasterSDK.GetSDKVersion() <= 0)
                {
                    return(false);
                }

                IList <IRGBDevice> devices = new List <IRGBDevice>();

                foreach (CoolerMasterDevicesIndexes index in Enum.GetValues(typeof(CoolerMasterDevicesIndexes)))
                {
                    try
                    {
                        RGBDeviceType deviceType = index.GetDeviceType();
                        if (deviceType == RGBDeviceType.None)
                        {
                            continue;
                        }

                        if (_CoolerMasterSDK.IsDevicePlugged(index))
                        {
                            if (!loadFilter.HasFlag(deviceType))
                            {
                                continue;
                            }

                            ICoolerMasterRGBDevice device;
                            switch (deviceType)
                            {
                            case RGBDeviceType.Keyboard:
                                CoolerMasterPhysicalKeyboardLayout physicalLayout = _CoolerMasterSDK.GetDeviceLayout(index);
                                device = new CoolerMasterKeyboardRGBDevice(new CoolerMasterKeyboardRGBDeviceInfo(index, physicalLayout, GetCulture()));
                                break;

                            case RGBDeviceType.Mouse:
                                device = new CoolerMasterMouseRGBDevice(new CoolerMasterMouseRGBDeviceInfo(index));
                                break;

                            default:
                                if (throwExceptions)
                                {
                                    throw new RGBDeviceException("Unknown Device-Type");
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            _CoolerMasterSDK.EnableLedControl(true, index);

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

                UpdateTrigger?.Start();

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

            return(true);
        }
        /// <inheritdoc />
        /// <summary>
        /// Internal constructor of managed <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDeviceInfo" />.
        /// </summary>
        /// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDevice" />.</param>
        /// <param name="physicalKeyboardLayout">The <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterPhysicalKeyboardLayout" /> of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDevice" />.</param>
        /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> of the layout this keyboard is using</param>
        internal CoolerMasterKeyboardRGBDeviceInfo(CoolerMasterDevicesIndexes deviceIndex, CoolerMasterPhysicalKeyboardLayout physicalKeyboardLayout, CultureInfo culture)
            : base(RGBDeviceType.Keyboard, deviceIndex)
        {
            this.PhysicalLayout = physicalKeyboardLayout;

            SetLayouts(culture.KeyboardLayoutId);
        }
Example #3
0
        /// <inheritdoc />
        /// <summary>
        /// Internal constructor of managed <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDeviceInfo" />.
        /// </summary>
        /// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDevice" />.</param>
        /// <param name="physicalKeyboardLayout">The <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterPhysicalKeyboardLayout" /> of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDevice" />.</param>
        /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> of the layout this keyboard is using</param>
        internal CoolerMasterKeyboardRGBDeviceInfo(CoolerMasterDevicesIndexes deviceIndex, CoolerMasterPhysicalKeyboardLayout physicalKeyboardLayout, CultureInfo culture)
            : base(RGBDeviceType.Keyboard, deviceIndex)
        {
            this.PhysicalLayout = physicalKeyboardLayout;

            SetLayouts(culture.KeyboardLayoutId);

            Image = new Uri(PathHelper.GetAbsolutePath($@"Images\CoolerMaster\Keyboards\{Model.Replace(" ", string.Empty).ToUpper()}.png"), UriKind.Absolute);
        }
Example #4
0
        /// <inheritdoc />
        public bool Initialize(bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
        {
            IsInitialized = false;

            try
            {
                _CoolerMasterSDK.Reload();
                if (_CoolerMasterSDK.GetSDKVersion() <= 0)
                {
                    return(false);
                }

                IList <IRGBDevice> devices = new List <IRGBDevice>();

                foreach (CoolerMasterDevicesIndexes index in Enum.GetValues(typeof(CoolerMasterDevicesIndexes)))
                {
                    try
                    {
                        _CoolerMasterSDK.SetControlDevice(index);
                        if (_CoolerMasterSDK.IsDevicePlugged())
                        {
                            ICoolerMasterRGBDevice device;
                            switch (index.GetDeviceType())
                            {
                            case RGBDeviceType.Keyboard:
                                CoolerMasterPhysicalKeyboardLayout physicalLayout = _CoolerMasterSDK.GetDeviceLayout();
                                device = new CoolerMasterKeyboardRGBDevice(new CoolerMasterKeyboardRGBDeviceInfo(index, physicalLayout, GetCulture()));
                                break;

                            default:
                                if (throwExceptions)
                                {
                                    throw new RGBDeviceException("Unknown Device-Type");
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            _CoolerMasterSDK.EnableLedControl(true);

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

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

            return(true);
        }