Hardware/ATI/ATIGPU.cs
author StephaneLenclud
Thu, 18 Apr 2013 23:25:10 +0200
branchMiniDisplay
changeset 444 9b09e2ee0968
parent 344 3145aadca3d2
permissions -rw-r--r--
Front View plug-in does not init if no sensor added.
Fixing some format to make strings shorter.
Now trying to start SoundGraphAccess.exe process from same directory.
Packed mode now can display three sensors along with the current time.
     1 /*
     2  
     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/.
     6  
     7   Copyright (C) 2009-2014 Michael Möller <mmoeller@openhardwaremonitor.org>
     8 	
     9 */
    10 
    11 using System;
    12 using System.Globalization;
    13 
    14 namespace OpenHardwareMonitor.Hardware.ATI {
    15   internal sealed class ATIGPU : Hardware {
    16 
    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;  
    28 
    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)
    33     {
    34       this.adapterIndex = adapterIndex;
    35       this.busNumber = busNumber;
    36       this.deviceNumber = deviceNumber;
    37 
    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);
    45 
    46       ADLFanSpeedInfo afsi = new ADLFanSpeedInfo();
    47       if (ADL.ADL_Overdrive5_FanSpeedInfo_Get(adapterIndex, 0, ref afsi)
    48         != ADL.ADL_OK) 
    49       {
    50         afsi.MaxPercent = 100;
    51         afsi.MinPercent = 0;
    52       }
    53 
    54       this.fanControl = new Control(controlSensor, settings, afsi.MinPercent, 
    55         afsi.MaxPercent);
    56       this.fanControl.ControlModeChanged += ControlModeChanged;
    57       this.fanControl.SoftwareControlValueChanged += 
    58         SoftwareControlValueChanged;
    59       ControlModeChanged(fanControl);
    60       this.controlSensor.Control = fanControl;
    61       Update();                   
    62     }
    63 
    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);
    71       }
    72     }
    73 
    74     private void ControlModeChanged(IControl control) {
    75       switch (control.ControlMode) {
    76         case ControlMode.Undefined:
    77           return;
    78         case ControlMode.Default:
    79           SetDefaultFanSpeed();
    80           break;
    81         case ControlMode.Software:
    82           SoftwareControlValueChanged(control);
    83           break;
    84         default:
    85           return;
    86       }
    87     }
    88 
    89     private void SetDefaultFanSpeed() {
    90       ADL.ADL_Overdrive5_FanSpeedToDefault_Set(adapterIndex, 0);
    91     }
    92 
    93     public int BusNumber { get { return busNumber; } }
    94 
    95     public int DeviceNumber { get { return deviceNumber; } }
    96 
    97 
    98     public override HardwareType HardwareType {
    99       get { return HardwareType.GpuAti; }
   100     }
   101 
   102     public override void Update() {
   103       ADLTemperature adlt = new ADLTemperature();
   104       if (ADL.ADL_Overdrive5_Temperature_Get(adapterIndex, 0, ref adlt)
   105         == ADL.ADL_OK) 
   106       {
   107         temperature.Value = 0.001f * adlt.Temperature;
   108         ActivateSensor(temperature);
   109       } else {
   110         temperature.Value = null;
   111       }
   112 
   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)
   116         == ADL.ADL_OK) 
   117       {
   118         fan.Value = adlf.FanSpeed;
   119         ActivateSensor(fan);
   120       } else {
   121         fan.Value = null;
   122       }
   123 
   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)
   127         == ADL.ADL_OK) {
   128         controlSensor.Value = adlf.FanSpeed;
   129         ActivateSensor(controlSensor);
   130       } else {
   131         controlSensor.Value = null;
   132       }
   133 
   134       ADLPMActivity adlp = new ADLPMActivity();
   135       if (ADL.ADL_Overdrive5_CurrentActivity_Get(adapterIndex, ref adlp)
   136         == ADL.ADL_OK) 
   137       {
   138         if (adlp.EngineClock > 0) {
   139           coreClock.Value = 0.01f * adlp.EngineClock;
   140           ActivateSensor(coreClock);
   141         } else {
   142           coreClock.Value = null;
   143         }
   144 
   145         if (adlp.MemoryClock > 0) {
   146           memoryClock.Value = 0.01f * adlp.MemoryClock;
   147           ActivateSensor(memoryClock);
   148         } else {
   149           memoryClock.Value = null;
   150         }
   151 
   152         if (adlp.Vddc > 0) {
   153           coreVoltage.Value = 0.001f * adlp.Vddc;
   154           ActivateSensor(coreVoltage);
   155         } else {
   156           coreVoltage.Value = null;
   157         }
   158 
   159         coreLoad.Value = Math.Min(adlp.ActivityPercent, 100);                        
   160         ActivateSensor(coreLoad);
   161       } else {
   162         coreClock.Value = null;
   163         memoryClock.Value = null;
   164         coreVoltage.Value = null;
   165         coreLoad.Value = null;
   166       }
   167     }
   168 
   169     public override void Close() {
   170       this.fanControl.ControlModeChanged -= ControlModeChanged;
   171       this.fanControl.SoftwareControlValueChanged -=
   172         SoftwareControlValueChanged;
   173 
   174       if (this.fanControl.ControlMode != ControlMode.Undefined)
   175         SetDefaultFanSpeed();
   176       base.Close();
   177     }
   178   }
   179 }