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

            try
            {
                UpdateTrigger?.Stop();

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

                if (loadFilter.HasFlag(RGBDeviceType.LedMatrix))
                {
                    for (int index = 0; index < OutputDeviceBase.DeviceCount; index++)
                    {
                        try
                        {
                            MidiOutCaps outCaps = OutputDeviceBase.GetDeviceCapabilities(index);
                            if (outCaps.name == null)
                            {
                                continue;
                            }

                            NovationDevices?deviceId = (NovationDevices?)Enum.GetValues(typeof(NovationDevices))
                                                       .Cast <Enum>()
                                                       .FirstOrDefault(x => string.Equals(x.GetDeviceId(), outCaps.name, StringComparison.OrdinalIgnoreCase));

                            if (deviceId == null)
                            {
                                continue;
                            }

                            INovationRGBDevice device = new NovationLaunchpadRGBDevice(new NovationLaunchpadRGBDeviceInfo(outCaps.name, index, deviceId.GetColorCapability()));
                            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 />
        /// <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);
        }
Пример #3
0
        /// <inheritdoc />
        public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
        {
            try
            {
                if (IsInitialized)
                {
                    _LogitechGSDK.LogiLedRestoreLighting();
                }
            }
            catch { /* At least we tried ... */ }

            IsInitialized = false;

            try
            {
                UpdateTrigger?.Stop();

                _LogitechGSDK.Reload();
                if (!_LogitechGSDK.LogiLedInit())
                {
                    return(false);
                }

                _LogitechGSDK.LogiLedSaveCurrentLighting();

                IList <IRGBDevice> devices = new List <IRGBDevice>();
                DeviceChecker.LoadDeviceList();

                try
                {
                    if (DeviceChecker.IsPerKeyDeviceConnected)
                    {
                        (string model, RGBDeviceType deviceType, int _, int _, string imageLayout, string layoutPath) = DeviceChecker.PerKeyDeviceData;
                        if (loadFilter.HasFlag(deviceType)) //TODO DarthAffe 07.12.2017: Check if it's worth to try another device if the one returned doesn't match the filter
                        {
                            ILogitechRGBDevice device = new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.PerKeyRGB, 0, imageLayout, layoutPath));
                            device.Initialize(_perKeyUpdateQueue);
                            devices.Add(device);
                        }
                    }
                }
                catch { if (throwExceptions)
                        {
                            throw;
                        }
                }

                try
                {
                    if (DeviceChecker.IsPerDeviceDeviceConnected)
                    {
                        (string model, RGBDeviceType deviceType, int _, int _, string imageLayout, string layoutPath) = DeviceChecker.PerDeviceDeviceData;
                        if (loadFilter.HasFlag(deviceType)) //TODO DarthAffe 07.12.2017: Check if it's worth to try another device if the one returned doesn't match the filter
                        {
                            ILogitechRGBDevice device = new LogitechPerDeviceRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.DeviceRGB, 0, imageLayout, layoutPath));
                            device.Initialize(_perDeviceUpdateQueue);
                            devices.Add(device);
                        }
                    }
                }
                catch { if (throwExceptions)
                        {
                            throw;
                        }
                }

                try
                {
                    if (DeviceChecker.IsZoneDeviceConnected)
                    {
                        foreach ((string model, RGBDeviceType deviceType, int _, int zones, string imageLayout, string layoutPath) in DeviceChecker.ZoneDeviceData)
                        {
                            try
                            {
                                if (loadFilter.HasFlag(deviceType))
                                {
                                    LogitechZoneUpdateQueue updateQueue = new LogitechZoneUpdateQueue(UpdateTrigger, deviceType);
                                    ILogitechRGBDevice      device      = new LogitechZoneRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.DeviceRGB, zones, imageLayout, layoutPath));
                                    device.Initialize(updateQueue);
                                    devices.Add(device);
                                    _zoneUpdateQueues.Add(deviceType, updateQueue);
                                }
                            }
                            catch { if (throwExceptions)
                                    {
                                        throw;
                                    }
                            }
                        }
                    }
                }
                catch { if (throwExceptions)
                        {
                            throw;
                        }
                }

                UpdateTrigger?.Start();

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

            return(true);
        }
