예제 #1
0
        public FanControl(FanControlConfigV2 config, ITemperatureFilter tempFilter, string pluginsPath)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            if (tempFilter == null)
            {
                throw new ArgumentNullException("filter");
            }

            if (pluginsPath == null)
            {
                throw new ArgumentNullException("pluginsPath");
            }

            if (!Directory.Exists(pluginsPath))
            {
                throw new DirectoryNotFoundException(pluginsPath + " could not be found.");
            }

            var ecLoader = new FanControlPluginLoader<IEmbeddedController>(pluginsPath);
            this.ec = ecLoader.FanControlPlugin;
            this.EmbeddedControllerPluginId = ecLoader.FanControlPluginId;

            var tempMonloader = new FanControlPluginLoader<ITemperatureMonitor>(pluginsPath);
            this.tempMon = tempMonloader.FanControlPlugin;
            this.TemperatureMonitorPluginId = tempMonloader.FanControlPluginId;

            this.autoEvent = new AutoResetEvent(false);
            this.tempFilter = tempFilter;
            this.config = (FanControlConfigV2)config.Clone();
            this.pollInterval = config.EcPollInterval;
            this.waitHandleTimeout = Math.Min(MaxWaitHandleTimeout, config.EcPollInterval);
            this.requestedSpeeds = new float[config.FanConfigurations.Count];
            this.fanInfo = new FanInformation[config.FanConfigurations.Count];
            this.fanInfoInternal = new FanInformation[config.FanConfigurations.Count];
            this.fanSpeedManagers = new FanSpeedManager[config.FanConfigurations.Count];
            this.asyncOp = AsyncOperationManager.CreateOperation(null);

            for (int i = 0; i < config.FanConfigurations.Count; i++)
            {
                var cfg = config.FanConfigurations[i];

                this.fanSpeedManagers[i] = new FanSpeedManager(cfg, config.CriticalTemperature);
                this.requestedSpeeds[i] = AutoFanSpeedPercentage;
                this.fanInfo[i] = new FanInformation(0, 0, true, false, cfg.FanDisplayName);
            }
        }
예제 #2
0
 public FanControl(FanControlConfigV2 config, string pluginsPath)
     : this(config, 
     new ArithmeticMeanTemperatureFilter(Math.Max(config.EcPollInterval, MinPollInterval)), 
     pluginsPath)
 {
 }
예제 #3
0
        private bool TryLoadConfig(out FanControlConfigV2 config)
        {
            bool result = false;
            var configManager = new FanControlConfigManager(FanControlService.ConfigsDirectory);
            string id = ServiceSettings.Default.SelectedConfigId;

            if (!string.IsNullOrWhiteSpace(id) && configManager.SelectConfig(id))
            {
                this.selectedConfig = configManager.SelectedConfigName;
                config = configManager.SelectedConfig;
                result = true;
            }
            else
            {
                config = null;
            }

            return result;
        }
예제 #4
0
 public FanControl(FanControlConfigV2 config)
     : this(config, Path.Combine(AssemblyDirectory, PluginsFolderDefaultName))
 {
 }
예제 #5
0
        private void InitializeFanSpeedSteps(FanControlConfigV2 cfg)
        {
            this.fanSpeedSteps = new int[cfg.FanConfigurations.Count];

            for (int i = 0; i < this.fanSpeedSteps.Length; i++)
            {
                var fanConfig = cfg.FanConfigurations[i];

                // Add 1 extra step for "auto control"
                this.fanSpeedSteps[i] = 1 + (Math.Max(fanConfig.MinSpeedValue, fanConfig.MaxSpeedValue)
                    - Math.Min(fanConfig.MinSpeedValue, fanConfig.MaxSpeedValue));
            }
        }
예제 #6
0
        private static bool TryInitializeFanControl(FanControlConfigV2 cfg, out FanControl fanControl)
        {
            bool success = false;
            fanControl = null;

            try
            {
                float[] speeds = ServiceSettings.Default.TargetFanSpeeds;
                fanControl = new FanControl(cfg);

                if (speeds == null || speeds.Length != cfg.FanConfigurations.Count)
                {
                    speeds = new float[cfg.FanConfigurations.Count];

                    for (int i = 0; i < speeds.Length; i++)
                    {
                        speeds[i] = FanControl.AutoFanSpeedPercentage;
                    }
                }

                if (speeds != null && speeds.Length == fanControl.FanInformation.Count)
                {
                    for (int i = 0; i < speeds.Length; i++)
                    {
                        fanControl.SetTargetFanSpeed(speeds[i], i);
                    }
                }
                success = true;
            }
            finally
            {
                if (!success && fanControl != null)
                {
                    fanControl.Dispose();
                    fanControl = null;
                }
            }

            return success;
        }
예제 #7
0
        private static FanControlConfigV2 ConvertViewModelToConfig(MainViewModel viewModel)
        {
            var config = new FanControlConfigV2()
            {
                CriticalTemperature = viewModel.CriticalTemperature,
                EcPollInterval = viewModel.EcPollInterval,
                NotebookModel = viewModel.NotebookModel,
                Author = viewModel.Author,
                ReadWriteWords = viewModel.ReadWriteWords
            };

            if (viewModel.FanConfigs != null)
            {
                config.FanConfigurations = ConvertViewModelsToFanConfigs(viewModel.FanConfigs);
            }

            if (viewModel.RegisterWriteConfigs != null)
            {
                config.RegisterWriteConfigurations = ConvertViewModelsToRegisterWriteConfigs(viewModel.RegisterWriteConfigs);
            }

            return config;
        }
예제 #8
0
        private void AddOrUpdateConfig(FanControlConfigV2 config, string configName)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            if (string.IsNullOrWhiteSpace(config.NotebookModel))
            {
                config.NotebookModel = this.ActualNotebookModel;
            }

            if (this.configManager.Contains(configName))
            {
                this.configManager.UpdateConfig(configName, config);
            }
            else
            {
                this.configManager.AddConfig(config, configName);
            }
        }
예제 #9
0
 public FanControl(FanControlConfigV2 config)
     : this(config, PluginsDirectory)
 {
 }