mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
feat: added GPU temperature indication. Supports both NVIDIA and AMD discrete GPUs
feat: immediately update sensors when opening GHelper window
This commit is contained in:
44
Gpu/NvidiaGpuTemperatureProvider.cs
Normal file
44
Gpu/NvidiaGpuTemperatureProvider.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using NvAPIWrapper.GPU;
|
||||
using NvAPIWrapper.Native;
|
||||
using NvAPIWrapper.Native.Exceptions;
|
||||
using NvAPIWrapper.Native.GPU;
|
||||
using NvAPIWrapper.Native.Interfaces.GPU;
|
||||
|
||||
namespace GHelper.Gpu;
|
||||
|
||||
public class NvidiaGpuTemperatureProvider : IGpuTemperatureProvider {
|
||||
private readonly PhysicalGPU? _internalGpu;
|
||||
|
||||
public NvidiaGpuTemperatureProvider() {
|
||||
_internalGpu = GetInternalDiscreteGpu();
|
||||
}
|
||||
|
||||
public bool IsValid => _internalGpu != null;
|
||||
|
||||
public int? GetCurrentTemperature() {
|
||||
if (!IsValid)
|
||||
return null;
|
||||
|
||||
IThermalSensor? gpuSensor =
|
||||
GPUApi.GetThermalSettings(_internalGpu!.Handle).Sensors
|
||||
.FirstOrDefault(s => s.Target == ThermalSettingsTarget.GPU);
|
||||
|
||||
if (gpuSensor == null)
|
||||
return null;
|
||||
|
||||
return gpuSensor.CurrentTemperature;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
}
|
||||
|
||||
private static PhysicalGPU? GetInternalDiscreteGpu() {
|
||||
try {
|
||||
return PhysicalGPU
|
||||
.GetPhysicalGPUs()
|
||||
.FirstOrDefault(gpu => gpu.SystemType == SystemType.Laptop);
|
||||
} catch (NVIDIAApiException) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user