internal void GetListOfMqttDevices()
        {
            Device[]     devices = IcueSdk.ListDevices();
            CorsairError error   = IcueSdk.CorsairGetLastError();

            if (error != CorsairError.Success)
            {
                Logger.LogError("SDK error getting list of devices", new Exception(error.ToString()));
            }
            Dictionary <string, int> modelCount = new Dictionary <string, int>();

            for (int i = 0; i < devices.Length; i++)
            {
                //handle multiple devices of same model
                int modelSuffix = 0;
                if (modelCount.ContainsKey(devices[i].CorsairDevice.Model))
                {
                    modelSuffix = modelCount[devices[i].CorsairDevice.Model] + 1;
                    modelCount[devices[i].CorsairDevice.Model] = modelSuffix;
                }
                else
                {
                    modelCount.Add(devices[i].CorsairDevice.Model, modelSuffix);
                }
                MqttIcueDeviceList.AddIcueDevice(devices[i], modelSuffix);
            }
        }
Exemple #2
0
        private static void Throw(CorsairError error)
        {
            ProtocolDetails    = null;
            HasExclusiveAccess = false;
            KeyboardSDK        = null;
            MouseSDK           = null;
            HeadsetSDK         = null;
            MousematSDK        = null;
            IsInitialized      = false;

            throw new CUEException(error);
        }
Exemple #3
0
        /// <summary>
        /// Handles the error.
        /// </summary>
        /// <exception cref="Exception"></exception>
        private bool HandleError()
        {
            CorsairError error = CorsairLightingSDK.GetLastError();

            if (error == CorsairError.ServerNotFound)
            {
                return(false);
            }
            else if (error != CorsairError.Success)
            {
                throw new Exception(error + "");
            }
            return(true);
        }
Exemple #4
0
        public void Configure(DriverDetails driverDetails)
        {
            _CUESDK.Reload();

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

            CorsairError error = LastError;

            if (error != CorsairError.Success)
            {
                throw new Exception(error.ToString());
            }

            if (ProtocolDetails.BreakingChanges)
            {
                throw new Exception("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 (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl))
            //{
            //    throw new Exception(LastError.ToString());
            //    HasExclusiveAccess = true;
            //}
            //else
            //{
            HasExclusiveAccess = false;
            //}

            if (!_CUESDK.CorsairSetLayerPriority(127))
            {
                throw new Exception(LastError.ToString());
            }

            // DarthAffe 07.07.2018: 127 is CUE, we want to directly compete with it as in older versions.
        }
        public static string GetMessage(this CorsairError corsairError)
        {
            switch (corsairError)
            {
            case CorsairError.CE_Success: return("Success - Previously called function was completed successfully");

            case CorsairError.CE_ServerNotFound: return("ServerNotFound - CUE is not running or was shut down or third-party control is disabled in CUE settings");

            case CorsairError.CE_NoControl: return("NoControl - some other client has or took over exclusive control");

            case CorsairError.CE_ProtocolHandshakeMissing: return("ProtocolHandshakeMissing - developer did not perform protocol handshake");

            case CorsairError.CE_IncompatibleProtocol: return("IncompatibleProtocol - developer is calling the function that is not supported by the server (either protocol has been broken by server or client or the function is new and server is too old. Check CorsairProtocolDetails for details)");

            case CorsairError.CE_InvalidArguments: return("InvalidArguments - the profiles directory does not exist or is not configured correctly");

            case CorsairError.CE_ProfilesConfigurationProblem: return("ProfilesConfigurationProblem - problem related to profiles and priorities file");

            case CorsairError.CE_StateNotSet: return("StateNotSet - developer is calling clear but state is not set");

            case CorsairError.Unknown:
            default: return("Unknown - this error code is unknown");
            }
        }
        /// <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);
        }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CUEException"/> class.
 /// </summary>
 /// <param name="error">The <see cref="CorsairError" /> provided by CUE, which leads to this exception.</param>
 public CUEException(CorsairError error)
 {
     this.Error = error;
 }
Exemple #8
0
        private static void Throw(CorsairError error)
        {
            ProtocolDetails = null;
            HasExclusiveAccess = false;
            KeyboardSDK = null;
            MouseSDK = null;
            HeadsetSDK = null;

            throw new CUEException(error);
        }
Exemple #9
0
        /// <summary>
        /// Reinitialize the CUE-SDK and temporarily hand back full control to CUE.
        /// </summary>
        /// <param name="exclusiveAccess">Specifies whether the application should request exclusive access or not.</param>
        public static void Reinitialize(bool exclusiveAccess)
        {
            if (!IsInitialized)
            {
                throw new WrapperException("CueSDK isn't initialized.");
            }

            if (_onKeyPressedDelegate != null)
            {
                throw new WrapperException("Keypress-Callback is enabled.");
            }

            KeyboardSDK?.ResetLeds();
            MouseSDK?.ResetLeds();
            HeadsetSDK?.ResetLeds();
            MousematSDK?.ResetLeds();
            HeadsetStandSDK?.ResetLeds();

            _CUESDK.Reload();

            _CUESDK.CorsairPerformProtocolHandshake();

            CorsairError error = LastError;

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

            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, false);
                }
            }
            HasExclusiveAccess = exclusiveAccess;

            int deviceCount = _CUESDK.CorsairGetDeviceCount();
            Dictionary <CorsairDeviceType, GenericDeviceInfo> reloadedDevices = new Dictionary <CorsairDeviceType, GenericDeviceInfo>();

            for (int i = 0; i < deviceCount; i++)
            {
                GenericDeviceInfo info = new GenericDeviceInfo((_CorsairDeviceInfo)Marshal.PtrToStructure(_CUESDK.CorsairGetDeviceInfo(i), typeof(_CorsairDeviceInfo)));
                if (!info.CapsMask.HasFlag(CorsairDeviceCaps.Lighting))
                {
                    continue; // Everything that doesn't support lighting control is useless
                }
                reloadedDevices.Add(info.Type, info);

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

            if (KeyboardSDK != null)
            {
                if (!reloadedDevices.ContainsKey(CorsairDeviceType.Keyboard) ||
                    KeyboardSDK.KeyboardDeviceInfo.Model != reloadedDevices[CorsairDeviceType.Keyboard].Model)
                {
                    throw new WrapperException("The previously loaded Keyboard got disconnected.");
                }
            }
            if (MouseSDK != null)
            {
                if (!reloadedDevices.ContainsKey(CorsairDeviceType.Mouse) ||
                    MouseSDK.MouseDeviceInfo.Model != reloadedDevices[CorsairDeviceType.Mouse].Model)
                {
                    throw new WrapperException("The previously loaded Mouse got disconnected.");
                }
            }
            if (HeadsetSDK != null)
            {
                if (!reloadedDevices.ContainsKey(CorsairDeviceType.Headset) ||
                    HeadsetSDK.HeadsetDeviceInfo.Model != reloadedDevices[CorsairDeviceType.Headset].Model)
                {
                    throw new WrapperException("The previously loaded Headset got disconnected.");
                }
            }
            if (MousematSDK != null)
            {
                if (!reloadedDevices.ContainsKey(CorsairDeviceType.Mousemat) ||
                    MousematSDK.MousematDeviceInfo.Model != reloadedDevices[CorsairDeviceType.Mousemat].Model)
                {
                    throw new WrapperException("The previously loaded Mousemat got disconnected.");
                }
            }
            if (HeadsetStandSDK != null)
            {
                if (!reloadedDevices.ContainsKey(CorsairDeviceType.HeadsetStand) ||
                    HeadsetStandSDK.HeadsetStandDeviceInfo.Model != reloadedDevices[CorsairDeviceType.HeadsetStand].Model)
                {
                    throw new WrapperException("The previously loaded Headset Stand got disconnected.");
                }
            }

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

            IsInitialized = true;
        }
