Fixed Issue 651.
3 This Source Code Form is subject to the terms of the Mozilla Public
4 License, v. 2.0. If a copy of the MPL was not distributed with this
5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 Copyright (C) 2009-2014 Michael Möller <mmoeller@openhardwaremonitor.org>
12 using System.Globalization;
14 namespace OpenHardwareMonitor.Hardware.ATI {
15 internal sealed class ATIGPU : Hardware {
17 private readonly int adapterIndex;
18 private readonly int busNumber;
19 private readonly int deviceNumber;
20 private readonly Sensor temperature;
21 private readonly Sensor fan;
22 private readonly Sensor coreClock;
23 private readonly Sensor memoryClock;
24 private readonly Sensor coreVoltage;
25 private readonly Sensor coreLoad;
26 private readonly Sensor controlSensor;
27 private readonly Control fanControl;
29 public ATIGPU(string name, int adapterIndex, int busNumber,
30 int deviceNumber, ISettings settings)
31 : base(name, new Identifier("atigpu",
32 adapterIndex.ToString(CultureInfo.InvariantCulture)), settings)
34 this.adapterIndex = adapterIndex;
35 this.busNumber = busNumber;
36 this.deviceNumber = deviceNumber;
38 this.temperature = new Sensor("GPU Core", 0, SensorType.Temperature, this, settings);
39 this.fan = new Sensor("GPU Fan", 0, SensorType.Fan, this, settings);
40 this.coreClock = new Sensor("GPU Core", 0, SensorType.Clock, this, settings);
41 this.memoryClock = new Sensor("GPU Memory", 1, SensorType.Clock, this, settings);
42 this.coreVoltage = new Sensor("GPU Core", 0, SensorType.Voltage, this, settings);
43 this.coreLoad = new Sensor("GPU Core", 0, SensorType.Load, this, settings);
44 this.controlSensor = new Sensor("GPU Fan", 0, SensorType.Control, this, settings);
46 ADLFanSpeedInfo afsi = new ADLFanSpeedInfo();
47 if (ADL.ADL_Overdrive5_FanSpeedInfo_Get(adapterIndex, 0, ref afsi)
50 afsi.MaxPercent = 100;
54 this.fanControl = new Control(controlSensor, settings, afsi.MinPercent,
56 this.fanControl.ControlModeChanged += ControlModeChanged;
57 this.fanControl.SoftwareControlValueChanged +=
58 SoftwareControlValueChanged;
59 ControlModeChanged(fanControl);
60 this.controlSensor.Control = fanControl;
64 private void SoftwareControlValueChanged(IControl control) {
65 if (control.ControlMode == ControlMode.Software) {
66 ADLFanSpeedValue adlf = new ADLFanSpeedValue();
67 adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
68 adlf.Flags = ADL.ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED;
69 adlf.FanSpeed = (int)control.SoftwareValue;
70 ADL.ADL_Overdrive5_FanSpeed_Set(adapterIndex, 0, ref adlf);
74 private void ControlModeChanged(IControl control) {
75 switch (control.ControlMode) {
76 case ControlMode.Undefined:
78 case ControlMode.Default:
81 case ControlMode.Software:
82 SoftwareControlValueChanged(control);
89 private void SetDefaultFanSpeed() {
90 ADL.ADL_Overdrive5_FanSpeedToDefault_Set(adapterIndex, 0);
93 public int BusNumber { get { return busNumber; } }
95 public int DeviceNumber { get { return deviceNumber; } }
98 public override HardwareType HardwareType {
99 get { return HardwareType.GpuAti; }
102 public override void Update() {
103 ADLTemperature adlt = new ADLTemperature();
104 if (ADL.ADL_Overdrive5_Temperature_Get(adapterIndex, 0, ref adlt)
107 temperature.Value = 0.001f * adlt.Temperature;
108 ActivateSensor(temperature);
110 temperature.Value = null;
113 ADLFanSpeedValue adlf = new ADLFanSpeedValue();
114 adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_RPM;
115 if (ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0, ref adlf)
118 fan.Value = adlf.FanSpeed;
124 adlf = new ADLFanSpeedValue();
125 adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
126 if (ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0, ref adlf)
128 controlSensor.Value = adlf.FanSpeed;
129 ActivateSensor(controlSensor);
131 controlSensor.Value = null;
134 ADLPMActivity adlp = new ADLPMActivity();
135 if (ADL.ADL_Overdrive5_CurrentActivity_Get(adapterIndex, ref adlp)
138 if (adlp.EngineClock > 0) {
139 coreClock.Value = 0.01f * adlp.EngineClock;
140 ActivateSensor(coreClock);
142 coreClock.Value = null;
145 if (adlp.MemoryClock > 0) {
146 memoryClock.Value = 0.01f * adlp.MemoryClock;
147 ActivateSensor(memoryClock);
149 memoryClock.Value = null;
153 coreVoltage.Value = 0.001f * adlp.Vddc;
154 ActivateSensor(coreVoltage);
156 coreVoltage.Value = null;
159 coreLoad.Value = Math.Min(adlp.ActivityPercent, 100);
160 ActivateSensor(coreLoad);
162 coreClock.Value = null;
163 memoryClock.Value = null;
164 coreVoltage.Value = null;
165 coreLoad.Value = null;
169 public override void Close() {
170 this.fanControl.ControlModeChanged -= ControlModeChanged;
171 this.fanControl.SoftwareControlValueChanged -=
172 SoftwareControlValueChanged;
174 if (this.fanControl.ControlMode != ControlMode.Undefined)
175 SetDefaultFanSpeed();