Added support for NVIDIA fan rpm. Changed NVIDIA GPU enumeration.
1.1 --- a/Hardware/Nvidia/NVAPI.cs Tue Feb 09 18:55:45 2010 +0000
1.2 +++ b/Hardware/Nvidia/NVAPI.cs Tue Feb 09 19:42:33 2010 +0000
1.3 @@ -174,6 +174,8 @@
1.4 out int gpuCount);
1.5 public delegate NvStatus NvAPI_EnumPhysicalGPUsDelegate(
1.6 [Out] NvPhysicalGpuHandle[] gpuHandles, out int gpuCount);
1.7 + public delegate NvStatus NvAPI_GPU_GetTachReadingDelegate(
1.8 + NvPhysicalGpuHandle gpuHandle, out int value);
1.9
1.10 private static bool available = false;
1.11 private static nvapi_QueryInterfaceDelegate nvapi_QueryInterface;
1.12 @@ -188,6 +190,8 @@
1.13 NvAPI_GetPhysicalGPUsFromDisplay;
1.14 public static NvAPI_EnumPhysicalGPUsDelegate
1.15 NvAPI_EnumPhysicalGPUs;
1.16 + public static NvAPI_GPU_GetTachReadingDelegate
1.17 + NvAPI_GPU_GetTachReading;
1.18
1.19 public static NvStatus NvAPI_GPU_GetFullName(NvPhysicalGpuHandle gpuHandle,
1.20 out string name) {
1.21 @@ -209,7 +213,12 @@
1.22 where T : class
1.23 {
1.24 IntPtr ptr = nvapi_QueryInterface(id);
1.25 - newDelegate = Marshal.GetDelegateForFunctionPointer(ptr, typeof(T)) as T;
1.26 + if (ptr != IntPtr.Zero) {
1.27 + newDelegate =
1.28 + Marshal.GetDelegateForFunctionPointer(ptr, typeof(T)) as T;
1.29 + } else {
1.30 + newDelegate = null;
1.31 + }
1.32 }
1.33
1.34 static NVAPI() {
1.35 @@ -231,6 +240,7 @@
1.36 GetDelegate(0x9ABDD40D, out NvAPI_EnumNvidiaDisplayHandle);
1.37 GetDelegate(0x34EF9506, out NvAPI_GetPhysicalGPUsFromDisplay);
1.38 GetDelegate(0xE5AC921F, out NvAPI_EnumPhysicalGPUs);
1.39 + GetDelegate(0x5F608315, out NvAPI_GPU_GetTachReading);
1.40 available = true;
1.41 }
1.42 }
2.1 --- a/Hardware/Nvidia/NvidiaGPU.cs Tue Feb 09 18:55:45 2010 +0000
2.2 +++ b/Hardware/Nvidia/NvidiaGPU.cs Tue Feb 09 19:42:33 2010 +0000
2.3 @@ -40,7 +40,7 @@
2.4 using System.Drawing;
2.5
2.6 namespace OpenHardwareMonitor.Hardware.Nvidia {
2.7 - public class NvidiaGPU : IHardware {
2.8 + public class NvidiaGPU : Hardware, IHardware {
2.9
2.10 private string name;
2.11 private Image icon;
2.12 @@ -48,12 +48,18 @@
2.13 private NvPhysicalGpuHandle handle;
2.14
2.15 private Sensor[] temperatures;
2.16 + private Sensor fan = null;
2.17 +
2.18 + private bool available;
2.19
2.20 public NvidiaGPU(int adapterIndex, NvPhysicalGpuHandle handle) {
2.21 try {
2.22 string gpuName;
2.23 - NVAPI.NvAPI_GPU_GetFullName(handle, out gpuName);
2.24 - this.name = "NVIDIA " + gpuName;
2.25 + if (NVAPI.NvAPI_GPU_GetFullName(handle, out gpuName) == NvStatus.OK) {
2.26 + this.name = "NVIDIA " + gpuName.Trim();
2.27 + } else {
2.28 + this.name = "NVIDIA";
2.29 + }
2.30 this.icon = Utilities.EmbeddedResources.GetImage("nvidia.png");
2.31 this.adapterIndex = adapterIndex;
2.32 this.handle = handle;
2.33 @@ -73,12 +79,28 @@
2.34 }
2.35 temperatures[i] = new Sensor(name, i, sensor.DefaultMaxTemp,
2.36 SensorType.Temperature, this);
2.37 + ActivateSensor(temperatures[i]);
2.38 }
2.39 +
2.40 + int value;
2.41 + if (NVAPI.NvAPI_GPU_GetTachReading != null &&
2.42 + NVAPI.NvAPI_GPU_GetTachReading(handle, out value) == NvStatus.OK) {
2.43 + if (value > 0) {
2.44 + fan = new Sensor("GPU", 0, SensorType.Fan, this);
2.45 + ActivateSensor(fan);
2.46 + }
2.47 + }
2.48 +
2.49 + available = temperatures.Length > 0 || fan != null;
2.50 } catch (Exception e) {
2.51 System.Windows.Forms.MessageBox.Show(e.Message + "\n" + e.StackTrace);
2.52 }
2.53 }
2.54
2.55 + public bool IsAvailable {
2.56 + get { return available; }
2.57 + }
2.58 +
2.59 public string Name {
2.60 get { return name; }
2.61 }
2.62 @@ -91,12 +113,6 @@
2.63 get { return icon; }
2.64 }
2.65
2.66 - public ISensor[] Sensors {
2.67 - get {
2.68 - return temperatures;
2.69 - }
2.70 - }
2.71 -
2.72 public string GetReport() {
2.73 return null;
2.74 }
2.75 @@ -106,21 +122,23 @@
2.76 settings.Version = NVAPI.GPU_THERMAL_SETTINGS_VER;
2.77 settings.Count = NVAPI.MAX_THERMAL_SENSORS_PER_GPU;
2.78 settings.Sensor = new NvSensor[NVAPI.MAX_THERMAL_SENSORS_PER_GPU];
2.79 - NVAPI.NvAPI_GPU_GetThermalSettings(handle, (int)NvThermalTarget.ALL,
2.80 - ref settings);
2.81 + if (NVAPI.NvAPI_GPU_GetThermalSettings(handle, (int)NvThermalTarget.ALL,
2.82 + ref settings) != NvStatus.OK) {
2.83 + settings.Count = 0;
2.84 + }
2.85 return settings;
2.86 }
2.87
2.88 public void Update() {
2.89 NvGPUThermalSettings settings = GetThermalSettings();
2.90 foreach (Sensor sensor in temperatures)
2.91 - sensor.Value = settings.Sensor[sensor.Index].CurrentTemp;
2.92 + sensor.Value = settings.Sensor[sensor.Index].CurrentTemp;
2.93 +
2.94 + if (fan != null) {
2.95 + int value = 0;
2.96 + NVAPI.NvAPI_GPU_GetTachReading(handle, out value);
2.97 + fan.Value = value;
2.98 + }
2.99 }
2.100 -
2.101 - #pragma warning disable 67
2.102 - public event SensorEventHandler SensorAdded;
2.103 - public event SensorEventHandler SensorRemoved;
2.104 - #pragma warning restore 67
2.105 -
2.106 }
2.107 }
3.1 --- a/Hardware/Nvidia/NvidiaGroup.cs Tue Feb 09 18:55:45 2010 +0000
3.2 +++ b/Hardware/Nvidia/NvidiaGroup.cs Tue Feb 09 19:42:33 2010 +0000
3.3 @@ -65,10 +65,9 @@
3.4 report.AppendLine();
3.5
3.6 for (int i = 0; i < count; i++) {
3.7 - string gpuName;
3.8 - NVAPI.NvAPI_GPU_GetFullName(handles[i], out gpuName);
3.9 - if (gpuName != null && gpuName.Trim() != "")
3.10 - hardware.Add(new NvidiaGPU(i, handles[i]));
3.11 + NvidiaGPU gpu = new NvidiaGPU(i, handles[i]);
3.12 + if (gpu.IsAvailable)
3.13 + hardware.Add(gpu);
3.14 }
3.15 }
3.16
4.1 --- a/Properties/AssemblyInfo.cs Tue Feb 09 18:55:45 2010 +0000
4.2 +++ b/Properties/AssemblyInfo.cs Tue Feb 09 19:42:33 2010 +0000
4.3 @@ -69,5 +69,5 @@
4.4 // You can specify all the values or you can default the Build and Revision Numbers
4.5 // by using the '*' as shown below:
4.6 // [assembly: AssemblyVersion("1.0.*")]
4.7 -[assembly: AssemblyVersion("0.1.16.0")]
4.8 -[assembly: AssemblyFileVersion("0.1.16.0")]
4.9 +[assembly: AssemblyVersion("0.1.17.0")]
4.10 +[assembly: AssemblyFileVersion("0.1.17.0")]