Пример #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
        private static T LoadPlugin<T>(string pluginsDirectory) where T : IFanControlPlugin
        {
            if (pluginsDirectory == null)
            {
                throw new ArgumentNullException(nameof(pluginsDirectory));
            }

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

            var pluginLoader = new FanControlPluginLoader<T>(pluginsDirectory);

            if (pluginLoader.FanControlPlugin == null)
            {
                throw new PlatformNotSupportedException(
                    "Could not load a  plugin which implements " + typeof(T));
            }

            return pluginLoader.FanControlPlugin;
        }
Пример #3
0
        private static IEmbeddedController LoadEC()
        {
            var ecLoader = new FanControlPluginLoader <IEmbeddedController>(FanControl.PluginsDirectory);

            if (ecLoader.FanControlPlugin == null)
            {
                return(null);
            }

            ecLoader.FanControlPlugin.Initialize();

            if (ecLoader.FanControlPlugin.IsInitialized)
            {
                return(ecLoader.FanControlPlugin);
            }
            else
            {
                ecLoader.FanControlPlugin.Dispose();
            }

            return(null);
        }
Пример #4
0
        private static void AccessEcSynchronized(Action <IEmbeddedController> callback)
        {
            var ecLoader           = new FanControlPluginLoader <IEmbeddedController>(FanControl.PluginsDirectory);
            IEmbeddedController ec = ecLoader.FanControlPlugin;

            ec.Initialize();

            if (ec.AcquireLock(200))
            {
                try
                {
                    callback(ec);
                }
                finally
                {
                    ec.ReleaseLock();
                }
            }
            else
            {
                Console.Error.WriteLine("Error connecting to Embedded Controller");
            }
        }
Пример #5
0
        private static IEmbeddedController LoadEC()
        {
            var ecLoader = new FanControlPluginLoader <IEmbeddedController>(FanControl.PluginsDirectory);

            if (ecLoader.FanControlPlugin == null)
            {
                Console.Error.WriteLine("Could not load EC plugin");
                return(null);
            }

            ecLoader.FanControlPlugin.Initialize();

            if (ecLoader.FanControlPlugin.IsInitialized)
            {
                return(ecLoader.FanControlPlugin);
            }
            else
            {
                Console.Error.WriteLine("EC initialization failed");
                ecLoader.FanControlPlugin.Dispose();
            }

            return(null);
        }
Пример #6
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);
            }
        }
Пример #7
0
 public MainClass()
 {
     var ecLoader = new FanControlPluginLoader<IEmbeddedController>(FanControl.PluginsDirectory);
     this.ec = ecLoader.FanControlPlugin;
     this.ec.Initialize();
 }
Пример #8
0
        private static void AccessEcSynchronized(Action<IEmbeddedController> callback)
        {
            var ecLoader = new FanControlPluginLoader<IEmbeddedController>(FanControl.PluginsDirectory);
            IEmbeddedController ec = ecLoader.FanControlPlugin;
            ec.Initialize();

            if (ec.AcquireLock(200))
            {
                try
                {
                    callback(ec);
                }
                finally
                {
                    ec.ReleaseLock();
                }
            }
            else
            {
                Console.Error.WriteLine("Error connecting to Embedded Controller");
            }
        }