Пример #4
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);
        }
Пример #5
0
        /// <inheritdoc />
        public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
        {
            IsInitialized = false;

            try
            {
                UpdateTrigger?.Stop();

                _AsusSDK.Reload();

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

                #region Mainboard

                if (loadFilter.HasFlag(RGBDeviceType.Mainboard))
                {
                    try
                    {
                        //TODO DarthAffe 26.11.2017: This is not a fix! There might really be a second controller on the mainboard, but for now this should prevent the random crash for some guys.
                        // DarthAffe 26.11.2017: https://rog.asus.com/forum/showthread.php?97754-Access-Violation-Wrong-EnumerateMB-Result&p=688901#post688901
                        int mainboardCount = Math.Min(1, _AsusSDK.EnumerateMbController(IntPtr.Zero, 0));
                        if (mainboardCount > 0)
                        {
                            IntPtr mainboardHandles = Marshal.AllocHGlobal(mainboardCount * IntPtr.Size);
                            _AsusSDK.EnumerateMbController(mainboardHandles, mainboardCount);

                            for (int i = 0; i < mainboardCount; i++)
                            {
                                try
                                {
                                    IntPtr handle = Marshal.ReadIntPtr(mainboardHandles, i);
                                    _AsusSDK.SetMbMode(handle, 1);
                                    AsusMainboardRGBDevice device = new AsusMainboardRGBDevice(new AsusMainboardRGBDeviceInfo(RGBDeviceType.Mainboard, handle));
                                    device.Initialize(UpdateTrigger);
                                    devices.Add(device);
                                }
                                catch { if (throwExceptions)
                                        {
                                            throw;
                                        }
                                }
                            }
                        }
                    }
                    catch { if (throwExceptions)
                            {
                                throw;
                            }
                    }
                }

                #endregion

                #region Graphics cards

                //TODO DarthAffe 21.10.2017: This somehow returns non-existant gpus (at least for me) which cause huge lags (if a real asus-ready gpu is connected this doesn't happen)

                if (loadFilter.HasFlag(RGBDeviceType.GraphicsCard))
                {
                    try
                    {
                        int graphicCardCount = _AsusSDK.EnumerateGPU(IntPtr.Zero, 0);
                        if (graphicCardCount > 0)
                        {
                            IntPtr grapicsCardHandles = Marshal.AllocHGlobal(graphicCardCount * IntPtr.Size);
                            _AsusSDK.EnumerateGPU(grapicsCardHandles, graphicCardCount);

                            for (int i = 0; i < graphicCardCount; i++)
                            {
                                try
                                {
                                    IntPtr handle = Marshal.ReadIntPtr(grapicsCardHandles, i);
                                    _AsusSDK.SetGPUMode(handle, 1);
                                    AsusGraphicsCardRGBDevice device = new AsusGraphicsCardRGBDevice(new AsusGraphicsCardRGBDeviceInfo(RGBDeviceType.GraphicsCard, handle));
                                    device.Initialize(UpdateTrigger);
                                    devices.Add(device);
                                }
                                catch { if (throwExceptions)
                                        {
                                            throw;
                                        }
                                }
                            }
                        }
                    }
                    catch { if (throwExceptions)
                            {
                                throw;
                            }
                    }
                }

                #endregion

                #region DRAM

                //TODO DarthAffe 29.10.2017: I don't know why they are even documented, but the asus guy said they aren't in the SDK right now.
                //try
                //{
                //int dramCount = _AsusSDK.EnumerateDram(IntPtr.Zero, 0);
                //if (dramCount > 0)
                //{
                //    IntPtr dramHandles = Marshal.AllocHGlobal(dramCount * IntPtr.Size);
                //    _AsusSDK.EnumerateDram(dramHandles, dramCount);

                //    for (int i = 0; i < dramCount; i++)
                //    {
                //try
                //{
                //        IntPtr handle = Marshal.ReadIntPtr(dramHandles, i);
                //        _AsusSDK.SetDramMode(handle, 1);
                //        AsusDramRGBDevice device = new AsusDramRGBDevice(new AsusDramRGBDeviceInfo(RGBDeviceType.DRAM, handle));
                //        device.Initialize(UpdateTrigger);
                //        devices.Add(device);
                //    }
                //catch { if (throwExceptions) throw; }
                //    }
                //}
                //}
                //    catch { if (throwExceptions) throw; }

                #endregion

                #region Keyboard

                if (loadFilter.HasFlag(RGBDeviceType.Keyboard))
                {
                    try
                    {
                        IntPtr keyboardHandle = Marshal.AllocHGlobal(IntPtr.Size);
                        if (_AsusSDK.CreateClaymoreKeyboard(keyboardHandle))
                        {
                            _AsusSDK.SetClaymoreKeyboardMode(keyboardHandle, 1);
                            AsusKeyboardRGBDevice device = new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(RGBDeviceType.Keyboard, keyboardHandle, GetCulture()));
                            device.Initialize(UpdateTrigger);
                            devices.Add(device);
                        }
                    }
                    catch { if (throwExceptions)
                            {
                                throw;
                            }
                    }
                }

                #endregion

                #region Mouse

                if (loadFilter.HasFlag(RGBDeviceType.Mouse))
                {
                    try
                    {
                        IntPtr mouseHandle = Marshal.AllocHGlobal(IntPtr.Size);
                        if (_AsusSDK.CreateRogMouse(mouseHandle))
                        {
                            _AsusSDK.SetRogMouseMode(mouseHandle, 1);
                            AsusMouseRGBDevice device = new AsusMouseRGBDevice(new AsusMouseRGBDeviceInfo(RGBDeviceType.Mouse, mouseHandle));
                            device.Initialize(UpdateTrigger);
                            devices.Add(device);
                        }
                    }
                    catch { if (throwExceptions)
                            {
                                throw;
                            }
                    }
                }

                #endregion

                UpdateTrigger?.Start();

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

            return(true);
        }
