mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 16:26:39 +01:00
GPU temp detection
This commit is contained in:
+4
-14
@@ -36,18 +36,10 @@ static double detectCPUTemp(const FFinstance* instance)
|
||||
FFTempValue* value = ffListGet(&temps->values, i);
|
||||
|
||||
if(
|
||||
ffStrbufFirstIndexS(&value->name, "cpu") == value->name.length &&
|
||||
ffStrbufCompS(&value->name, "k10temp") != 0 &&
|
||||
ffStrbufCompS(&value->name, "coretemp") != 0
|
||||
) continue;
|
||||
|
||||
double temp = ffStrbufToDouble(&value->value);
|
||||
|
||||
//NaN
|
||||
if(temp != temp)
|
||||
continue;
|
||||
|
||||
return temp / 1000.0; // millidegrees to degrees
|
||||
ffStrbufFirstIndexS(&value->name, "cpu") < value->name.length ||
|
||||
ffStrbufCompS(&value->name, "k10temp") == 0 ||
|
||||
ffStrbufCompS(&value->name, "coretemp") == 0
|
||||
) return value->value;
|
||||
}
|
||||
|
||||
return 0.0 / 0.0; //NaN
|
||||
@@ -170,8 +162,6 @@ void ffPrintCPU(FFinstance* instance)
|
||||
double cpuTemp;
|
||||
if(instance->config.cpu.outputFormat.length > 0)
|
||||
cpuTemp = detectCPUTemp(instance);
|
||||
else
|
||||
cpuTemp = 0.0 / 0.0; //NaN
|
||||
|
||||
FFstrbuf cpu;
|
||||
ffStrbufInitA(&cpu, 128);
|
||||
|
||||
+31
-4
@@ -3,7 +3,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#define FF_GPU_MODULE_NAME "GPU"
|
||||
#define FF_GPU_NUM_FORMAT_ARGS 5
|
||||
#define FF_GPU_NUM_FORMAT_ARGS 6
|
||||
|
||||
static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache, FFGPUResult* result)
|
||||
{
|
||||
@@ -39,6 +39,7 @@ static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache,
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->name},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &namePretty},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->driver},
|
||||
{FF_FORMAT_ARG_TYPE_DOUBLE, &result->temperature}
|
||||
});
|
||||
|
||||
ffStrbufDestroy(&result->vendor);
|
||||
@@ -89,6 +90,26 @@ static void pciGetDriver(struct pci_dev* dev, FFstrbuf* driver, char*(*ffpci_get
|
||||
ffStrbufDestroy(&path);
|
||||
}
|
||||
|
||||
static double pciGetTemperatur(const FFinstance* instance, uint16_t deviceClass)
|
||||
{
|
||||
const FFTempsResult* tempsResult = ffDetectTemps(instance);
|
||||
|
||||
for(uint32_t i = 0; i < tempsResult->values.length; i++)
|
||||
{
|
||||
FFTempValue* tempValue = ffListGet(&tempsResult->values, i);
|
||||
|
||||
uint32_t tempClass;
|
||||
if(sscanf(tempValue->deviceClass.chars, "%x", &tempClass) != 1)
|
||||
continue;
|
||||
|
||||
//The kernel exposes the device class multiplied by 256 for some reason
|
||||
if(tempClass == deviceClass * 256)
|
||||
return tempValue->value;
|
||||
}
|
||||
|
||||
return 0.0 / 0.0; //NaN
|
||||
}
|
||||
|
||||
static bool pciPrintGPUs(FFinstance* instance)
|
||||
{
|
||||
FF_LIBRARY_LOAD(pci, instance->config.libPCI, false, "libpci.so", 4)
|
||||
@@ -121,16 +142,22 @@ static bool pciPrintGPUs(FFinstance* instance)
|
||||
FFGPUResult* result = ffListAdd(&results);
|
||||
|
||||
ffStrbufInitA(&result->vendor, 256);
|
||||
ffpci_lookup_name(pacc, result->vendor.chars, (int) result->vendor.allocated -1, PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id);
|
||||
ffpci_lookup_name(pacc, result->vendor.chars, (int) ffStrbufGetFree(&result->vendor), PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id);
|
||||
ffStrbufRecalculateLength(&result->vendor);
|
||||
|
||||
ffStrbufInitA(&result->name, 256);
|
||||
ffpci_lookup_name(pacc, result->name.chars, (int) result->name.allocated - 1, PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id);
|
||||
ffpci_lookup_name(pacc, result->name.chars, (int) ffStrbufGetFree(&result->name), PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id);
|
||||
ffStrbufRecalculateLength(&result->name);
|
||||
|
||||
ffStrbufInit(&result->driver);
|
||||
if(instance->config.gpu.outputFormat.length > 0) //We only need it for the format string, so don't detect it if it isn't needed
|
||||
result->temperature = 0;
|
||||
|
||||
//We only need it for the format string, so don't detect it if it isn't needed
|
||||
if(instance->config.gpu.outputFormat.length > 0)
|
||||
{
|
||||
pciGetDriver(dev, &result->driver, ffpci_get_param);
|
||||
result->temperature = pciGetTemperatur(instance, dev->device_class);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user