Пример #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);
        }
Пример #2
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);
        }