|
5 | 5 |
|
6 | 6 | #include <dirent.h> |
7 | 7 |
|
| 8 | +// https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-power |
| 9 | + |
8 | 10 | static void parseBattery(FFstrbuf* dir, const char* id, FFBatteryOptions* options, FFlist* results) |
9 | 11 | { |
10 | 12 | uint32_t dirLength = dir->length; |
@@ -68,6 +70,26 @@ static void parseBattery(FFstrbuf* dir, const char* id, FFBatteryOptions* option |
68 | 70 | ffStrbufTrimRightSpace(&result->status); |
69 | 71 | ffStrbufSubstrBefore(dir, dirLength); |
70 | 72 |
|
| 73 | + // Unknown, Charging, Discharging, Not charging, Full |
| 74 | + if (ffStrbufEqualS(&result->status, "Not charging") || ffStrbufEqualS(&result->status, "Full")) |
| 75 | + ffStrbufSetStatic(&result->status, "AC Connected"); |
| 76 | + else if (ffStrbufEqualS(&result->status, "Unknown")) |
| 77 | + ffStrbufClear(&result->status); |
| 78 | + |
| 79 | + ffStrbufAppendS(dir, "/capacity_level"); |
| 80 | + if (ffReadFileBuffer(dir->chars, &tmpBuffer)) |
| 81 | + { |
| 82 | + ffStrbufTrimRightSpace(&result->manufacturer); |
| 83 | + if (ffStrbufEqualS(&tmpBuffer, "Critical")) |
| 84 | + { |
| 85 | + if (result->status.length) |
| 86 | + ffStrbufAppendS(&result->status, ", Critical"); |
| 87 | + else |
| 88 | + ffStrbufSetStatic(&result->status, "Critical"); |
| 89 | + } |
| 90 | + } |
| 91 | + ffStrbufSubstrBefore(dir, dirLength); |
| 92 | + |
71 | 93 | ffStrbufInit(&result->serial); |
72 | 94 | ffStrbufAppendS(dir, "/serial_number"); |
73 | 95 | if (ffReadFileBuffer(dir->chars, &result->serial)) |
|
0 commit comments