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).
authormoel.mich
Tue, 30 Dec 2014 16:02:52 +0000
changeset 4283c1cdc197b24
parent 427 39ed1a16c32a
child 429 5d87c9fc69f6
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).
Hardware/ATI/ATIGPU.cs
Hardware/Control.cs
Hardware/IControl.cs
Hardware/Mainboard/SuperIOHardware.cs
Hardware/Nvidia/NvidiaGPU.cs
Properties/AssemblyVersion.cs
     1.1 --- a/Hardware/ATI/ATIGPU.cs	Sun Dec 28 22:42:36 2014 +0000
     1.2 +++ b/Hardware/ATI/ATIGPU.cs	Tue Dec 30 16:02:52 2014 +0000
     1.3 @@ -4,7 +4,7 @@
     1.4    License, v. 2.0. If a copy of the MPL was not distributed with this
     1.5    file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.6   
     1.7 -  Copyright (C) 2009-2011 Michael Möller <mmoeller@openhardwaremonitor.org>
     1.8 +  Copyright (C) 2009-2014 Michael Möller <mmoeller@openhardwaremonitor.org>
     1.9  	
    1.10  */
    1.11  
    1.12 @@ -24,10 +24,7 @@
    1.13      private readonly Sensor coreVoltage;
    1.14      private readonly Sensor coreLoad;
    1.15      private readonly Sensor controlSensor;
    1.16 -    private readonly Control fanControl;
    1.17 -
    1.18 -    private bool restoreDefaultFanSpeedRequired = false;
    1.19 -    private ADLFanSpeedValue initialFanSpeedValue;    
    1.20 +    private readonly Control fanControl;  
    1.21  
    1.22      public ATIGPU(string name, int adapterIndex, int busNumber, 
    1.23        int deviceNumber, ISettings settings) 
    1.24 @@ -64,31 +61,8 @@
    1.25        Update();                   
    1.26      }
    1.27  
    1.28 -    private void SaveDefaultFanSpeed() {
    1.29 -      if (!restoreDefaultFanSpeedRequired) {        
    1.30 -        initialFanSpeedValue = new ADLFanSpeedValue();
    1.31 -        initialFanSpeedValue.SpeedType =
    1.32 -          ADL.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
    1.33 -        restoreDefaultFanSpeedRequired = 
    1.34 -          ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0,
    1.35 -          ref initialFanSpeedValue) == ADL.ADL_OK;
    1.36 -      }
    1.37 -    }
    1.38 -
    1.39 -    private void RestoreDefaultFanSpeed() {
    1.40 -      if (restoreDefaultFanSpeedRequired) {        
    1.41 -        ADL.ADL_Overdrive5_FanSpeed_Set(adapterIndex, 0,
    1.42 -          ref this.initialFanSpeedValue);
    1.43 -        if ((initialFanSpeedValue.Flags &
    1.44 -          ADL.ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED) == 0)
    1.45 -          ADL.ADL_Overdrive5_FanSpeedToDefault_Set(adapterIndex, 0);
    1.46 -        restoreDefaultFanSpeedRequired = false;
    1.47 -      }
    1.48 -    }
    1.49 -
    1.50      private void SoftwareControlValueChanged(IControl control) {
    1.51 -      if (control.ControlMode == ControlMode.Software) {
    1.52 -        SaveDefaultFanSpeed();
    1.53 +      if (control.ControlMode == ControlMode.Software) {        
    1.54          ADLFanSpeedValue adlf = new ADLFanSpeedValue();
    1.55          adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
    1.56          adlf.Flags = ADL.ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED;
    1.57 @@ -98,13 +72,24 @@
    1.58      }
    1.59  
    1.60      private void ControlModeChanged(IControl control) {
    1.61 -      if (control.ControlMode == ControlMode.Default) {
    1.62 -        RestoreDefaultFanSpeed();     
    1.63 -      } else {
    1.64 -        SoftwareControlValueChanged(control);
    1.65 +      switch (control.ControlMode) {
    1.66 +        case ControlMode.Undefined:
    1.67 +          return;
    1.68 +        case ControlMode.Default:
    1.69 +          SetDefaultFanSpeed();
    1.70 +          break;
    1.71 +        case ControlMode.Software:
    1.72 +          SoftwareControlValueChanged(control);
    1.73 +          break;
    1.74 +        default:
    1.75 +          return;
    1.76        }
    1.77      }
    1.78  
    1.79 +    private void SetDefaultFanSpeed() {
    1.80 +      ADL.ADL_Overdrive5_FanSpeedToDefault_Set(adapterIndex, 0);
    1.81 +    }
    1.82 +
    1.83      public int BusNumber { get { return busNumber; } }
    1.84  
    1.85      public int DeviceNumber { get { return deviceNumber; } }
    1.86 @@ -186,7 +171,8 @@
    1.87        this.fanControl.SoftwareControlValueChanged -=
    1.88          SoftwareControlValueChanged;
    1.89  
    1.90 -      RestoreDefaultFanSpeed();
    1.91 +      if (this.fanControl.ControlMode != ControlMode.Undefined)
    1.92 +        SetDefaultFanSpeed();
    1.93        base.Close();
    1.94      }
    1.95    }
     2.1 --- a/Hardware/Control.cs	Sun Dec 28 22:42:36 2014 +0000
     2.2 +++ b/Hardware/Control.cs	Tue Dec 30 16:02:52 2014 +0000
     2.3 @@ -4,7 +4,7 @@
     2.4    License, v. 2.0. If a copy of the MPL was not distributed with this
     2.5    file, You can obtain one at http://mozilla.org/MPL/2.0/.
     2.6   
     2.7 -  Copyright (C) 2010 Michael Möller <mmoeller@openhardwaremonitor.org>
     2.8 +  Copyright (C) 2010-2014 Michael Möller <mmoeller@openhardwaremonitor.org>
     2.9  	
    2.10  */
    2.11  
    2.12 @@ -42,11 +42,11 @@
    2.13        int mode;
    2.14        if (!int.TryParse(settings.GetValue(
    2.15            new Identifier(identifier, "mode").ToString(),
    2.16 -          ((int)ControlMode.Default).ToString(CultureInfo.InvariantCulture)),
    2.17 +          ((int)ControlMode.Undefined).ToString(CultureInfo.InvariantCulture)),
    2.18          NumberStyles.Integer, CultureInfo.InvariantCulture,
    2.19          out mode)) 
    2.20        {
    2.21 -        this.mode = ControlMode.Default;
    2.22 +        this.mode = ControlMode.Undefined;
    2.23        } else {
    2.24          this.mode = (ControlMode)mode;
    2.25        }
     3.1 --- a/Hardware/IControl.cs	Sun Dec 28 22:42:36 2014 +0000
     3.2 +++ b/Hardware/IControl.cs	Tue Dec 30 16:02:52 2014 +0000
     3.3 @@ -4,15 +4,16 @@
     3.4    License, v. 2.0. If a copy of the MPL was not distributed with this
     3.5    file, You can obtain one at http://mozilla.org/MPL/2.0/.
     3.6   
     3.7 -  Copyright (C) 2010 Michael Möller <mmoeller@openhardwaremonitor.org>
     3.8 +  Copyright (C) 2010-2014 Michael Möller <mmoeller@openhardwaremonitor.org>
     3.9  	
    3.10  */
    3.11  
    3.12  namespace OpenHardwareMonitor.Hardware {
    3.13  
    3.14    public enum ControlMode {
    3.15 -    Default,
    3.16 -    Software
    3.17 +    Undefined,
    3.18 +    Software,
    3.19 +    Default
    3.20    }
    3.21  
    3.22    public interface IControl {
     4.1 --- a/Hardware/Mainboard/SuperIOHardware.cs	Sun Dec 28 22:42:36 2014 +0000
     4.2 +++ b/Hardware/Mainboard/SuperIOHardware.cs	Tue Dec 30 16:02:52 2014 +0000
     4.3 @@ -4,7 +4,7 @@
     4.4    License, v. 2.0. If a copy of the MPL was not distributed with this
     4.5    file, You can obtain one at http://mozilla.org/MPL/2.0/.
     4.6   
     4.7 -  Copyright (C) 2009-2013 Michael Möller <mmoeller@openhardwaremonitor.org>
     4.8 +  Copyright (C) 2009-2014 Michael Möller <mmoeller@openhardwaremonitor.org>
     4.9  	
    4.10  */
    4.11  
    4.12 @@ -72,18 +72,37 @@
    4.13              this, settings);
    4.14            Control control = new Control(sensor, settings, 0, 100);
    4.15            control.ControlModeChanged += (cc) => {
    4.16 -            if (cc.ControlMode == ControlMode.Default) {
    4.17 -              superIO.SetControl(index, null);
    4.18 -            } else {
    4.19 -              superIO.SetControl(index, (byte)(cc.SoftwareValue * 2.55));
    4.20 +            switch (cc.ControlMode) {
    4.21 +              case ControlMode.Undefined:
    4.22 +                return;
    4.23 +              case ControlMode.Default:
    4.24 +                superIO.SetControl(index, null);
    4.25 +                break;
    4.26 +              case ControlMode.Software:
    4.27 +                superIO.SetControl(index, (byte)(cc.SoftwareValue * 2.55));
    4.28 +                break;
    4.29 +              default:
    4.30 +                return;
    4.31              }
    4.32            };
    4.33            control.SoftwareControlValueChanged += (cc) => {
    4.34              if (cc.ControlMode == ControlMode.Software)
    4.35                superIO.SetControl(index, (byte)(cc.SoftwareValue * 2.55));
    4.36            };
    4.37 -          if (control.ControlMode == ControlMode.Software)
    4.38 -            superIO.SetControl(index, (byte)(control.SoftwareValue * 2.55));
    4.39 +
    4.40 +          switch (control.ControlMode) {
    4.41 +            case ControlMode.Undefined:
    4.42 +              break;
    4.43 +            case ControlMode.Default:
    4.44 +              superIO.SetControl(index, null);
    4.45 +              break;
    4.46 +            case ControlMode.Software:
    4.47 +              superIO.SetControl(index, (byte)(control.SoftwareValue * 2.55));
    4.48 +              break;
    4.49 +            default:
    4.50 +              break;
    4.51 +          }            
    4.52 +
    4.53            sensor.Control = control;
    4.54            controls.Add(sensor);
    4.55            ActivateSensor(sensor);
     5.1 --- a/Hardware/Nvidia/NvidiaGPU.cs	Sun Dec 28 22:42:36 2014 +0000
     5.2 +++ b/Hardware/Nvidia/NvidiaGPU.cs	Tue Dec 30 16:02:52 2014 +0000
     5.3 @@ -4,7 +4,7 @@
     5.4    License, v. 2.0. If a copy of the MPL was not distributed with this
     5.5    file, You can obtain one at http://mozilla.org/MPL/2.0/.
     5.6   
     5.7 -  Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
     5.8 +  Copyright (C) 2009-2014 Michael Möller <mmoeller@openhardwaremonitor.org>
     5.9  	Copyright (C) 2011 Christian Vallières
    5.10   
    5.11  */
    5.12 @@ -28,9 +28,6 @@
    5.13      private readonly Sensor memoryLoad;
    5.14      private readonly Control fanControl;
    5.15  
    5.16 -    private bool restoreDefaultFanSpeedRequired;
    5.17 -    private NvLevel initialFanSpeedValue;
    5.18 -
    5.19      public NvidiaGPU(int adapterIndex, NvPhysicalGpuHandle handle,
    5.20        NvDisplayHandle? displayHandle, ISettings settings)
    5.21        : base(GetName(handle), new Identifier("nvidiagpu",
    5.22 @@ -431,7 +428,6 @@
    5.23      }
    5.24  
    5.25      private void SoftwareControlValueChanged(IControl control) {
    5.26 -      SaveDefaultFanSpeed();
    5.27        NvGPUCoolerLevels coolerLevels = new NvGPUCoolerLevels();
    5.28        coolerLevels.Version = NVAPI.GPU_COOLER_LEVELS_VER;
    5.29        coolerLevels.Levels = new NvLevel[NVAPI.MAX_COOLER_PER_GPU];
    5.30 @@ -440,34 +436,39 @@
    5.31        NVAPI.NvAPI_GPU_SetCoolerLevels(handle, 0, ref coolerLevels);
    5.32      }
    5.33  
    5.34 -    private void SaveDefaultFanSpeed() {
    5.35 -      if (!restoreDefaultFanSpeedRequired) {
    5.36 -        NvGPUCoolerSettings coolerSettings = GetCoolerSettings();
    5.37 -        if (coolerSettings.Count > 0) {
    5.38 -          restoreDefaultFanSpeedRequired = true;
    5.39 -          initialFanSpeedValue.Level = coolerSettings.Cooler[0].CurrentLevel;
    5.40 -          initialFanSpeedValue.Policy = coolerSettings.Cooler[0].CurrentPolicy;
    5.41 -        }
    5.42 +    private void ControlModeChanged(IControl control) {
    5.43 +      switch (control.ControlMode) {
    5.44 +        case ControlMode.Undefined:
    5.45 +          return;
    5.46 +        case ControlMode.Default:
    5.47 +          SetDefaultFanSpeed();
    5.48 +          break;
    5.49 +        case ControlMode.Software:
    5.50 +          SoftwareControlValueChanged(control);
    5.51 +          break;
    5.52 +        default:
    5.53 +          return;
    5.54        }
    5.55      }
    5.56  
    5.57 -    private void ControlModeChanged(IControl control) {
    5.58 -      if (control.ControlMode == ControlMode.Default) {
    5.59 -        RestoreDefaultFanSpeed();
    5.60 -      } else {
    5.61 -        SoftwareControlValueChanged(control);
    5.62 -      }
    5.63 +    private void SetDefaultFanSpeed() {
    5.64 +      NvGPUCoolerLevels coolerLevels = new NvGPUCoolerLevels();
    5.65 +      coolerLevels.Version = NVAPI.GPU_COOLER_LEVELS_VER;
    5.66 +      coolerLevels.Levels = new NvLevel[NVAPI.MAX_COOLER_PER_GPU];
    5.67 +      coolerLevels.Levels[0].Policy = 0x20;
    5.68 +      NVAPI.NvAPI_GPU_SetCoolerLevels(handle, 0, ref coolerLevels);
    5.69      }
    5.70  
    5.71 -    private void RestoreDefaultFanSpeed() {
    5.72 -      if (restoreDefaultFanSpeedRequired) {
    5.73 -        NvGPUCoolerLevels coolerLevels = new NvGPUCoolerLevels();
    5.74 -        coolerLevels.Version = NVAPI.GPU_COOLER_LEVELS_VER;
    5.75 -        coolerLevels.Levels = new NvLevel[NVAPI.MAX_COOLER_PER_GPU];
    5.76 -        coolerLevels.Levels[0] = initialFanSpeedValue;
    5.77 -        NVAPI.NvAPI_GPU_SetCoolerLevels(handle, 0, ref coolerLevels);
    5.78 -        restoreDefaultFanSpeedRequired = false;
    5.79 +    public override void Close() {
    5.80 +      if (this.fanControl != null) {
    5.81 +        this.fanControl.ControlModeChanged -= ControlModeChanged;
    5.82 +        this.fanControl.SoftwareControlValueChanged -=
    5.83 +          SoftwareControlValueChanged;
    5.84 +
    5.85 +        if (this.fanControl.ControlMode != ControlMode.Undefined)
    5.86 +          SetDefaultFanSpeed();
    5.87        }
    5.88 +      base.Close();
    5.89      }
    5.90    }
    5.91  }
     6.1 --- a/Properties/AssemblyVersion.cs	Sun Dec 28 22:42:36 2014 +0000
     6.2 +++ b/Properties/AssemblyVersion.cs	Tue Dec 30 16:02:52 2014 +0000
     6.3 @@ -4,11 +4,11 @@
     6.4    License, v. 2.0. If a copy of the MPL was not distributed with this
     6.5    file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6.6   
     6.7 -  Copyright (C) 2009-2013 Michael Möller <mmoeller@openhardwaremonitor.org>
     6.8 +  Copyright (C) 2009-2014 Michael Möller <mmoeller@openhardwaremonitor.org>
     6.9   
    6.10  */
    6.11  
    6.12  using System.Reflection;
    6.13  
    6.14 -[assembly: AssemblyVersion("0.6.0.15")]
    6.15 -[assembly: AssemblyInformationalVersion("0.6.0.15 Alpha")]
    6.16 \ No newline at end of file
    6.17 +[assembly: AssemblyVersion("0.6.0.16")]
    6.18 +[assembly: AssemblyInformationalVersion("0.6.0.16 Alpha")]
    6.19 \ No newline at end of file