Пример #6
0
        /// <inheritdoc />
        public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
        {
            if (IsInitialized)
            {
                TryUnInit();
            }

            IsInitialized = false;

            try
            {
                UpdateTrigger?.Stop();

                _RazerSDK.Reload();

                RazerError error;
                if (((error = _RazerSDK.Init()) != RazerError.Success) &&
                    Enum.IsDefined(typeof(RazerError), error))    //HACK DarthAffe 08.02.2018: The x86-SDK seems to have a problem here ...
                {
                    ThrowRazerError(error);
                }

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

                if (loadFilter.HasFlag(RGBDeviceType.Keyboard))
                {
                    foreach ((Guid guid, string model) in Razer.Devices.KEYBOARDS)
                    {
                        try
                        {
                            if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1)) &&
                                (!LoadEmulatorDevices || (Razer.Devices.KEYBOARDS.FirstOrDefault().guid != guid)))
                            {
                                continue;
                            }

                            RazerKeyboardRGBDevice device = new RazerKeyboardRGBDevice(new RazerKeyboardRGBDeviceInfo(guid, model, GetCulture()));
                            device.Initialize(UpdateTrigger);
                            devices.Add(device);
                        }
                        catch { if (throwExceptions)
                                {
                                    throw;
                                }
                        }
                    }
                }

                if (loadFilter.HasFlag(RGBDeviceType.Mouse))
                {
                    foreach ((Guid guid, string model) in Razer.Devices.MICE)
                    {
                        try
                        {
                            if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1)) &&
                                (!LoadEmulatorDevices || (Razer.Devices.MICE.FirstOrDefault().guid != guid)))
                            {
                                continue;
                            }

                            RazerMouseRGBDevice device = new RazerMouseRGBDevice(new RazerMouseRGBDeviceInfo(guid, model));
                            device.Initialize(UpdateTrigger);
                            devices.Add(device);
                        }
                        catch { if (throwExceptions)
                                {
                                    throw;
                                }
                        }
                    }
                }

                if (loadFilter.HasFlag(RGBDeviceType.Headset))
                {
                    foreach ((Guid guid, string model) in Razer.Devices.HEADSETS)
                    {
                        try
                        {
                            if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1)) &&
                                (!LoadEmulatorDevices || (Razer.Devices.HEADSETS.FirstOrDefault().guid != guid)))
                            {
                                continue;
                            }

                            RazerHeadsetRGBDevice device = new RazerHeadsetRGBDevice(new RazerHeadsetRGBDeviceInfo(guid, model));
                            device.Initialize(UpdateTrigger);
                            devices.Add(device);
                        }
                        catch { if (throwExceptions)
                                {
                                    throw;
                                }
                        }
                    }
                }

                if (loadFilter.HasFlag(RGBDeviceType.Mousepad))
                {
                    foreach ((Guid guid, string model) in Razer.Devices.MOUSEMATS)
                    {
                        try
                        {
                            if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1)) &&
                                (!LoadEmulatorDevices || (Razer.Devices.MOUSEMATS.FirstOrDefault().guid != guid)))
                            {
                                continue;
                            }

                            RazerMousepadRGBDevice device = new RazerMousepadRGBDevice(new RazerMousepadRGBDeviceInfo(guid, model));
                            device.Initialize(UpdateTrigger);
                            devices.Add(device);
                        }
                        catch { if (throwExceptions)
                                {
                                    throw;
                                }
                        }
                    }
                }

                if (loadFilter.HasFlag(RGBDeviceType.Keypad))
                {
                    foreach ((Guid guid, string model) in Razer.Devices.KEYPADS)
                    {
                        try
                        {
                            if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1)) &&
                                (!LoadEmulatorDevices || (Razer.Devices.KEYPADS.FirstOrDefault().guid != guid)))
                            {
                                continue;
                            }

                            RazerKeypadRGBDevice device = new RazerKeypadRGBDevice(new RazerKeypadRGBDeviceInfo(guid, model));
                            device.Initialize(UpdateTrigger);
                            devices.Add(device);
                        }
                        catch { if (throwExceptions)
                                {
                                    throw;
                                }
                        }
                    }
                }

                if (loadFilter.HasFlag(RGBDeviceType.Keyboard))
                {
                    foreach ((Guid guid, string model) in Razer.Devices.CHROMALINKS)
                    {
                        try
                        {
                            if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1)) &&
                                (!LoadEmulatorDevices || (Razer.Devices.CHROMALINKS.FirstOrDefault().guid != guid)))
                            {
                                continue;
                            }

                            RazerChromaLinkRGBDevice device = new RazerChromaLinkRGBDevice(new RazerChromaLinkRGBDeviceInfo(guid, model));
                            device.Initialize(UpdateTrigger);
                            devices.Add(device);
                        }
                        catch { if (throwExceptions)
                                {
                                    throw;
                                }
                        }
                    }
                }

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

            return(true);
        }
