From b1f54ab7a206d20f086ad74faf403734efd554db Mon Sep 17 00:00:00 2001 From: Carter Li Date: Tue, 26 Dec 2023 16:43:44 +0800 Subject: [PATCH] Battery (Linux): fix temp detection for asahi --- src/detection/battery/battery_linux.c | 2 +- src/detection/temps/temps_linux.c | 15 +++++++++++++++ src/detection/temps/temps_linux.h | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/detection/battery/battery_linux.c b/src/detection/battery/battery_linux.c index 113c8949c..04b8a9a0a 100644 --- a/src/detection/battery/battery_linux.c +++ b/src/detection/battery/battery_linux.c @@ -89,7 +89,7 @@ static void parseBattery(FFstrbuf* dir, const char* id, FFBatteryOptions* option FF_LIST_FOR_EACH(FFTempValue, value, *tempsResult) { - if (ffStrbufEqualS(&value->name, id)) + if (ffStrbufEqualS(&value->deviceName, id)) { result->temperature = value->value; break; diff --git a/src/detection/temps/temps_linux.c b/src/detection/temps/temps_linux.c index 5c8b39078..89d9f941e 100644 --- a/src/detection/temps/temps_linux.c +++ b/src/detection/temps/temps_linux.c @@ -37,9 +37,24 @@ static bool parseHwmonDir(FFstrbuf* dir, FFTempValue* value) ffReadFileBuffer(dir->chars, &valueBuffer); } ffStrbufTrimRightSpace(&valueBuffer); + ffStrbufSubstrBefore(dir, dirLength); if(valueBuffer.length) value->deviceClass = (uint32_t) strtoul(valueBuffer.chars, NULL, 16); + ffStrbufClear(&valueBuffer); + ffStrbufEnsureFree(&valueBuffer, 64); + ffStrbufAppendS(dir, "device"); + ssize_t linkLen = readlink(dir->chars, valueBuffer.chars, valueBuffer.allocated - 1); + if (linkLen > 0) + { + valueBuffer.length = (uint32_t) linkLen; + valueBuffer.chars[linkLen] = 0; + ffStrbufSubstrAfterLastC(&valueBuffer, '/'); + ffStrbufInitMove(&value->deviceName, &valueBuffer); + } + else + ffStrbufInit(&value->deviceName); + return value->name.length > 0 || value->deviceClass > 0; } diff --git a/src/detection/temps/temps_linux.h b/src/detection/temps/temps_linux.h index 0d153ccfd..ccb908b44 100644 --- a/src/detection/temps/temps_linux.h +++ b/src/detection/temps/temps_linux.h @@ -5,6 +5,7 @@ typedef struct FFTempValue { FFstrbuf name; + FFstrbuf deviceName; uint32_t deviceClass; double value; } FFTempValue;