Converted project to VisualStudio 2012.
Adding SoundGraphDisplay and SensorFrontView classes.
They were respectively based on SystemTray and SensorNotifyIcon.
SoundGraphDisplay is now able to load iMONDisplay.dll providing it lives on your PATH.
Adding option to sensor context menu for adding it into FrontView.
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-2011 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 private bool restoreDefaultFanSpeedRequired = false;
30 private ADLFanSpeedValue initialFanSpeedValue;
32 public ATIGPU(string name, int adapterIndex, int busNumber,
33 int deviceNumber, ISettings settings)
34 : base(name, new Identifier("atigpu",
35 adapterIndex.ToString(CultureInfo.InvariantCulture)), settings)
37 this.adapterIndex = adapterIndex;
38 this.busNumber = busNumber;
39 this.deviceNumber = deviceNumber;
41 this.temperature = new Sensor("GPU Core", 0, SensorType.Temperature, this, settings);
42 this.fan = new Sensor("GPU Fan", 0, SensorType.Fan, this, settings);
43 this.coreClock = new Sensor("GPU Core", 0, SensorType.Clock, this, settings);
44 this.memoryClock = new Sensor("GPU Memory", 1, SensorType.Clock, this, settings);
45 this.coreVoltage = new Sensor("GPU Core", 0, SensorType.Voltage, this, settings);
46 this.coreLoad = new Sensor("GPU Core", 0, SensorType.Load, this, settings);
47 this.controlSensor = new Sensor("GPU Fan", 0, SensorType.Control, this, settings);
49 ADLFanSpeedInfo afsi = new ADLFanSpeedInfo();
50 if (ADL.ADL_Overdrive5_FanSpeedInfo_Get(adapterIndex, 0, ref afsi)
53 afsi.MaxPercent = 100;
57 this.fanControl = new Control(controlSensor, settings, afsi.MinPercent,
59 this.fanControl.ControlModeChanged += ControlModeChanged;
60 this.fanControl.SoftwareControlValueChanged +=
61 SoftwareControlValueChanged;
62 ControlModeChanged(fanControl);
63 this.controlSensor.Control = fanControl;
67 private void SaveDefaultFanSpeed() {
68 if (!restoreDefaultFanSpeedRequired) {
69 initialFanSpeedValue = new ADLFanSpeedValue();
70 initialFanSpeedValue.SpeedType =
71 ADL.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
72 restoreDefaultFanSpeedRequired =
73 ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0,
74 ref initialFanSpeedValue) == ADL.ADL_OK;
78 private void RestoreDefaultFanSpeed() {
79 if (restoreDefaultFanSpeedRequired) {
80 ADL.ADL_Overdrive5_FanSpeed_Set(adapterIndex, 0,
81 ref this.initialFanSpeedValue);
82 if ((initialFanSpeedValue.Flags &
83 ADL.ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED) == 0)
84 ADL.ADL_Overdrive5_FanSpeedToDefault_Set(adapterIndex, 0);
85 restoreDefaultFanSpeedRequired = false;
89 private void SoftwareControlValueChanged(IControl control) {
90 if (control.ControlMode == ControlMode.Software) {
91 SaveDefaultFanSpeed();
92 ADLFanSpeedValue adlf = new ADLFanSpeedValue();
93 adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
94 adlf.Flags = ADL.ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED;
95 adlf.FanSpeed = (int)control.SoftwareValue;
96 ADL.ADL_Overdrive5_FanSpeed_Set(adapterIndex, 0, ref adlf);
100 private void ControlModeChanged(IControl control) {
101 if (control.ControlMode == ControlMode.Default) {
102 RestoreDefaultFanSpeed();
104 SoftwareControlValueChanged(control);
108 public int BusNumber { get { return busNumber; } }
110 public int DeviceNumber { get { return deviceNumber; } }
113 public override HardwareType HardwareType {
114 get { return HardwareType.GpuAti; }
117 public override void Update() {
118 ADLTemperature adlt = new ADLTemperature();
119 if (ADL.ADL_Overdrive5_Temperature_Get(adapterIndex, 0, ref adlt)
122 temperature.Value = 0.001f * adlt.Temperature;
123 ActivateSensor(temperature);
125 temperature.Value = null;
128 ADLFanSpeedValue adlf = new ADLFanSpeedValue();
129 adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_RPM;
130 if (ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0, ref adlf)
133 fan.Value = adlf.FanSpeed;
139 adlf = new ADLFanSpeedValue();
140 adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
141 if (ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0, ref adlf)
143 controlSensor.Value = adlf.FanSpeed;
144 ActivateSensor(controlSensor);
146 controlSensor.Value = null;
149 ADLPMActivity adlp = new ADLPMActivity();
150 if (ADL.ADL_Overdrive5_CurrentActivity_Get(adapterIndex, ref adlp)
153 if (adlp.EngineClock > 0) {
154 coreClock.Value = 0.01f * adlp.EngineClock;
155 ActivateSensor(coreClock);
157 coreClock.Value = null;
160 if (adlp.MemoryClock > 0) {
161 memoryClock.Value = 0.01f * adlp.MemoryClock;
162 ActivateSensor(memoryClock);
164 memoryClock.Value = null;
168 coreVoltage.Value = 0.001f * adlp.Vddc;
169 ActivateSensor(coreVoltage);
171 coreVoltage.Value = null;
174 coreLoad.Value = Math.Min(adlp.ActivityPercent, 100);
175 ActivateSensor(coreLoad);
177 coreClock.Value = null;
178 memoryClock.Value = null;
179 coreVoltage.Value = null;
180 coreLoad.Value = null;
184 public override void Close() {
185 this.fanControl.ControlModeChanged -= ControlModeChanged;
186 this.fanControl.SoftwareControlValueChanged -=
187 SoftwareControlValueChanged;
189 RestoreDefaultFanSpeed();