Beispiel #1
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);
        }
Beispiel #2
0
        /// <inheritdoc />
        public bool Initialize(bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
        {
            try
            {
                if (IsInitialized)
                {
                    _LogitechGSDK.LogiLedRestoreLighting();
                }
            }
            catch { /* At least we tried ... */ }

            IsInitialized = false;

            try
            {
                _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 _, string imageBasePath, string imageLayout, string layoutPath) = DeviceChecker.PerKeyDeviceData;
                        ILogitechRGBDevice device = new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.PerKeyRGB, imageBasePath, imageLayout, layoutPath));
                        device.Initialize();
                        devices.Add(device);
                    }
                }
                catch { if (throwExceptions)
                        {
                            throw;
                        }
                }

                try
                {
                    if (DeviceChecker.IsPerDeviceDeviceConnected)
                    {
                        (string model, RGBDeviceType deviceType, int _, string imageBasePath, string imageLayout, string layoutPath) = DeviceChecker.PerDeviceDeviceData;
                        ILogitechRGBDevice device = new LogitechPerDeviceRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.DeviceRGB, imageBasePath, imageLayout, layoutPath));
                        device.Initialize();
                        devices.Add(device);
                    }
                }
                catch { if (throwExceptions)
                        {
                            throw;
                        }
                }

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

            return(true);
        }