From 12155e029b1258565b6cec699f6308121b829423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 9 Jan 2024 23:08:19 +0800 Subject: [PATCH] Battery (Linux): support manufacture date detection --- src/detection/battery/battery_linux.c | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/detection/battery/battery_linux.c b/src/detection/battery/battery_linux.c index 536f1995d..605ac2ad0 100644 --- a/src/detection/battery/battery_linux.c +++ b/src/detection/battery/battery_linux.c @@ -84,6 +84,37 @@ static void parseBattery(FFstrbuf* dir, const char* id, FFBatteryOptions* option } ffStrbufInit(&result->manufacturerDate); + ffStrbufAppendS(dir, "/manufacture_year"); + available = ffReadFileBuffer(dir->chars, &tmpBuffer); + ffStrbufSubstrBefore(dir, dirLength); + if (available) + { + int year = (int) ffStrbufToSInt(&tmpBuffer, 0); + if (year > 0) + { + ffStrbufAppendS(dir, "/manufacture_month"); + available = ffReadFileBuffer(dir->chars, &tmpBuffer); + ffStrbufSubstrBefore(dir, dirLength); + if (available) + { + int month = (int) ffStrbufToSInt(&tmpBuffer, 0); + if (month > 0) + { + ffStrbufAppendS(dir, "/manufacture_day"); + available = ffReadFileBuffer(dir->chars, &tmpBuffer); + ffStrbufSubstrBefore(dir, dirLength); + if (available) + { + int day = (int) ffStrbufToSInt(&tmpBuffer, 0); + if (day > 0) + { + ffStrbufSetF(&result->manufacturerDate, "%.4d-%.2d-%.2d", year, month, day); + } + } + } + } + } + } result->temperature = FF_BATTERY_TEMP_UNSET; if (options->temp)