Hardware/ATI/ATIGPU.cs
author moel.mich
Thu, 06 May 2010 19:20:38 +0000
changeset 109 70d0c3102424
parent 80 129a9a1d514f
child 110 411b72b73d8f
permissions -rw-r--r--
Added an Identifier class for IHardware, ISensor and IParameter Identifier properties.
     1 /*
     2   
     3   Version: MPL 1.1/GPL 2.0/LGPL 2.1
     4 
     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
     8  
     9   http://www.mozilla.org/MPL/
    10 
    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.
    14 
    15   The Original Code is the Open Hardware Monitor code.
    16 
    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-2010
    20   the Initial Developer. All Rights Reserved.
    21 
    22   Contributor(s):
    23 
    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.
    35  
    36 */
    37 
    38 using System;
    39 using System.Collections.Generic;
    40 using System.Drawing;
    41 using System.Reflection;
    42 
    43 namespace OpenHardwareMonitor.Hardware.ATI {
    44   public class ATIGPU : Hardware, IHardware {
    45 
    46     private string name;
    47     private Image icon;
    48     private int adapterIndex;
    49     private int busNumber;
    50     private int deviceNumber;
    51     private Sensor temperature;
    52     private Sensor fan;
    53     private Sensor coreClock;
    54     private Sensor memoryClock;
    55     private Sensor coreVoltage;
    56     private Sensor coreLoad;
    57 
    58     public ATIGPU(string name, int adapterIndex, int busNumber, 
    59       int deviceNumber) 
    60     {
    61       this.name = name;
    62       this.icon = Utilities.EmbeddedResources.GetImage("ati.png");
    63       this.adapterIndex = adapterIndex;
    64       this.busNumber = busNumber;
    65       this.deviceNumber = deviceNumber;
    66 
    67       ADLFanSpeedInfo speedInfo = new ADLFanSpeedInfo();
    68       ADL.ADL_Overdrive5_FanSpeedInfo_Get(adapterIndex, 0, ref speedInfo);
    69 
    70       this.temperature = 
    71         new Sensor("GPU Core", 0, SensorType.Temperature, this);
    72       this.fan = new Sensor("GPU", 0, speedInfo.MaxRPM, SensorType.Fan, this,
    73         null);
    74       this.coreClock = new Sensor("GPU Core", 0, SensorType.Clock, this);
    75       this.memoryClock = new Sensor("GPU Memory", 1, SensorType.Clock, this);
    76       this.coreVoltage = new Sensor("GPU Core", 0, SensorType.Voltage, this);
    77       this.coreLoad = new Sensor("GPU Core", 0, SensorType.Load, this);
    78       Update();                   
    79     }
    80 
    81     public int BusNumber { get { return busNumber; } }
    82 
    83     public int DeviceNumber { get { return deviceNumber; } }
    84 
    85     public string Name {
    86       get { return name; }
    87     }
    88 
    89     public Identifier Identifier {
    90       get { return new Identifier("atigpu", adapterIndex.ToString()); }
    91     }
    92 
    93     public Image Icon {
    94       get { return icon; }
    95     }
    96 
    97     public string GetReport() {
    98       return null;
    99     }
   100 
   101     public void Update() {
   102       ADLTemperature adlt = new ADLTemperature();
   103       if (ADL.ADL_Overdrive5_Temperature_Get(adapterIndex, 0, ref adlt)
   104         == ADL.ADL_OK) 
   105       {
   106         temperature.Value = 0.001f * adlt.Temperature;
   107         ActivateSensor(temperature);
   108       } else {
   109         DeactivateSensor(temperature);
   110       }
   111 
   112       ADLFanSpeedValue adlf = new ADLFanSpeedValue();
   113       adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_RPM;
   114       if (ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0, ref adlf)
   115         == ADL.ADL_OK) 
   116       {
   117         fan.Value = adlf.FanSpeed;
   118         ActivateSensor(fan);
   119       } else {
   120         DeactivateSensor(fan);
   121       }
   122 
   123       ADLPMActivity adlp = new ADLPMActivity();
   124       if (ADL.ADL_Overdrive5_CurrentActivity_Get(adapterIndex, ref adlp)
   125         == ADL.ADL_OK) 
   126       {
   127         if (adlp.EngineClock > 0) {
   128           coreClock.Value = 0.01f * adlp.EngineClock;
   129           ActivateSensor(coreClock);
   130         }
   131 
   132         if (adlp.MemoryClock > 0) {
   133           memoryClock.Value = 0.01f * adlp.MemoryClock;
   134           ActivateSensor(memoryClock);
   135         }
   136 
   137         if (adlp.Vddc > 0) {
   138           coreVoltage.Value = 0.001f * adlp.Vddc;
   139           ActivateSensor(coreVoltage);
   140         }
   141 
   142         coreLoad.Value = adlp.ActivityPercent;                        
   143         ActivateSensor(coreLoad);
   144       } else {
   145         DeactivateSensor(coreClock);
   146         DeactivateSensor(memoryClock);
   147         DeactivateSensor(coreVoltage);
   148         DeactivateSensor(coreLoad);
   149       }
   150     }
   151   }
   152 }