private static void AccessEcSynchronized(Action <IEmbeddedController> callback) { using (IEmbeddedController ec = LoadEC()) { if (ec != null) { AccessEcSynchronized(callback, ec); } } }
public Fan(IEmbeddedController ec, FanConfiguration config, int criticalTemperature, bool readWriteWords) { this.ec = ec; this.fanConfig = config; this.criticalTemperature = criticalTemperature; this.readWriteWords = readWriteWords; this.overriddenPercentages = new Dictionary <float, FanSpeedPercentageOverride>(); this.overriddenValues = new Dictionary <int, FanSpeedPercentageOverride>(); this.minSpeedValueWrite = config.MinSpeedValue; this.maxSpeedValueWrite = config.MaxSpeedValue; if (config.IndependentReadMinMaxValues) { this.minSpeedValueRead = config.MinSpeedValueRead; this.maxSpeedValueRead = config.MaxSpeedValueRead; } else { this.minSpeedValueRead = this.minSpeedValueWrite; this.maxSpeedValueRead = this.maxSpeedValueWrite; } this.minSpeedValueReadAbs = Math.Min(this.minSpeedValueRead, this.maxSpeedValueRead); this.maxSpeedValueReadAbs = Math.Max(this.minSpeedValueRead, this.maxSpeedValueRead); if (config.TemperatureThresholds != null && config.TemperatureThresholds.Count > 0) { this.threshMan = new TemperatureThresholdManager(config.TemperatureThresholds); } else { this.threshMan = new TemperatureThresholdManager(FanConfiguration.DefaultTemperatureThresholds); } foreach (FanSpeedPercentageOverride o in config.FanSpeedPercentageOverrides) { if (o.TargetOperation.HasFlag(OverrideTargetOperation.Write) && !this.overriddenPercentages.ContainsKey(o.FanSpeedPercentage)) { this.overriddenPercentages.Add(o.FanSpeedPercentage, o); } if (o.TargetOperation.HasFlag(OverrideTargetOperation.Read) && !this.overriddenValues.ContainsKey(o.FanSpeedValue)) { this.overriddenValues.Add(o.FanSpeedValue, o); } } }
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); } }
public FanControl( FanControlConfigV2 config, ITemperatureFilter filter, IEmbeddedController ec, ITemperatureMonitor tempMon) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (filter == null) { throw new ArgumentNullException(nameof(filter)); } if (ec == null) { throw new ArgumentNullException(nameof(ec)); } if (tempMon == null) { throw new ArgumentNullException(nameof(tempMon)); } this.ec = ec; this.tempMon = tempMon; this.tempFilter = filter; this.config = (FanControlConfigV2)config.Clone(); this.pollInterval = config.EcPollInterval; this.requestedSpeeds = new float[config.FanConfigurations.Count]; this.fanInfo = new FanInformation[config.FanConfigurations.Count]; this.fans = new Fan[config.FanConfigurations.Count]; this.lockTimeout = Math.Min(MaxLockTimeout, config.EcPollInterval); this.asyncOp = AsyncOperationManager.CreateOperation(null); for (int i = 0; i < config.FanConfigurations.Count; i++) { var cfg = this.config.FanConfigurations[i]; if (string.IsNullOrWhiteSpace(cfg.FanDisplayName)) { cfg.FanDisplayName = "Fan #" + (i + 1); } this.fanInfo[i] = new FanInformation(0, 0, true, false, cfg.FanDisplayName); this.fans[i] = new Fan(this.ec, cfg, config.CriticalTemperature, config.ReadWriteWords); this.requestedSpeeds[i] = AutoFanSpeedPercentage; } }
internal FanControl( FanControlConfigV2 config, ITemperatureFilter filter, IEmbeddedController ec, ITemperatureMonitor tempMon, Fan[] fans) : this(config, filter, ec, tempMon) { if (fans == null) { throw new ArgumentNullException(nameof(fans)); } if (fans.Length != this.fans.Length) { throw new ArgumentException( "The length must be equal to the number of fan configurations", nameof(fans)); } this.fans = fans; }
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"); } }
private static void AccessEcSynchronized(Action <IEmbeddedController> callback, IEmbeddedController ec) { if (ec.AcquireLock(200)) { try { callback(ec); } finally { ec.ReleaseLock(); } } else { Console.Error.WriteLine("Could not acquire EC lock"); } }
private static void ECMonitor(int timespan, int interval, string reportPath, bool clearly) { var dict = new Dictionary <byte, List <byte> >(); Console.CancelKeyPress += (sender, e) => { if (reportPath != null) { SaveMonitoringReport(reportPath, dict, clearly); } }; using (IEmbeddedController embeddedController = LoadEC()) { if (embeddedController == null) { return; } byte[] initialBytes = new byte[byte.MaxValue]; for (byte reg = 0; reg < initialBytes.Length; reg++) { AccessEcSynchronized(ec => { initialBytes[reg] = ec.ReadByte(reg); }, embeddedController); } int loopCount = 0; while ((timespan < 1) || (loopCount < Math.Ceiling(((double)timespan / interval) - 1))) { Thread.Sleep(interval * 1000); AccessEcSynchronized(ec => { for (byte reg = 0; reg < initialBytes.Length; reg++) { byte value = ec.ReadByte(reg); if (dict.ContainsKey(reg)) { dict[reg].Add(value); } else if (value != initialBytes[reg]) { var log = new List <byte>(); for (int j = 0; j <= loopCount; j++) { log.Add(initialBytes[reg]); } log.Add(value); dict.Add(reg, log); } } }, embeddedController); Console.Clear(); PrintMonitoringStatus(dict, clearly); loopCount++; } } if (reportPath != null) { SaveMonitoringReport(reportPath, dict, clearly); } }
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); } }
private static void AccessEcSynchronized(Action <IEmbeddedController> callback, IEmbeddedController ec) { if (ec.AcquireLock(200)) { try { callback(ec); } finally { ec.ReleaseLock(); } } }
private static void ECMonitor(int timespan, int interval, string reportPath, bool clearly, bool decimalFormat) { var logs = new RegisterLog[byte.MaxValue]; Console.CancelKeyPress += (sender, e) => { if (reportPath != null) { SaveRegisterLogs(reportPath, logs, clearly, decimalFormat); } }; using (ec = LoadEC()) { if (ec == null) { return; } Console.WriteLine("monitoring..."); for (byte b = 0; b < logs.Length; b++) { AccessEcSynchronized(ec => { logs[b].Values = new List <byte>(); logs[b].Values.Add(ec.ReadByte(b)); }, ec); } int loopCount = 0; while ((timespan < 1) || (loopCount < Math.Ceiling(((double)timespan / interval) - 1))) { Thread.Sleep(interval * 1000); AccessEcSynchronized(ec => { for (int i = 0; i < logs.Length; i++) { byte value = ec.ReadByte((byte)i); logs[i].Values.Add(value); if (value != logs[i].Values[0]) { logs[i].Print = true; } } }, ec); Console.Clear(); PrintRegisterLogs(logs, clearly, decimalFormat); loopCount++; } } if (reportPath != null) { SaveRegisterLogs(reportPath, logs, clearly, decimalFormat); } }
public MainClass() { var ecLoader = new FanControlPluginLoader<IEmbeddedController>(FanControl.PluginsDirectory); this.ec = ecLoader.FanControlPlugin; this.ec.Initialize(); }