//Initializes CUESDK with optional Exclusive Access
        private bool InitializeCueSdk(bool ExclusiveAccess)
        {
            CueSDK.Initialize(ExclusiveAccess);
            if (!CheckForCUEError())
            {
                return(false);
            }
            CorsairProtocolDetails protocol = CueSDK.ProtocolDetails;

            Console.WriteLine("CUE SDK: SDK Version {0}, Server Version {1}", protocol.SdkVersion, protocol.ServerVersion);
            return(true);
        }
Exemplo n.º 2
0
        public ICueBridge()
        {
            CUESDK.LoadCUESDK();
            CorsairProtocolDetails details = CUESDK.CorsairPerformProtocolHandshake();

            CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl);
            int devCount = CUESDK.CorsairGetDeviceCount();

            Debug.WriteLine("CorsairGetDeviceCount: {1}", "", devCount);

            for (int deviceIndex = 0; deviceIndex < devCount; deviceIndex++)
            {
                IntPtr              deviceInfoPointer  = CUESDK.CorsairGetDeviceInfo(deviceIndex);
                CorsairDeviceInfo   DeviceInfo         = (CorsairDeviceInfo)Marshal.PtrToStructure(deviceInfoPointer, typeof(CorsairDeviceInfo));
                IntPtr              ledPositionPointer = CUESDK.CorsairGetLedPositionsByDeviceIndex(deviceIndex);
                CorsairLedPositions LedPositions       = (CorsairLedPositions)Marshal.PtrToStructure(ledPositionPointer, typeof(CorsairLedPositions));
                switch (DeviceInfo.type)
                {
                case CorsairDeviceType.Keyboard:
                    Debug.WriteLine("Keyboard LedPosition: {1}", "", LedPositions.numberOfLed);
                    Keyboard = new Keyboard();
                    Keyboard.LedPositions       = LedPositions;
                    Keyboard.DeviceInfo         = DeviceInfo;
                    Keyboard.CorsairDeviceIndex = deviceIndex;
                    break;

                case CorsairDeviceType.LightningNodePro:
                    Debug.WriteLine("LightningNodePro LedPosition: {1}", "", LedPositions.numberOfLed);
                    LedStrip = new LedStrip();
                    LedStrip.LedPositions       = LedPositions;
                    LedStrip.DeviceInfo         = DeviceInfo;
                    LedStrip.CorsairDeviceIndex = deviceIndex;
                    break;
                }
                Debug.WriteLine("DeviceInfo: {1}", "", DeviceInfo.type);
            }
        }
Exemplo n.º 3
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;
        }