示例#1
0
        private bool DeviceSpeedTimerCallback()
        {
            var isCriticalTemperature = _configManager.CurrentConfig.CriticalTemperature.Any(pair =>
                                                                                             _cache.GetTemperature(pair.Key) >= pair.Value);

            foreach (var profile in _configManager.CurrentConfig.Profiles)
            {
                lock (_deviceManager)
                {
                    foreach (var port in profile.Ports)
                    {
                        var controller = _deviceManager.GetController(port);
                        var data       = controller?.GetPortData(port.Id);
                        _cache.StorePortData(port, data);
                    }
                }

                IDictionary <PortIdentifier, byte> speedMap;
                if (isCriticalTemperature)
                {
                    speedMap = profile.Ports.ToDictionary(p => p, p => (byte)100);
                }
                else
                {
                    var speedControllers = _speedControllerManager.GetSpeedControllers(profile.Guid);
                    var speedController  = speedControllers?.FirstOrDefault(c => c.Enabled);
                    if (speedController == null)
                    {
                        continue;
                    }

                    speedMap = speedController.GenerateSpeeds(profile.Ports, _cache.AsReadOnly());
                }

                if (speedMap == null)
                {
                    continue;
                }

                lock (_deviceManager)
                {
                    foreach (var(port, speed) in speedMap)
                    {
                        var controller = _deviceManager.GetController(port);
                        if (controller == null)
                        {
                            continue;
                        }

                        controller.SetSpeed(port.Id, speed);
                    }
                }
            }

            return(true);
        }
示例#2
0
        private bool DeviceSpeedTimerCallback()
        {
            var criticalState = _sensorManager.EnabledSensors.Any(s => {
                var value = _cache.GetSensorValue(s);
                if (float.IsNaN(value))
                {
                    return(false);
                }

                var config = _cache.GetSensorConfig(s);
                if (config == null || config.CriticalValue == null)
                {
                    return(false);
                }

                return(value > config.CriticalValue);
            });

            foreach (var profile in _config.Profiles)
            {
                lock (_deviceManager)
                {
                    foreach (var port in profile.Ports)
                    {
                        var controller = _deviceManager.GetController(port);
                        var data       = controller?.GetPortData(port.Id);
                        _cache.StorePortData(port, data);
                    }
                }

                IDictionary <PortIdentifier, byte> speedMap;
                if (criticalState)
                {
                    speedMap = profile.Ports.ToDictionary(p => p, _ => (byte)100);
                }
                else
                {
                    var speedController = _pluginStore
                                          .Get <ISpeedControllerBase>(profile)
                                          .FirstOrDefault(c => c.IsEnabled(_cache.AsReadOnly()));
                    if (speedController == null)
                    {
                        continue;
                    }

                    try
                    {
                        speedMap = speedController.GenerateSpeeds(profile.Ports, _cache.AsReadOnly());
                    }
                    catch (Exception e)
                    {
                        Logger.Fatal("{0} failed with {1}", speedController.GetType().Name, e);
                        speedMap = profile.Ports.ToDictionary(p => p, _ => (byte)100);
                    }
                }

                if (speedMap == null)
                {
                    continue;
                }

                lock (_deviceManager)
                {
                    foreach (var(port, speed) in speedMap)
                    {
                        if (speed == _cache.GetPortSpeed(port))
                        {
                            continue;
                        }

                        var controller = _deviceManager.GetController(port);
                        if (controller == null)
                        {
                            continue;
                        }

                        _cache.StorePortSpeed(port, speed);
                        controller.SetSpeed(port.Id, speed);
                    }
                }
            }

            return(true);
        }