diff -r 6dc755f1970e -r 045eb5c1ec32 Hardware/ATI/ATIGPU.cs --- a/Hardware/ATI/ATIGPU.cs Thu Jan 20 21:31:54 2011 +0000 +++ b/Hardware/ATI/ATIGPU.cs Thu Jan 20 21:48:26 2011 +0000 @@ -54,7 +54,8 @@ private readonly Sensor controlSensor; private readonly Control fanControl; - private ADLFanSpeedValue initialFanSpeedValue; + private bool restoreDefaultFanSpeedRequired = false; + private ADLFanSpeedValue initialFanSpeedValue; public ATIGPU(string name, int adapterIndex, int busNumber, int deviceNumber, ISettings settings) @@ -64,12 +65,6 @@ this.busNumber = busNumber; this.deviceNumber = deviceNumber; - this.initialFanSpeedValue = new ADLFanSpeedValue(); - this.initialFanSpeedValue.SpeedType = - ADL.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT; - ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0, - ref this.initialFanSpeedValue); - this.temperature = new Sensor("GPU Core", 0, SensorType.Temperature, this, settings); this.fan = new Sensor("GPU Fan", 0, SensorType.Fan, this, settings); this.coreClock = new Sensor("GPU Core", 0, SensorType.Clock, this, settings); @@ -96,8 +91,28 @@ 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); + restoreDefaultFanSpeedRequired = false; + } + } + private void SoftwareControlValueChanged(IControl control) { if (control.ControlMode == ControlMode.Software) { + SaveDefaultFanSpeed(); ADLFanSpeedValue adlf = new ADLFanSpeedValue(); adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT; adlf.Flags = ADL.ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED; @@ -108,14 +123,9 @@ private void ControlModeChanged(IControl control) { if (control.ControlMode == ControlMode.Default) { - ADL.ADL_Overdrive5_FanSpeed_Set(adapterIndex, 0, - ref this.initialFanSpeedValue); + RestoreDefaultFanSpeed(); } else { - ADLFanSpeedValue adlf = new ADLFanSpeedValue(); - adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT; - adlf.Flags = ADL.ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED; - adlf.FanSpeed = (int)control.SoftwareValue; - ADL.ADL_Overdrive5_FanSpeed_Set(adapterIndex, 0, ref adlf); + SoftwareControlValueChanged(control); } } @@ -204,8 +214,7 @@ this.fanControl.SoftwareControlValueChanged -= SoftwareControlValueChanged; - ADL.ADL_Overdrive5_FanSpeed_Set(adapterIndex, 0, - ref this.initialFanSpeedValue); + RestoreDefaultFanSpeed(); } } }