Skip to content

Commit

Permalink
[macos] fix temp sensor on system with many cores
Browse files Browse the repository at this point in the history
  • Loading branch information
joske committed Aug 23, 2023
1 parent 1b126f5 commit dcbdb73
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/osx/smc.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit dcbdb73

Please sign in to comment.