[macos] fix temp sensor on system with many cores

This commit is contained in:
Jos Dehaes 2023-08-23 15:46:47 +02:00
parent 1b126f55e3
commit dcbdb7360d

View file

@ -18,6 +18,9 @@ tab-size = 4
#include "smc.hpp"
static constexpr size_t MaxIndexCount = sizeof("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") - 1;
static constexpr const char *KeyIndexes = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static UInt32 _strtoul(char *str, int size, int base) {
UInt32 total = 0;
int i;
@ -91,13 +94,16 @@ namespace Cpu {
// according to VirtualSMC docs (hackintosh fake SMC) the enumeration follows with alphabetic chars - not implemented yet here (nor in VirtualSMC)
long long SMCConnection::getTemp(int core) {
char key[] = SMC_KEY_CPU_TEMP;
if (core > MaxIndexCount) {
return -1;
}
if (core >= 0) {
snprintf(key, 5, "TC%1dc", core);
snprintf(key, 5, "TC%1cc", KeyIndexes[core]);
}
long long result = getSMCTemp(key);
if (result == -1) {
// try again with C
snprintf(key, 5, "TC%1dC", core);
snprintf(key, 5, "TC%1dC", KeyIndexes[core]);
result = getSMCTemp(key);
}
return result;