Exemple #10
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;
        }
Exemple #11
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="CUEException" /> class.
 /// </summary>
 /// <param name="error">The <see cref="CorsairError" /> provided by CUE, which leads to this exception.</param>
 public CUEException(CorsairError error) => Error = error;
Exemple #12
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);
        }
        /// <summary>
        /// Handles the MqttMsgPublishReceived event of the client control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="MqttMsgPublishEventArgs"/> instance containing the event data.</param>
        private void client_MqttMsgPublishReceived(MqttApplicationMessageReceivedEventArgs e)
        {
            string jsonMessage = Encoding.UTF8.GetString(e.ApplicationMessage.Payload, 0, e.ApplicationMessage.Payload.Length);

            Console.WriteLine(e.ApplicationMessage.Topic);
            if (e.ApplicationMessage.Topic == MqttIcueDeviceList.TOPIC_ALL_DEVICE_STATE)
            {
                SendStateUpdate(MqttIcueDeviceList.TOPIC_ALL_DEVICE_STATE, MqttIcueDeviceList.GetAllDeviceAverageState());
                return;
            }

            if (e.ApplicationMessage.Topic == TOPIC_CONTROL_SWITCH_STATE)
            {
                SendControlSwitchUpdate();
                return;
            }

            MqttIcueDevice mqttIcueDevice = MqttIcueDeviceList.GetDeviceByStateTopic(e.ApplicationMessage.Topic);

            if (mqttIcueDevice != null)
            {
                SendStateUpdate(mqttIcueDevice);
                return;
            }
            bool isSetAllDevices = e.ApplicationMessage.Topic == MqttIcueDeviceList.TOPIC_ALL_DEVICE_SET;

            mqttIcueDevice = MqttIcueDeviceList.GetDeviceBySetTopic(e.ApplicationMessage.Topic);
            if (mqttIcueDevice != null || isSetAllDevices)
            {
                MqttIcueDeviceState state = JsonConvert.DeserializeObject <MqttIcueDeviceState>(jsonMessage);
                if (state.Color == null)
                {
                    if (state.State.Equals("ON"))
                    {
                        SetState(mqttIcueDevice, isSetAllDevices);
                        CorsairError error = IcueSdk.CorsairGetLastError();
                        if (error != CorsairError.Success)
                        {
                            Logger.LogError("SDK error setting device to ON", new Exception(error.ToString()));
                        }
                    }
                    else
                    {
                        mqttIcueDevice.SetOffState();
                        SetState(mqttIcueDevice, isSetAllDevices, 0, 0, 0);
                        CorsairError error = IcueSdk.CorsairGetLastError();
                        if (error != CorsairError.Success)
                        {
                            Logger.LogError("SDK error setting device to OFF", new Exception(error.ToString()));
                        }
                    }
                    return;
                }
                else
                {
                    SetState(mqttIcueDevice, isSetAllDevices, state.Color.R, state.Color.G, state.Color.B);
                    CorsairError error = IcueSdk.CorsairGetLastError();
                    if (error != CorsairError.Success)
                    {
                        Logger.LogError("SDK error setting device color", new Exception(error.ToString()));
                    }
                }
                return;
            }

            if (e.ApplicationMessage.Topic == TOPIC_CONTROL_SWITCH_SET)
            {
                if (jsonMessage.Equals("ON"))
                {
                    HasControl = true;
                    IcueSdk.SetLayerPriority(130);
                }
                else
                {
                    HasControl = false;
                    IcueSdk.SetLayerPriority(126);
                }
                SendControlSwitchUpdate();
                return;
            }
        }
