Battery (Linux): fix temp detection for asahi

This commit is contained in:
Carter Li
2023-12-26 16:43:44 +08:00
parent 5a372882fa
commit b1f54ab7a2
3 changed files with 17 additions and 1 deletions
+1 -1
View File
@@ -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;
+15
View File
@@ -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;
}
+1
View File
@@ -5,6 +5,7 @@
typedef struct FFTempValue
{
FFstrbuf name;
FFstrbuf deviceName;
uint32_t deviceClass;
double value;
} FFTempValue;