Пример #7
0
        /// <inheritdoc />
        public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
        {
            IsInitialized = false;

            try
            {
                UpdateTrigger?.Stop();

                // ReSharper disable once SuspiciousTypeConversion.Global
                _sdk = (IAuraSdk2) new AuraSdk();
                _sdk.SwitchMode();

                IList <IRGBDevice> devices = new List <IRGBDevice>();
                foreach (IAuraSyncDevice device in _sdk.Enumerate(0))
                {
                    try
                    {
                        IAsusRGBDevice rgbDevice;
                        switch ((AsusDeviceType)device.Type)
                        {
                        case AsusDeviceType.MB_RGB:
                            rgbDevice = new AsusMainboardRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Mainboard, device, WMIHelper.GetMainboardInfo()?.model ?? device.Name));
                            break;

                        case AsusDeviceType.MB_ADDRESABLE:
                            rgbDevice = new AsusUnspecifiedRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.LedStripe, device), LedId.LedStripe1);
                            break;

                        case AsusDeviceType.VGA_RGB:
                            rgbDevice = new AsusGraphicsCardRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.GraphicsCard, device));
                            break;

                        case AsusDeviceType.HEADSET_RGB:
                            rgbDevice = new AsusHeadsetRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Headset, device));
                            break;

                        case AsusDeviceType.DRAM_RGB:
                            rgbDevice = new AsusDramRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.DRAM, device));
                            break;

                        case AsusDeviceType.KEYBOARD_RGB:
                        case AsusDeviceType.NB_KB_RGB:
                        case AsusDeviceType.NB_KB_4ZONE_RGB:
                            rgbDevice = new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device, CultureInfo.CurrentCulture));
                            break;

                        case AsusDeviceType.MOUSE_RGB:
                            rgbDevice = new AsusMouseRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Mouse, device));
                            break;

                        default:
                            rgbDevice = new AsusUnspecifiedRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Unknown, device), LedId.Custom1);
                            break;
                        }

                        if (loadFilter.HasFlag(rgbDevice.DeviceInfo.DeviceType))
                        {
                            rgbDevice.Initialize(UpdateTrigger);
                            devices.Add(rgbDevice);
                        }
                    }
                    catch
                    {
                        if (throwExceptions)
                        {
                            throw;
                        }
                    }
                }

                UpdateTrigger?.Start();

                Devices       = new ReadOnlyCollection <IRGBDevice>(devices);
                IsInitialized = true;
            }
            catch
            {
                if (throwExceptions)
                {
                    throw;
                }
                return(false);
            }
            return(true);
        }