Exemple #14
0
        private void Scan()
        {
            Debug.WriteLine("Scanning");
            if (!isCueSetUp)
            {
                // if ((DateTime.Now - lastTimeCueWasChecked).TotalSeconds > 10)
                {
                    lastTimeCueWasChecked = DateTime.Now;

                    if (IsICUERunning())
                    {
                        _CUESDK.HomePath = homePath;

                        _CUESDK.Reload();
                        okayToUseCue    = true;
                        ProtocolDetails = new CorsairProtocolDetails(_CUESDK.CorsairPerformProtocolHandshake());

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

                        if (ProtocolDetails.BreakingChanges)
                        {
                            throw new Exception("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 (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl))
                        //{
                        //    throw new Exception(LastError.ToString());
                        //    HasExclusiveAccess = true;
                        //}
                        //else
                        //{
                        HasExclusiveAccess = false;
                        //}

                        if (!_CUESDK.CorsairSetLayerPriority(127))
                        {
                            throw new Exception(LastError.ToString());
                        }

                        isCueSetUp = true;
                    }
                }
            }

            if (isCueSetUp)
            {
                // if ((DateTime.Now - lastTimeDevicesWasChecked).TotalSeconds > 10)
                {
                    var result = GetDevices();
                    foreach (ControlDevice controlDevicex in result)
                    {
                        if (foundDevices.Count == 0 || !foundDevices.Any(x => x.Name == controlDevicex.Name && x.TitleOverride == controlDevicex.TitleOverride))
                        {
                            controlDevicex.ProductImage = GetImage(((CorsairDevice)controlDevicex).ImageKey);
                            foundDevices.Add(controlDevicex);
                            DeviceAdded?.Invoke(this, new Events.DeviceChangeEventArgs(controlDevicex));
                        }
                    }

                    List <ControlDevice> removeList = new List <ControlDevice>();
                    foreach (ControlDevice controlDevicex in foundDevices)
                    {
                        if (result.Count == 0 || !result.Any(x => x.Name == controlDevicex.Name && x.TitleOverride == controlDevicex.TitleOverride))
                        {
                            removeList.Add(controlDevicex);
                            DeviceRemoved?.Invoke(this, new Events.DeviceChangeEventArgs(controlDevicex));
                        }
                    }

                    foreach (ControlDevice controlDevicex in removeList)
                    {
                        foundDevices.Remove(controlDevicex);
                    }
                }
            }
        }
Exemple #15
0
 /// <inheritdoc />
 /// <summary>
 /// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CUEException" /> class.
 /// </summary>
 /// <param name="error">The <see cref="T:RGB.NET.Devices.Corsair.CorsairError" /> provided by CUE, which leads to this exception.</param>
 public CUEException(CorsairError error)
 {
     this.Error = error;
 }
 public SdkError(CorsairError corsairError)
     : this(corsairError, $"Sdk Error occurred: {corsairError.GetMessage()}")
 {
 }
 public SdkError(CorsairError corsairError, string message)
     : base(message)
 {
     CorsairError = corsairError;
 }