# HG changeset patch # User moel.mich # Date 1419955372 0 # Node ID 3c1cdc197b24b5fe8ebbc5a2d21a08c9ebc30066 # Parent 39ed1a16c32a573fc2dbf2e44b3ad22dbf613c61 Added a new "Undefined" control mode. Changed the GPU fan control to restore to default (auto) settings when the Open Hardware Monitor closes (unless the control remained in "Undefined" mode). diff -r 39ed1a16c32a -r 3c1cdc197b24 Hardware/ATI/ATIGPU.cs --- a/Hardware/ATI/ATIGPU.cs Sun Dec 28 22:42:36 2014 +0000 +++ b/Hardware/ATI/ATIGPU.cs Tue Dec 30 16:02:52 2014 +0000 @@ -4,7 +4,7 @@ License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - Copyright (C) 2009-2011 Michael Möller + Copyright (C) 2009-2014 Michael Möller */ @@ -24,10 +24,7 @@ private readonly Sensor coreVoltage; private readonly Sensor coreLoad; private readonly Sensor controlSensor; - private readonly Control fanControl; - - private bool restoreDefaultFanSpeedRequired = false; - private ADLFanSpeedValue initialFanSpeedValue; + private readonly Control fanControl; public ATIGPU(string name, int adapterIndex, int busNumber, int deviceNumber, ISettings settings) @@ -64,31 +61,8 @@ Update(); } - private void SaveDefaultFanSpeed() { - if (!restoreDefaultFanSpeedRequired) { - initialFanSpeedValue = new ADLFanSpeedValue(); - initialFanSpeedValue.SpeedType = - ADL.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT; - restoreDefaultFanSpeedRequired = - ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0, - ref initialFanSpeedValue) == ADL.ADL_OK; - } - } - - private void RestoreDefaultFanSpeed() { - if (restoreDefaultFanSpeedRequired) { - ADL.ADL_Overdrive5_FanSpeed_Set(adapterIndex, 0, - ref this.initialFanSpeedValue); - if ((initialFanSpeedValue.Flags & - ADL.ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED) == 0) - ADL.ADL_Overdrive5_FanSpeedToDefault_Set(adapterIndex, 0); - restoreDefaultFanSpeedRequired = false; - } - } - private void SoftwareControlValueChanged(IControl control) { - if (control.ControlMode == ControlMode.Software) { - SaveDefaultFanSpeed(); + if (control.ControlMode == ControlMode.Software) { ADLFanSpeedValue adlf = new ADLFanSpeedValue(); adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT; adlf.Flags = ADL.ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED; @@ -98,13 +72,24 @@ } private void ControlModeChanged(IControl control) { - if (control.ControlMode == ControlMode.Default) { - RestoreDefaultFanSpeed(); - } else { - SoftwareControlValueChanged(control); + switch (control.ControlMode) { + case ControlMode.Undefined: + return; + case ControlMode.Default: + SetDefaultFanSpeed(); + break; + case ControlMode.Software: + SoftwareControlValueChanged(control); + break; + default: + return; } } + private void SetDefaultFanSpeed() { + ADL.ADL_Overdrive5_FanSpeedToDefault_Set(adapterIndex, 0); + } + public int BusNumber { get { return busNumber; } } public int DeviceNumber { get { return deviceNumber; } } @@ -186,7 +171,8 @@ this.fanControl.SoftwareControlValueChanged -= SoftwareControlValueChanged; - RestoreDefaultFanSpeed(); + if (this.fanControl.ControlMode != ControlMode.Undefined) + SetDefaultFanSpeed(); base.Close(); } } diff -r 39ed1a16c32a -r 3c1cdc197b24 Hardware/Control.cs --- a/Hardware/Control.cs Sun Dec 28 22:42:36 2014 +0000 +++ b/Hardware/Control.cs Tue Dec 30 16:02:52 2014 +0000 @@ -4,7 +4,7 @@ License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - Copyright (C) 2010 Michael Möller + Copyright (C) 2010-2014 Michael Möller */ @@ -42,11 +42,11 @@ int mode; if (!int.TryParse(settings.GetValue( new Identifier(identifier, "mode").ToString(), - ((int)ControlMode.Default).ToString(CultureInfo.InvariantCulture)), + ((int)ControlMode.Undefined).ToString(CultureInfo.InvariantCulture)), NumberStyles.Integer, CultureInfo.InvariantCulture, out mode)) { - this.mode = ControlMode.Default; + this.mode = ControlMode.Undefined; } else { this.mode = (ControlMode)mode; } diff -r 39ed1a16c32a -r 3c1cdc197b24 Hardware/IControl.cs --- a/Hardware/IControl.cs Sun Dec 28 22:42:36 2014 +0000 +++ b/Hardware/IControl.cs Tue Dec 30 16:02:52 2014 +0000 @@ -4,15 +4,16 @@ License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - Copyright (C) 2010 Michael Möller + Copyright (C) 2010-2014 Michael Möller */ namespace OpenHardwareMonitor.Hardware { public enum ControlMode { - Default, - Software + Undefined, + Software, + Default } public interface IControl { diff -r 39ed1a16c32a -r 3c1cdc197b24 Hardware/Mainboard/SuperIOHardware.cs --- a/Hardware/Mainboard/SuperIOHardware.cs Sun Dec 28 22:42:36 2014 +0000 +++ b/Hardware/Mainboard/SuperIOHardware.cs Tue Dec 30 16:02:52 2014 +0000 @@ -4,7 +4,7 @@ License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - Copyright (C) 2009-2013 Michael Möller + Copyright (C) 2009-2014 Michael Möller */ @@ -72,18 +72,37 @@ this, settings); Control control = new Control(sensor, settings, 0, 100); control.ControlModeChanged += (cc) => { - if (cc.ControlMode == ControlMode.Default) { - superIO.SetControl(index, null); - } else { - superIO.SetControl(index, (byte)(cc.SoftwareValue * 2.55)); + switch (cc.ControlMode) { + case ControlMode.Undefined: + return; + case ControlMode.Default: + superIO.SetControl(index, null); + break; + case ControlMode.Software: + superIO.SetControl(index, (byte)(cc.SoftwareValue * 2.55)); + break; + default: + return; } }; control.SoftwareControlValueChanged += (cc) => { if (cc.ControlMode == ControlMode.Software) superIO.SetControl(index, (byte)(cc.SoftwareValue * 2.55)); }; - if (control.ControlMode == ControlMode.Software) - superIO.SetControl(index, (byte)(control.SoftwareValue * 2.55)); + + switch (control.ControlMode) { + case ControlMode.Undefined: + break; + case ControlMode.Default: + superIO.SetControl(index, null); + break; + case ControlMode.Software: + superIO.SetControl(index, (byte)(control.SoftwareValue * 2.55)); + break; + default: + break; + } + sensor.Control = control; controls.Add(sensor); ActivateSensor(sensor); diff -r 39ed1a16c32a -r 3c1cdc197b24 Hardware/Nvidia/NvidiaGPU.cs --- a/Hardware/Nvidia/NvidiaGPU.cs Sun Dec 28 22:42:36 2014 +0000 +++ b/Hardware/Nvidia/NvidiaGPU.cs Tue Dec 30 16:02:52 2014 +0000 @@ -4,7 +4,7 @@ License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - Copyright (C) 2009-2012 Michael Möller + Copyright (C) 2009-2014 Michael Möller Copyright (C) 2011 Christian Vallières */ @@ -28,9 +28,6 @@ private readonly Sensor memoryLoad; private readonly Control fanControl; - private bool restoreDefaultFanSpeedRequired; - private NvLevel initialFanSpeedValue; - public NvidiaGPU(int adapterIndex, NvPhysicalGpuHandle handle, NvDisplayHandle? displayHandle, ISettings settings) : base(GetName(handle), new Identifier("nvidiagpu", @@ -431,7 +428,6 @@ } private void SoftwareControlValueChanged(IControl control) { - SaveDefaultFanSpeed(); NvGPUCoolerLevels coolerLevels = new NvGPUCoolerLevels(); coolerLevels.Version = NVAPI.GPU_COOLER_LEVELS_VER; coolerLevels.Levels = new NvLevel[NVAPI.MAX_COOLER_PER_GPU]; @@ -440,34 +436,39 @@ NVAPI.NvAPI_GPU_SetCoolerLevels(handle, 0, ref coolerLevels); } - private void SaveDefaultFanSpeed() { - if (!restoreDefaultFanSpeedRequired) { - NvGPUCoolerSettings coolerSettings = GetCoolerSettings(); - if (coolerSettings.Count > 0) { - restoreDefaultFanSpeedRequired = true; - initialFanSpeedValue.Level = coolerSettings.Cooler[0].CurrentLevel; - initialFanSpeedValue.Policy = coolerSettings.Cooler[0].CurrentPolicy; - } + private void ControlModeChanged(IControl control) { + switch (control.ControlMode) { + case ControlMode.Undefined: + return; + case ControlMode.Default: + SetDefaultFanSpeed(); + break; + case ControlMode.Software: + SoftwareControlValueChanged(control); + break; + default: + return; } } - private void ControlModeChanged(IControl control) { - if (control.ControlMode == ControlMode.Default) { - RestoreDefaultFanSpeed(); - } else { - SoftwareControlValueChanged(control); - } + private void SetDefaultFanSpeed() { + NvGPUCoolerLevels coolerLevels = new NvGPUCoolerLevels(); + coolerLevels.Version = NVAPI.GPU_COOLER_LEVELS_VER; + coolerLevels.Levels = new NvLevel[NVAPI.MAX_COOLER_PER_GPU]; + coolerLevels.Levels[0].Policy = 0x20; + NVAPI.NvAPI_GPU_SetCoolerLevels(handle, 0, ref coolerLevels); } - private void RestoreDefaultFanSpeed() { - if (restoreDefaultFanSpeedRequired) { - NvGPUCoolerLevels coolerLevels = new NvGPUCoolerLevels(); - coolerLevels.Version = NVAPI.GPU_COOLER_LEVELS_VER; - coolerLevels.Levels = new NvLevel[NVAPI.MAX_COOLER_PER_GPU]; - coolerLevels.Levels[0] = initialFanSpeedValue; - NVAPI.NvAPI_GPU_SetCoolerLevels(handle, 0, ref coolerLevels); - restoreDefaultFanSpeedRequired = false; + public override void Close() { + if (this.fanControl != null) { + this.fanControl.ControlModeChanged -= ControlModeChanged; + this.fanControl.SoftwareControlValueChanged -= + SoftwareControlValueChanged; + + if (this.fanControl.ControlMode != ControlMode.Undefined) + SetDefaultFanSpeed(); } + base.Close(); } } } diff -r 39ed1a16c32a -r 3c1cdc197b24 Properties/AssemblyVersion.cs --- a/Properties/AssemblyVersion.cs Sun Dec 28 22:42:36 2014 +0000 +++ b/Properties/AssemblyVersion.cs Tue Dec 30 16:02:52 2014 +0000 @@ -4,11 +4,11 @@ License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - Copyright (C) 2009-2013 Michael Möller + Copyright (C) 2009-2014 Michael Möller */ using System.Reflection; -[assembly: AssemblyVersion("0.6.0.15")] -[assembly: AssemblyInformationalVersion("0.6.0.15 Alpha")] \ No newline at end of file +[assembly: AssemblyVersion("0.6.0.16")] +[assembly: AssemblyInformationalVersion("0.6.0.16 Alpha")] \ No newline at end of file