Пример #8
0
        /// <inheritdoc />
        public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
        {
            IsInitialized = false;

            try
            {
                UpdateTrigger?.Stop();

                // ReSharper disable once SuspiciousTypeConversion.Global
                _sdk = (IAuraSdk2) new AuraSdk();
                _sdk.SwitchMode();

                IList <IRGBDevice> devices = new List <IRGBDevice>();
                foreach (IAuraSyncDevice device in _sdk.Enumerate(0))
                {
                    try
                    {
                        IAsusRGBDevice rgbDevice = null;
                        switch (device.Type)
                        {
                        case 0x00010000:     //Motherboard
                            rgbDevice = new AsusMainboardRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Mainboard, device, WMIHelper.GetMainboardInfo()?.model ?? device.Name));
                            break;

                        case 0x00011000:     //Motherboard LED Strip
                            rgbDevice = new AsusUnspecifiedRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.LedStripe, device), LedId.LedStripe1);
                            break;

                        case 0x00020000:     //VGA
                            rgbDevice = new AsusGraphicsCardRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.GraphicsCard, device));
                            break;

                        case 0x00040000:     //Headset
                            rgbDevice = new AsusHeadsetRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Headset, device));
                            break;

                        case 0x00070000:     //DRAM
                            rgbDevice = new AsusDramRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.DRAM, device));
                            break;

                        case 0x00080000:     //Keyboard
                        case 0x00081000:     //Notebook Keyboard
                        case 0x00081001:     //Notebook Keyboard(4 - zone type)
                            rgbDevice = new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device, CultureInfo.CurrentCulture));
                            break;

                        case 0x00090000:     //Mouse
                            rgbDevice = new AsusMouseRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Mouse, device));
                            break;

                        case 0x00000000:     //All
                        case 0x00012000:     //All - In - One PC
                        case 0x00030000:     //Display
                        case 0x00050000:     //Microphone
                        case 0x00060000:     //External HDD
                        case 0x00061000:     //External BD Drive
                        case 0x000B0000:     //Chassis
                        case 0x000C0000:     //Projector
                            rgbDevice = new AsusUnspecifiedRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Unknown, device), LedId.Custom1);
                            break;
                        }

                        if ((rgbDevice != null) && loadFilter.HasFlag(rgbDevice.DeviceInfo.DeviceType))
                        {
                            rgbDevice.Initialize(UpdateTrigger);
                            devices.Add(rgbDevice);
                        }
                    }
                    catch
                    {
                        if (throwExceptions)
                        {
                            throw;
                        }
                    }
                }

                UpdateTrigger?.Start();

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