Esempio n. 1
0
 public override void Shutdown()
 {
     CUESDK.SetLayerPriority(0);
     deviceInfos.Clear();
     CUESDK.ReleaseControl();
     IsInitialized = false;
 }
Esempio n. 2
0
        public override bool Initialize()
        {
            CUESDK.PerformProtocolHandshake();
            var error = CUESDK.GetLastError();

            if (error != CorsairError.Success)
            {
                LogError("Error: " + error);
                return(IsInitialized = false);
            }

            for (int i = 0; i < CUESDK.GetDeviceCount(); i++)
            {
                deviceInfos.Add(CUESDK.GetDeviceInfo(i));
            }

            if (Global.Configuration.VarRegistry.GetVariable <bool>($"{DeviceName}_exclusive") && !CUESDK.RequestControl())
            {
                LogError("Error requesting cuesdk exclusive control:" + CUESDK.GetLastError());
            }
            CUESDK.SetLayerPriority(255);

            return(IsInitialized = true);
        }
Esempio n. 3
0
        public override bool UpdateDevice(Dictionary <DeviceKeys, Color> keyColors, DoWorkEventArgs e, bool forced = false)
        {
            if (deviceInfos.Count != CUESDK.GetDeviceCount())
            {
                this.Reset();
            }

            for (int i = 0; i < deviceInfos.Count; i++)
            {
                var deviceInfo = deviceInfos[i];
                if (deviceInfo.Type == CorsairDeviceType.Keyboard && Global.Configuration.DevicesDisableKeyboard)
                {
                    continue;
                }

                if ((deviceInfo.Type == CorsairDeviceType.Mouse || deviceInfo.Type == CorsairDeviceType.MouseMat) &&
                    Global.Configuration.DevicesDisableMouse)
                {
                    continue;
                }

                if ((deviceInfo.Type == CorsairDeviceType.Headset || deviceInfo.Type == CorsairDeviceType.HeadsetStand) &&
                    Global.Configuration.DevicesDisableHeadset)
                {
                    continue;
                }

                List <CorsairLedColor> colors = new List <CorsairLedColor>();

                if (LedMaps.MapsMap.TryGetValue(deviceInfo.Type, out var dict) && dict.Count != 0)
                {
                    foreach (var led in keyColors)
                    {
                        if (dict.TryGetValue(led.Key, out var ledid))
                        {
                            colors.Add(new CorsairLedColor()
                            {
                                LedId = ledid,
                                R     = led.Value.R,
                                G     = led.Value.G,
                                B     = led.Value.B
                            });
                        }
                    }
                }
                else
                {
                    if (keyColors.TryGetValue(DeviceKeys.Peripheral_Logo, out var clr))
                    {
                        if (deviceInfo.Type == CorsairDeviceType.LightingNodePro || deviceInfo.Type == CorsairDeviceType.CommanderPro)
                        {
                            int totalLeds = 0;
                            for (int j = 0; j < deviceInfo.Channels.ChannelsCount; j++)
                            {
                                totalLeds += deviceInfo.Channels.Channels[j].TotalLedsCount;
                                foreach (var ledid in LedMaps.ChannelLeds[j])
                                {
                                    if (colors.Count == totalLeds)
                                    {
                                        continue;
                                    }

                                    colors.Add(new CorsairLedColor()
                                    {
                                        LedId = ledid,
                                        R     = clr.R,
                                        G     = clr.G,
                                        B     = clr.B
                                    });
                                }
                            }
                        }
                        else
                        {
                            CorsairLedId initial = GetInitialLedIdForDeviceType(deviceInfo.Type);

                            if (initial == CorsairLedId.I_Invalid)
                            {
                                continue;
                            }

                            for (int j = 0; j < deviceInfo.LedsCount; j++)
                            {
                                colors.Add(new CorsairLedColor()
                                {
                                    LedId = initial++,
                                    R     = clr.R,
                                    G     = clr.G,
                                    B     = clr.B
                                });
                            }
                        }
                    }
                }

                if (colors.Count == 0)
                {
                    continue;
                }

                CUESDK.SetDeviceColors(i, colors.ToArray());
            }

            return(CUESDK.Update());
        }