Hardware/ATI/ATIGPU.cs
author moel.mich
Thu, 11 Nov 2010 21:22:24 +0000
changeset 241 52007c404f32
parent 182 4801e9eaf979
child 247 6dc755f1970e
permissions -rw-r--r--
Fixed a problem, where the MainForm location and size was lost when the application is started minimized and exited without ever showing the form. This caused MainForm_Load to be never called (location and size was not loaded), but the default size and location were still saved. The new implementation only saves the location and size when one of the two is changed.
     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.Globalization;
    40 
    41 namespace OpenHardwareMonitor.Hardware.ATI {
    42   internal sealed class ATIGPU : Hardware {
    43 
    44     private readonly string name;
    45     private readonly int adapterIndex;
    46     private readonly int busNumber;
    47     private readonly int deviceNumber;
    48     private readonly Sensor temperature;
    49     private readonly Sensor fan;
    50     private readonly Sensor coreClock;
    51     private readonly Sensor memoryClock;
    52     private readonly Sensor coreVoltage;
    53     private readonly Sensor coreLoad;
    54     private readonly Sensor fanControl;
    55 
    56     public ATIGPU(string name, int adapterIndex, int busNumber, 
    57       int deviceNumber, ISettings settings) 
    58     {
    59       this.name = name;
    60       this.adapterIndex = adapterIndex;
    61       this.busNumber = busNumber;
    62       this.deviceNumber = deviceNumber;
    63 
    64       this.temperature = new Sensor("GPU Core", 0, SensorType.Temperature, this, settings);
    65       this.fan = new Sensor("GPU Fan", 0, SensorType.Fan, this, settings);
    66       this.coreClock = new Sensor("GPU Core", 0, SensorType.Clock, this, settings);
    67       this.memoryClock = new Sensor("GPU Memory", 1, SensorType.Clock, this, settings);
    68       this.coreVoltage = new Sensor("GPU Core", 0, SensorType.Voltage, this, settings);
    69       this.coreLoad = new Sensor("GPU Core", 0, SensorType.Load, this, settings);
    70       this.fanControl = new Sensor("GPU Fan", 0, SensorType.Control, this, settings);
    71       Update();                   
    72     }
    73 
    74     public int BusNumber { get { return busNumber; } }
    75 
    76     public int DeviceNumber { get { return deviceNumber; } }
    77 
    78     public override string Name {
    79       get { return name; }
    80     }
    81 
    82     public override Identifier Identifier {
    83       get { 
    84         return new Identifier("atigpu", 
    85           adapterIndex.ToString(CultureInfo.InvariantCulture)); 
    86       }
    87     }
    88 
    89     public override HardwareType HardwareType {
    90       get { return HardwareType.GpuAti; }
    91     }
    92 
    93     public override void Update() {
    94       ADLTemperature adlt = new ADLTemperature();
    95       if (ADL.ADL_Overdrive5_Temperature_Get(adapterIndex, 0, ref adlt)
    96         == ADL.ADL_OK) 
    97       {
    98         temperature.Value = 0.001f * adlt.Temperature;
    99         ActivateSensor(temperature);
   100       } else {
   101         temperature.Value = null;
   102       }
   103 
   104       ADLFanSpeedValue adlf = new ADLFanSpeedValue();
   105       adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_RPM;
   106       if (ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0, ref adlf)
   107         == ADL.ADL_OK) 
   108       {
   109         fan.Value = adlf.FanSpeed;
   110         ActivateSensor(fan);
   111       } else {
   112         fan.Value = null;
   113       }
   114 
   115       adlf = new ADLFanSpeedValue();
   116       adlf.SpeedType = ADL.ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
   117       if (ADL.ADL_Overdrive5_FanSpeed_Get(adapterIndex, 0, ref adlf)
   118         == ADL.ADL_OK) {
   119         fanControl.Value = adlf.FanSpeed;
   120         ActivateSensor(fanControl);
   121       } else {
   122         fanControl.Value = null;
   123       }
   124 
   125       ADLPMActivity adlp = new ADLPMActivity();
   126       if (ADL.ADL_Overdrive5_CurrentActivity_Get(adapterIndex, ref adlp)
   127         == ADL.ADL_OK) 
   128       {
   129         if (adlp.EngineClock > 0) {
   130           coreClock.Value = 0.01f * adlp.EngineClock;
   131           ActivateSensor(coreClock);
   132         }
   133 
   134         if (adlp.MemoryClock > 0) {
   135           memoryClock.Value = 0.01f * adlp.MemoryClock;
   136           ActivateSensor(memoryClock);
   137         }
   138 
   139         if (adlp.Vddc > 0) {
   140           coreVoltage.Value = 0.001f * adlp.Vddc;
   141           ActivateSensor(coreVoltage);
   142         }
   143 
   144         coreLoad.Value = Math.Min(adlp.ActivityPercent, 100);                        
   145         ActivateSensor(coreLoad);
   146       } else {
   147         coreClock.Value = null;
   148         memoryClock.Value = null;
   149         coreVoltage.Value = null;
   150         coreLoad.Value = null;
   151       }
   152     }
   153   }
   154 }