mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
Temps: support macOS
This commit is contained in:
+2
-1
@@ -193,7 +193,6 @@ set(LIBFASTFETCH_SRC
|
||||
src/detection/terminalShell.c
|
||||
src/detection/vulkan.c
|
||||
src/detection/datetime.c
|
||||
src/detection/temps.c
|
||||
src/detection/title.c
|
||||
src/detection/host/host.c
|
||||
src/detection/os/os.c
|
||||
@@ -263,6 +262,7 @@ if(LINUX OR ANDROID OR BSD)
|
||||
src/detection/cpuUsage/cpuUsage_linux.c
|
||||
src/detection/disk/disk_linux.c
|
||||
src/detection/poweradapter/poweradapter_linux.c
|
||||
src/detection/temps/temps_linux.c
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -300,6 +300,7 @@ if(APPLE)
|
||||
src/detection/media/media_apple.m
|
||||
src/detection/disk/disk_apple.m
|
||||
src/detection/wmtheme/wmtheme_apple.c
|
||||
src/detection/temps/temps_apple.c
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -220,6 +220,10 @@ static void defaultConfig(FFinstance* instance)
|
||||
ffStrbufInitA(&instance->config.libplist, 0);
|
||||
ffStrbufInitA(&instance->config.libcJSON, 0);
|
||||
|
||||
instance->config.cpuTemp = false;
|
||||
instance->config.gpuTemp = false;
|
||||
instance->config.batteryTemp = false;
|
||||
|
||||
instance->config.titleFQDN = false;
|
||||
|
||||
ffStrbufInitA(&instance->config.diskFolders, 0);
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
#define FF_BATTERY_TEMP_UNSET (0/0.0)
|
||||
|
||||
typedef struct BatteryResult
|
||||
{
|
||||
FFstrbuf manufacturer;
|
||||
@@ -12,6 +14,7 @@ typedef struct BatteryResult
|
||||
FFstrbuf technology;
|
||||
FFstrbuf capacity;
|
||||
FFstrbuf status;
|
||||
double temperature;
|
||||
} BatteryResult;
|
||||
|
||||
const char* ffDetectBatteryImpl(FFinstance* instance, FFlist* results);
|
||||
|
||||
@@ -1,9 +1,34 @@
|
||||
#include "fastfetch.h"
|
||||
#include "battery.h"
|
||||
#include "util/apple/cf_helpers.h"
|
||||
#include "detection/temps/temps_apple.h"
|
||||
|
||||
#include <IOKit/IOKitLib.h>
|
||||
|
||||
static double detectBatteryTemp()
|
||||
{
|
||||
FFlist temps;
|
||||
ffListInit(&temps, sizeof(FFTempValue));
|
||||
|
||||
ffDetectCoreTemps(FF_TEMP_BATTERY, &temps);
|
||||
|
||||
if(temps.length == 0)
|
||||
return FF_BATTERY_TEMP_UNSET;
|
||||
|
||||
double result = 0;
|
||||
for(uint32_t i = 0; i < temps.length; ++i)
|
||||
{
|
||||
FFTempValue* tempValue = (FFTempValue*)ffListGet(&temps, i);
|
||||
result += tempValue->value;
|
||||
//TODO: do we really need this?
|
||||
ffStrbufDestroy(&tempValue->name);
|
||||
ffStrbufDestroy(&tempValue->deviceClass);
|
||||
}
|
||||
result /= temps.length;
|
||||
ffListDestroy(&temps);
|
||||
return result;
|
||||
}
|
||||
|
||||
const char* ffDetectBatteryImpl(FFinstance* instance, FFlist* results)
|
||||
{
|
||||
FF_UNUSED(instance);
|
||||
@@ -69,6 +94,8 @@ const char* ffDetectBatteryImpl(FFinstance* instance, FFlist* results)
|
||||
else
|
||||
ffStrbufAppendS(&battery->status, "");
|
||||
|
||||
battery->temperature = detectBatteryTemp();
|
||||
|
||||
CFRelease(properties);
|
||||
IOObjectRelease(registryEntry);
|
||||
}
|
||||
|
||||
@@ -70,6 +70,8 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
|
||||
ffStrbufAppendS(dir, "/status");
|
||||
ffReadFileBuffer(dir->chars, &result->status);
|
||||
ffStrbufSubstrBefore(dir, dirLength);
|
||||
|
||||
result->temperature = FF_BATTERY_TEMP_UNSET;
|
||||
}
|
||||
|
||||
const char* ffDetectBatteryImpl(FFinstance* instance, FFlist* results) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "cpu.h"
|
||||
#include "common/sysctl.h"
|
||||
#include "detection/temps/temps_apple.h"
|
||||
|
||||
static double getFrequency(const char* propName)
|
||||
{
|
||||
@@ -12,33 +13,61 @@ static double getFrequency(const char* propName)
|
||||
return herz / 1000.0; //to GHz
|
||||
}
|
||||
|
||||
static double detectCpuTemp(const FFstrbuf* cpuName)
|
||||
{
|
||||
FFlist temps;
|
||||
ffListInit(&temps, sizeof(FFTempValue));
|
||||
|
||||
if(ffStrbufStartsWithS(cpuName, "Apple M1"))
|
||||
ffDetectCoreTemps(FF_TEMP_CPU_M1X, &temps);
|
||||
else if(ffStrbufStartsWithS(cpuName, "Apple M2"))
|
||||
ffDetectCoreTemps(FF_TEMP_CPU_M2X, &temps);
|
||||
else //TODO: PPC?
|
||||
ffDetectCoreTemps(FF_TEMP_CPU_X64, &temps);
|
||||
|
||||
if(temps.length == 0)
|
||||
return FF_CPU_TEMP_UNSET;
|
||||
|
||||
double result = 0;
|
||||
for(uint32_t i = 0; i < temps.length; ++i)
|
||||
{
|
||||
FFTempValue* tempValue = (FFTempValue*)ffListGet(&temps, i);
|
||||
result += tempValue->value;
|
||||
//TODO: do we really need this?
|
||||
ffStrbufDestroy(&tempValue->name);
|
||||
ffStrbufDestroy(&tempValue->deviceClass);
|
||||
}
|
||||
result /= temps.length;
|
||||
ffListDestroy(&temps);
|
||||
return result;
|
||||
}
|
||||
|
||||
void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu, bool cached)
|
||||
{
|
||||
FF_UNUSED(instance);
|
||||
|
||||
//TODO find a way to detect this
|
||||
cpu->temperature = FF_CPU_TEMP_UNSET;
|
||||
if(!cached)
|
||||
{
|
||||
ffSysctlGetString("machdep.cpu.brand_string", &cpu->name);
|
||||
ffSysctlGetString("machdep.cpu.vendor", &cpu->vendor);
|
||||
|
||||
if(cached)
|
||||
return;
|
||||
cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.physicalcpu_max", 1);
|
||||
if(cpu->coresPhysical == 1)
|
||||
cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.physicalcpu", 1);
|
||||
|
||||
ffSysctlGetString("machdep.cpu.brand_string", &cpu->name);
|
||||
ffSysctlGetString("machdep.cpu.vendor", &cpu->vendor);
|
||||
cpu->coresLogical = (uint16_t) ffSysctlGetInt("hw.logicalcpu_max", 1);
|
||||
if(cpu->coresLogical == 1)
|
||||
cpu->coresLogical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1);
|
||||
|
||||
cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.physicalcpu_max", 1);
|
||||
if(cpu->coresPhysical == 1)
|
||||
cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.physicalcpu", 1);
|
||||
cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.logicalcpu", 1);
|
||||
if(cpu->coresOnline == 1)
|
||||
cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.activecpu", 1);
|
||||
|
||||
cpu->coresLogical = (uint16_t) ffSysctlGetInt("hw.logicalcpu_max", 1);
|
||||
if(cpu->coresLogical == 1)
|
||||
cpu->coresLogical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1);
|
||||
cpu->frequencyMin = getFrequency("hw.cpufrequency_min");
|
||||
cpu->frequencyMax = getFrequency("hw.cpufrequency_max");
|
||||
if(cpu->frequencyMax == 0.0)
|
||||
cpu->frequencyMax = getFrequency("hw.cpufrequency");
|
||||
}
|
||||
|
||||
cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.logicalcpu", 1);
|
||||
if(cpu->coresOnline == 1)
|
||||
cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.activecpu", 1);
|
||||
|
||||
cpu->frequencyMin = getFrequency("hw.cpufrequency_min");
|
||||
cpu->frequencyMax = getFrequency("hw.cpufrequency_max");
|
||||
if(cpu->frequencyMax == 0.0)
|
||||
cpu->frequencyMax = getFrequency("hw.cpufrequency");
|
||||
cpu->temperature = detectCpuTemp(&cpu->name);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "cpu.h"
|
||||
#include "common/io.h"
|
||||
#include "common/properties.h"
|
||||
#include "detection/temps.h"
|
||||
#include "detection/temps/temps_linux.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -1,10 +1,42 @@
|
||||
#include "gpu.h"
|
||||
#include "common/library.h"
|
||||
#include "detection/cpu/cpu.h"
|
||||
#include "detection/temps/temps_apple.h"
|
||||
#include "util/apple/cf_helpers.h"
|
||||
|
||||
#include <IOKit/graphics/IOGraphicsLib.h>
|
||||
|
||||
static double detectGpuTemp(const FFstrbuf* gpuName)
|
||||
{
|
||||
FFlist temps;
|
||||
ffListInit(&temps, sizeof(FFTempValue));
|
||||
|
||||
if(ffStrbufStartsWithS(gpuName, "Apple M1"))
|
||||
ffDetectCoreTemps(FF_TEMP_GPU_M1X, &temps);
|
||||
else if(ffStrbufStartsWithS(gpuName, "Apple M2"))
|
||||
ffDetectCoreTemps(FF_TEMP_GPU_M2X, &temps);
|
||||
else if(ffStrbufStartsWithS(gpuName, "Radeon") || ffStrbufStartsWithS(gpuName, "AMD"))
|
||||
ffDetectCoreTemps(FF_TEMP_GPU_AMD, &temps);
|
||||
else
|
||||
ffDetectCoreTemps(FF_TEMP_GPU_UNKNOWN, &temps);
|
||||
|
||||
if(temps.length == 0)
|
||||
return FF_GPU_TEMP_UNSET;
|
||||
|
||||
double result = 0;
|
||||
for(uint32_t i = 0; i < temps.length; ++i)
|
||||
{
|
||||
FFTempValue* tempValue = (FFTempValue*)ffListGet(&temps, i);
|
||||
result += tempValue->value;
|
||||
//TODO: do we really need this?
|
||||
ffStrbufDestroy(&tempValue->name);
|
||||
ffStrbufDestroy(&tempValue->deviceClass);
|
||||
}
|
||||
result /= temps.length;
|
||||
ffListDestroy(&temps);
|
||||
return result;
|
||||
}
|
||||
|
||||
const char* ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance)
|
||||
{
|
||||
FF_UNUSED(instance);
|
||||
@@ -52,7 +84,7 @@ const char* ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance)
|
||||
if(ffCfDictGetInt(properties, CFSTR("gpu-core-count"), &gpu->coreCount))
|
||||
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
|
||||
|
||||
gpu->temperature = FF_GPU_TEMP_UNSET;
|
||||
gpu->temperature = detectGpuTemp(&gpu->name);
|
||||
|
||||
CFRelease(properties);
|
||||
IOObjectRelease(registryEntry);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "common/library.h"
|
||||
#include "common/properties.h"
|
||||
#include "common/parsing.h"
|
||||
#include "detection/temps.h"
|
||||
#include "detection/temps/temps_linux.h"
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <pci/pci.h>
|
||||
|
||||
@@ -0,0 +1,413 @@
|
||||
#include "fastfetch.h"
|
||||
#include "temps_apple.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include <IOKit/IOKitLib.h>
|
||||
|
||||
static const char kDataTypeFlt[] = "flt ";
|
||||
static const char kDataTypeFp1f[] = "fp1f";
|
||||
static const char kDataTypeFp4c[] = "fp4c";
|
||||
static const char kDataTypeFp5b[] = "fp5b";
|
||||
static const char kDataTypeFp6a[] = "fp6a";
|
||||
static const char kDataTypeFp79[] = "fp79";
|
||||
static const char kDataTypeFp88[] = "fp88";
|
||||
static const char kDataTypeFpa6[] = "fpa6";
|
||||
static const char kDataTypeFpc4[] = "fpc4";
|
||||
static const char kDataTypeFpe2[] = "fpe2";
|
||||
static const char kDataTypeSp1e[] = "sp1e";
|
||||
static const char kDataTypeSp3c[] = "sp3c";
|
||||
static const char kDataTypeSp4b[] = "sp4b";
|
||||
static const char kDataTypeSp5a[] = "sp5a";
|
||||
static const char kDataTypeSp69[] = "sp69";
|
||||
static const char kDataTypeSp78[] = "sp78";
|
||||
static const char kDataTypeSp87[] = "sp87";
|
||||
static const char kDataTypeSp96[] = "sp96";
|
||||
static const char kDataTypeSpb4[] = "spb4";
|
||||
static const char kDataTypeSpf0[] = "spf0";
|
||||
static const char kDataTypeUi8[] = "ui8 ";
|
||||
static const char kDataTypeUi16[] = "ui16";
|
||||
static const char kDataTypeUi32[] = "ui32";
|
||||
static const char kDataTypeUi64[] = "ui64";
|
||||
static const char kDataTypeSi8[] = "si8 ";
|
||||
static const char kDataTypeSi16[] = "si16";
|
||||
static const char kDataTypePwm[] = "{pwm";
|
||||
|
||||
static const char *kIOAppleSmcHiddenClassName = "AppleSMC";
|
||||
static const char kSmcCmdReadBytes = 5;
|
||||
static const char kSmcCmdReadKeyInfo = 9;
|
||||
static const uint32_t kKernelIndexSmc = 2;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char major;
|
||||
char minor;
|
||||
char build;
|
||||
char reserved[1];
|
||||
uint16_t release;
|
||||
} SmcKeyData_vers_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t version;
|
||||
uint16_t length;
|
||||
uint32_t cpuPLimit;
|
||||
uint32_t gpuPLimit;
|
||||
uint32_t memPLimit;
|
||||
} SmcKeyData_pLimitData_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t dataSize;
|
||||
uint32_t dataType;
|
||||
char dataAttributes;
|
||||
} SmcKeyData_keyInfo_t;
|
||||
|
||||
typedef unsigned char SmcBytes_t[32];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t key;
|
||||
SmcKeyData_vers_t vers;
|
||||
SmcKeyData_pLimitData_t pLimitData;
|
||||
SmcKeyData_keyInfo_t keyInfo;
|
||||
char result;
|
||||
char status;
|
||||
char data8;
|
||||
uint32_t data32;
|
||||
SmcBytes_t bytes;
|
||||
} SmcKeyData_t;
|
||||
|
||||
typedef char UInt32Char_t[5];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UInt32Char_t key;
|
||||
uint32_t dataSize;
|
||||
UInt32Char_t dataType;
|
||||
SmcBytes_t bytes;
|
||||
} SmcVal_t;
|
||||
|
||||
static uint32_t smcStrtoul(const char *str, int size, int base)
|
||||
{
|
||||
uint32_t total = 0;
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
if (base == 16)
|
||||
total += (uint32_t)(str[i] << (size - 1 - i) * 8);
|
||||
else
|
||||
total += (uint32_t)((unsigned char)(str[i]) << (size - 1 - i) * 8);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
static void smcUltostr(char *str, uint32_t val)
|
||||
{
|
||||
str[0] = '\0';
|
||||
sprintf(str, "%c%c%c%c",
|
||||
(unsigned int)val >> 24,
|
||||
(unsigned int)val >> 16,
|
||||
(unsigned int)val >> 8,
|
||||
(unsigned int)val);
|
||||
}
|
||||
|
||||
static const char *smcCall(io_connect_t conn, uint32_t selector, SmcKeyData_t *inputStructure, SmcKeyData_t *outputStructure)
|
||||
{
|
||||
size_t structureInputSize;
|
||||
size_t structureOutputSize;
|
||||
structureInputSize = sizeof(SmcKeyData_t);
|
||||
structureOutputSize = sizeof(SmcKeyData_t);
|
||||
|
||||
if (IOConnectCallStructMethod(conn, selector, inputStructure, structureInputSize, outputStructure, &structureOutputSize) != kIOReturnSuccess)
|
||||
return "IOConnectCallStructMethod(conn) failed";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Provides key info, using a cache to dramatically improve the energy impact of smcFanControl
|
||||
static const char *smcGetKeyInfo(io_connect_t conn, const uint32_t key, SmcKeyData_keyInfo_t *key_info)
|
||||
{
|
||||
SmcKeyData_t inputStructure = {0};
|
||||
SmcKeyData_t outputStructure = {0};
|
||||
|
||||
inputStructure.key = key;
|
||||
inputStructure.data8 = kSmcCmdReadKeyInfo;
|
||||
|
||||
const char *error = smcCall(conn, kKernelIndexSmc, &inputStructure, &outputStructure);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
*key_info = outputStructure.keyInfo;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *smcReadSmcVal(io_connect_t conn, const UInt32Char_t key, SmcVal_t *val)
|
||||
{
|
||||
SmcKeyData_t inputStructure = {0};
|
||||
SmcKeyData_t outputStructure = {0};
|
||||
|
||||
inputStructure.key = smcStrtoul(key, 4, 16);
|
||||
strcpy(val->key, key);
|
||||
|
||||
const char *error = smcGetKeyInfo(conn, inputStructure.key, &outputStructure.keyInfo);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
val->dataSize = outputStructure.keyInfo.dataSize;
|
||||
smcUltostr(val->dataType, outputStructure.keyInfo.dataType);
|
||||
inputStructure.keyInfo.dataSize = val->dataSize;
|
||||
inputStructure.data8 = kSmcCmdReadBytes;
|
||||
|
||||
error = smcCall(conn, kKernelIndexSmc, &inputStructure, &outputStructure);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
memcpy(val->bytes, outputStructure.bytes, sizeof(outputStructure.bytes));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *smcOpen(io_connect_t *conn)
|
||||
{
|
||||
CFMutableDictionaryRef matchDict = IOServiceMatching(kIOAppleSmcHiddenClassName);
|
||||
if (matchDict == NULL)
|
||||
return "IOServiceMatching(\"AppleSmartBattery\") failed";
|
||||
|
||||
io_iterator_t iterator;
|
||||
if (IOServiceGetMatchingServices(MACH_PORT_NULL, matchDict, &iterator) != kIOReturnSuccess)
|
||||
return "IOServiceGetMatchingServices() failed";
|
||||
|
||||
io_object_t device = IOIteratorNext(iterator);
|
||||
IOObjectRelease(iterator);
|
||||
if (device == 0)
|
||||
return "No SMC device found";
|
||||
|
||||
kern_return_t result = IOServiceOpen(device, mach_task_self(), 0, conn);
|
||||
IOObjectRelease(device);
|
||||
if (result != kIOReturnSuccess)
|
||||
return "IOServiceOpen() failed";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *smcClose(io_connect_t conn)
|
||||
{
|
||||
if (IOServiceClose(conn) != kIOReturnSuccess)
|
||||
return "IOServiceClose() failed";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *smcReadValue(io_connect_t conn, const UInt32Char_t key, double *value)
|
||||
{
|
||||
SmcVal_t val = {0};
|
||||
const char* error = smcReadSmcVal(conn, key, &val);
|
||||
if (error != NULL)
|
||||
return error;
|
||||
|
||||
if (strcmp(val.dataType, kDataTypeUi8) == 0 ||
|
||||
strcmp(val.dataType, kDataTypeUi16) == 0 ||
|
||||
strcmp(val.dataType, kDataTypeUi32) == 0 ||
|
||||
strcmp(val.dataType, kDataTypeUi64) == 0)
|
||||
{
|
||||
uint64_t tmp = 0;
|
||||
for (uint32_t i = 0; i < val.dataSize; i++)
|
||||
tmp += (uint64_t)((uint8_t)(val.bytes[i]) * pow(256, val.dataSize - 1 - i));
|
||||
*value = tmp;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeFlt) == 0)
|
||||
{
|
||||
*value = *(float *)(val.bytes);
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeFp1f) && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(uint16_t *)(val.bytes)) / 32768.0;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeFp4c) && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(uint16_t *)(val.bytes)) / 4096.0;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeFp5b) == 0 && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(uint16_t *)(val.bytes)) / 2048.0;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeFp6a) == 0 && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(uint16_t *)(val.bytes)) / 1024.0;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeFp79) == 0 && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(uint16_t *)(val.bytes)) / 512.0;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeFp88) == 0 && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(uint16_t *)(val.bytes)) / 256.0;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeFpa6) == 0 && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(uint16_t *)(val.bytes)) / 64.0;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeFpc4) == 0 && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(uint16_t *)(val.bytes)) / 16.0;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeFpe2) == 0 && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(uint16_t *)(val.bytes)) / 4.0;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeSp1e) == 0 && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(uint16_t *)(val.bytes)) / 16384.0;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeSp3c) == 0 && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(uint16_t *)(val.bytes)) / 4096.0;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeSp4b) == 0 && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(uint16_t *)(val.bytes)) / 2048.0;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeSp5a) == 0 && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(uint16_t *)(val.bytes)) / 1024.0;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeSp69) == 0 && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(uint16_t *)(val.bytes)) / 512.0;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeSp78) == 0 && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(uint16_t *)(val.bytes)) / 256.0;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeSp87) == 0 && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(uint16_t *)(val.bytes)) / 128.0;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeSp96) == 0 && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(uint16_t *)(val.bytes)) / 64.0;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeSpb4) == 0 && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(uint16_t *)(val.bytes)) / 16.0;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeSpf0) == 0 && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(uint16_t *)(val.bytes)) / 1.0;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeSi8) == 0 && val.dataSize == 1)
|
||||
{
|
||||
signed char *bytes = (signed char *)val.bytes;
|
||||
int16_t temp = 0;
|
||||
temp += (int8_t)(bytes[0]);
|
||||
*value = temp;
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypeSi16) == 0 && val.dataSize == 2)
|
||||
{
|
||||
*value = ntohs(*(int16_t *)(val.bytes));
|
||||
}
|
||||
else if (strcmp(val.dataType, kDataTypePwm) == 0 && val.dataSize == 2)
|
||||
{
|
||||
*value = (double)ntohs(*(uint16_t *)(val.bytes)) * 100 / 65536.0;
|
||||
}
|
||||
else
|
||||
return "Unknown SMC data type";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void detectTemp(io_connect_t conn, const char *sensor, const char *name, FFlist *list)
|
||||
{
|
||||
double temp = 0;
|
||||
const char* error = smcReadValue(conn, sensor, &temp);
|
||||
if (error)
|
||||
return;
|
||||
|
||||
FFTempValue* tempValue= (FFTempValue*)ffListAdd(list);
|
||||
tempValue->value = temp;
|
||||
|
||||
assert(strlen(sensor) == 4);
|
||||
ffStrbufInitNS(&tempValue->deviceClass, 4, sensor);
|
||||
|
||||
ffStrbufInitS(&tempValue->name, name);
|
||||
}
|
||||
|
||||
const char *ffDetectCoreTemps(enum FFTempType type, FFlist *result)
|
||||
{
|
||||
io_connect_t conn;
|
||||
const char* error = smcOpen(&conn);
|
||||
if(error)
|
||||
return error;
|
||||
|
||||
// https://github.com/exelban/stats/blob/master/Modules/Sensors/values.swift
|
||||
switch (type)
|
||||
{
|
||||
case FF_TEMP_CPU_X64:
|
||||
detectTemp(conn, "TC0D", "CPU diode", result);
|
||||
detectTemp(conn, "TC0E", "CPU diode virtual", result);
|
||||
detectTemp(conn, "TC0E", "CPU diode filtered", result);
|
||||
detectTemp(conn, "TC0P", "CPU proximity", result);
|
||||
break;
|
||||
|
||||
case FF_TEMP_CPU_M1X:
|
||||
detectTemp(conn, "Tp09", "CPU efficient core 1", result);
|
||||
detectTemp(conn, "Tp0T", "CPU efficient core 2", result);
|
||||
|
||||
detectTemp(conn, "Tp01", "CPU performance core 1", result);
|
||||
detectTemp(conn, "Tp05", "CPU performance core 2", result);
|
||||
detectTemp(conn, "Tp0D", "CPU performance core 3", result);
|
||||
detectTemp(conn, "Tp0H", "CPU performance core 4", result);
|
||||
detectTemp(conn, "Tp0L", "CPU performance core 5", result);
|
||||
detectTemp(conn, "Tp0P", "CPU performance core 6", result);
|
||||
detectTemp(conn, "Tp0X", "CPU performance core 7", result);
|
||||
detectTemp(conn, "Tp0b", "CPU performance core 8", result);
|
||||
break;
|
||||
|
||||
case FF_TEMP_CPU_M2X:
|
||||
detectTemp(conn, "Tp05", "CPU efficient core 1", result);
|
||||
detectTemp(conn, "Tp0D", "CPU efficient core 2", result);
|
||||
detectTemp(conn, "Tp0j", "CPU efficient core 3", result);
|
||||
detectTemp(conn, "Tp0r", "CPU efficient core 4", result);
|
||||
|
||||
detectTemp(conn, "Tp01", "CPU performance core 1", result);
|
||||
detectTemp(conn, "Tp09", "CPU performance core 2", result);
|
||||
detectTemp(conn, "Tp0f", "CPU performance core 3", result);
|
||||
detectTemp(conn, "Tp0n", "CPU performance core 4", result);
|
||||
break;
|
||||
|
||||
case FF_TEMP_GPU_INTEL:
|
||||
detectTemp(conn, "TCGC", "GPU Intel Graphics", result);
|
||||
detectTemp(conn, "TG0D", "GPU diode", result);
|
||||
detectTemp(conn, "TG0P", "GPU proximity", result);
|
||||
break;
|
||||
|
||||
case FF_TEMP_GPU_AMD:
|
||||
detectTemp(conn, "TGDD", "GPU AMD Radeon", result);
|
||||
detectTemp(conn, "TG0D", "GPU diode", result);
|
||||
detectTemp(conn, "TG0P", "GPU proximity", result);
|
||||
break;
|
||||
|
||||
case FF_TEMP_GPU_UNKNOWN: // Nvidia?
|
||||
detectTemp(conn, "TG0D", "GPU diode", result);
|
||||
detectTemp(conn, "TG0P", "GPU proximity", result);
|
||||
break;
|
||||
|
||||
case FF_TEMP_GPU_M1X:
|
||||
detectTemp(conn, "Tg05", "GPU 1", result);
|
||||
detectTemp(conn, "Tg0D", "GPU 2", result);
|
||||
detectTemp(conn, "Tg0L", "GPU 3", result);
|
||||
detectTemp(conn, "Tg0T", "GPU 4", result);
|
||||
break;
|
||||
|
||||
case FF_TEMP_GPU_M2X:
|
||||
detectTemp(conn, "Tg0f", "GPU 1", result);
|
||||
detectTemp(conn, "Tg0n", "GPU 2", result);
|
||||
break;
|
||||
|
||||
case FF_TEMP_BATTERY:
|
||||
detectTemp(conn, "TB1T", "Battery", result);
|
||||
break;
|
||||
}
|
||||
|
||||
error = smcClose(conn);
|
||||
if(error)
|
||||
return error;
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef FF_INCLUDED_detection_temps_apple
|
||||
#define FF_INCLUDED_detection_temps_apple
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include "util/FFlist.h"
|
||||
|
||||
typedef struct FFTempValue
|
||||
{
|
||||
FFstrbuf name;
|
||||
FFstrbuf deviceClass;
|
||||
double value;
|
||||
} FFTempValue;
|
||||
|
||||
enum FFTempType
|
||||
{
|
||||
FF_TEMP_CPU_X64,
|
||||
FF_TEMP_CPU_M1X,
|
||||
FF_TEMP_CPU_M2X,
|
||||
|
||||
FF_TEMP_GPU_INTEL,
|
||||
FF_TEMP_GPU_AMD,
|
||||
FF_TEMP_GPU_UNKNOWN,
|
||||
FF_TEMP_GPU_M1X,
|
||||
FF_TEMP_GPU_M2X,
|
||||
|
||||
FF_TEMP_BATTERY,
|
||||
};
|
||||
|
||||
const char *ffDetectCoreTemps(enum FFTempType type, FFlist *result);
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "fastfetch.h"
|
||||
#include "detection/temps.h"
|
||||
#include "common/io.h"
|
||||
#include "temps_linux.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef FF_INCLUDED_detection_temps
|
||||
#define FF_INCLUDED_detection_temps
|
||||
#ifndef FF_INCLUDED_detection_temps_linux
|
||||
#define FF_INCLUDED_detection_temps_linux
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#define FF_BATTERY_MODULE_NAME "Battery"
|
||||
#define FF_BATTERY_NUM_FORMAT_ARGS 5
|
||||
|
||||
static void printBattery(FFinstance* instance, const BatteryResult* result, uint8_t index)
|
||||
static void printBattery(FFinstance* instance, BatteryResult* result, uint8_t index)
|
||||
{
|
||||
if(instance->config.battery.outputFormat.length == 0)
|
||||
{
|
||||
@@ -32,6 +32,9 @@ static void printBattery(FFinstance* instance, const BatteryResult* result, uint
|
||||
putchar(']');
|
||||
}
|
||||
|
||||
if(result->temperature == result->temperature) //FF_BATTERY_TEMP_UNSET
|
||||
printf(" - %.1f°C", result->temperature);
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
@@ -41,7 +44,8 @@ static void printBattery(FFinstance* instance, const BatteryResult* result, uint
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->modelName},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->technology},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->capacity},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->status}
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->status},
|
||||
{FF_FORMAT_ARG_TYPE_DOUBLE, &result->temperature},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,9 @@ void ffPrintCPU(FFinstance* instance)
|
||||
if(cpu->frequencyMax > 0.0)
|
||||
printf(" @ %.9g GHz", cpu->frequencyMax);
|
||||
|
||||
if(cpu->temperature == cpu->temperature) //FF_CPU_TEMP_UNSET
|
||||
printf(" - %.1f°C", cpu->temperature);
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
|
||||
+4
-1
@@ -25,11 +25,14 @@ static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache,
|
||||
if(gpu->coreCount != FF_GPU_CORE_COUNT_UNSET)
|
||||
ffStrbufAppendF(&output, " (%d)", gpu->coreCount);
|
||||
|
||||
if(gpu->temperature == gpu->temperature) //FF_GPU_TEMP_UNSET
|
||||
ffStrbufAppendF(&output, " - %.1f°C", gpu->temperature);
|
||||
|
||||
ffPrintAndAppendToCache(instance, FF_GPU_MODULE_NAME, index, &instance->config.gpu, cache, &output, FF_GPU_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->vendor},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->name},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->driver},
|
||||
{FF_FORMAT_ARG_TYPE_DOUBLE, &gpu->temperature},
|
||||
{FF_FORMAT_ARG_TYPE_DOUBLE, &gpu->temperature}, //FIXME: temperature shouldn't be cached
|
||||
{FF_FORMAT_ARG_TYPE_INT, &gpu->coreCount},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user