示例#1
0
        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);
            }
        }
示例#2
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.
        }
示例#3
0
        /// <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;
            }
        }
示例#4
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);
                    }
                }
            }
        }