Added support for saving and restoring the sensor history for the last 24h. The sensor history is now saved in a reduced format (duplicate values are removed, gaps are marked with a NAN sensor value.
3 Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 The contents of this file are subject to the Mozilla Public License Version
6 1.1 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.mozilla.org/MPL/
11 Software distributed under the License is distributed on an "AS IS" basis,
12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 for the specific language governing rights and limitations under the License.
15 The Original Code is the Open Hardware Monitor code.
17 The Initial Developer of the Original Code is
18 Michael Möller <m.moeller@gmx.ch>.
19 Portions created by the Initial Developer are Copyright (C) 2009-2011
20 the Initial Developer. All Rights Reserved.
24 Alternatively, the contents of this file may be used under the terms of
25 either the GNU General Public License Version 2 or later (the "GPL"), or
26 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 in which case the provisions of the GPL or the LGPL are applicable instead
28 of those above. If you wish to allow use of your version of this file only
29 under the terms of either the GPL or the LGPL, and not to allow others to
30 use your version of this file under the terms of the MPL, indicate your
31 decision by deleting the provisions above and replace them with the notice
32 and other provisions required by the GPL or the LGPL. If you do not delete
33 the provisions above, a recipient may use your version of this file under
34 the terms of any one of the MPL, the GPL or the LGPL.
39 using System.Globalization;
41 namespace OpenHardwareMonitor.Hardware.ATI {
42 internal sealed class ATIGPU : Hardware {
44 private readonly int adapterIndex;
45 private readonly int busNumber;
46 private readonly int deviceNumber;
47 private readonly Sensor temperature;
48 private readonly Sensor fan;
49 private readonly Sensor coreClock;
50 private readonly Sensor memoryClock;
51 private readonly Sensor coreVoltage;
52 private readonly Sensor coreLoad;
53 private readonly Sensor controlSensor;
54 private readonly Control fanControl;
56 private bool restoreDefaultFanSpeedRequired = false;
57 private ADLFanSpeedValue initialFanSpeedValue;
59 public ATIGPU(string name, int adapterIndex, int busNumber,
60 int deviceNumber, ISettings settings)
61 : base(name, new Identifier("atigpu",
62 adapterIndex.ToString(CultureInfo.InvariantCulture)), settings)
64 this.adapterIndex = adapterIndex;
65 this.busNumber = busNumber;
66 this.deviceNumber = deviceNumber;
68 this.temperature = new Sensor("GPU Core", 0, SensorType.Temperature, this, settings);
69 this.fan = new Sensor("GPU Fan", 0, SensorType.Fan, this, settings);
70 this.coreClock = new Sensor("GPU Core", 0, SensorType.Clock, this, settings);
71 this.memoryClock = new Sensor("GPU Memory", 1, SensorType.Clock, this, settings);
72 this.coreVoltage = new Sensor("GPU Core", 0, SensorType.Voltage, this, settings);
73 this.coreLoad = new Sensor("GPU Core", 0, SensorType.Load, this, settings);
74 this.controlSensor = new Sensor("GPU Fan", 0, SensorType.Control, this, settings);
76 ADLFanSpeedInfo afsi = new ADLFanSpeedInfo();
77 if (ADL.ADL_Overdrive5_FanSpeedInfo_Get(adapterIndex, 0, ref afsi)
80 afsi.MaxPercent = 100;
84 this.fanControl = new Control(controlSensor, settings, afsi.MinPercent,
86 this.fanControl.ControlModeChanged += ControlModeChanged;
87 this.fanControl.SoftwareControlValueChanged +=
88 SoftwareControlValueChanged;
89 ControlModeChanged(fanControl);
90 this.controlSensor.Control = fanControl;
94 private void SaveDefaultFanSpeed() {
95 if (!restoreDefaultFanSpeedRequired) {
96 initialFanSpeedValue = new ADLFanSpeedValue();
97 initialFanSpeedValue.SpeedType =
98 ADL.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
99 restoreDefaultFanSpeedRequired =
100 ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0,
101 ref initialFanSpeedValue) == ADL.ADL_OK;
105 private void RestoreDefaultFanSpeed() {
106 if (restoreDefaultFanSpeedRequired) {
107 ADL.ADL_Overdrive5_FanSpeed_Set(adapterIndex, 0,
108 ref this.initialFanSpeedValue);
109 if ((initialFanSpeedValue.Flags &
110 ADL.ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED) == 0)
111 ADL.ADL_Overdrive5_FanSpeedToDefault_Set(adapterIndex, 0);
112 restoreDefaultFanSpeedRequired = false;
116 private void SoftwareControlValueChanged(IControl control) {
117 if (control.ControlMode == ControlMode.Software) {
118 SaveDefaultFanSpeed();
119 ADLFanSpeedValue adlf = new ADLFanSpeedValue();
120 adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
121 adlf.Flags = ADL.ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED;
122 adlf.FanSpeed = (int)control.SoftwareValue;
123 ADL.ADL_Overdrive5_FanSpeed_Set(adapterIndex, 0, ref adlf);
127 private void ControlModeChanged(IControl control) {
128 if (control.ControlMode == ControlMode.Default) {
129 RestoreDefaultFanSpeed();
131 SoftwareControlValueChanged(control);
135 public int BusNumber { get { return busNumber; } }
137 public int DeviceNumber { get { return deviceNumber; } }
140 public override HardwareType HardwareType {
141 get { return HardwareType.GpuAti; }
144 public override void Update() {
145 ADLTemperature adlt = new ADLTemperature();
146 if (ADL.ADL_Overdrive5_Temperature_Get(adapterIndex, 0, ref adlt)
149 temperature.Value = 0.001f * adlt.Temperature;
150 ActivateSensor(temperature);
152 temperature.Value = null;
155 ADLFanSpeedValue adlf = new ADLFanSpeedValue();
156 adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_RPM;
157 if (ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0, ref adlf)
160 fan.Value = adlf.FanSpeed;
166 adlf = new ADLFanSpeedValue();
167 adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
168 if (ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0, ref adlf)
170 controlSensor.Value = adlf.FanSpeed;
171 ActivateSensor(controlSensor);
173 controlSensor.Value = null;
176 ADLPMActivity adlp = new ADLPMActivity();
177 if (ADL.ADL_Overdrive5_CurrentActivity_Get(adapterIndex, ref adlp)
180 if (adlp.EngineClock > 0) {
181 coreClock.Value = 0.01f * adlp.EngineClock;
182 ActivateSensor(coreClock);
184 coreClock.Value = null;
187 if (adlp.MemoryClock > 0) {
188 memoryClock.Value = 0.01f * adlp.MemoryClock;
189 ActivateSensor(memoryClock);
191 memoryClock.Value = null;
195 coreVoltage.Value = 0.001f * adlp.Vddc;
196 ActivateSensor(coreVoltage);
198 coreVoltage.Value = null;
201 coreLoad.Value = Math.Min(adlp.ActivityPercent, 100);
202 ActivateSensor(coreLoad);
204 coreClock.Value = null;
205 memoryClock.Value = null;
206 coreVoltage.Value = null;
207 coreLoad.Value = null;
211 public override void Close() {
212 this.fanControl.ControlModeChanged -= ControlModeChanged;
213 this.fanControl.SoftwareControlValueChanged -=
214 SoftwareControlValueChanged;
216 RestoreDefaultFanSpeed();