Linux: fixes sysfs battery discovery

This commit is contained in:
smattie 2019-09-07 15:21:04 +01:00
parent 402e46bb82
commit 1886117c72
1 changed files with 12 additions and 1 deletions

View File

@ -193,7 +193,18 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) {
char* entryName = (char *) dirEntry->d_name;
const char filePath[50];
if (entryName[0] == 'B' && entryName[1] == 'A' && entryName[2] == 'T') {
xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/type", entryName);
int fd = open(filePath, O_RDONLY);
if (fd == -1)
continue;
char type[8];
ssize_t typelen = xread(fd, type, 7);
close(fd);
if (typelen < 1)
continue;
if (type[0] == 'B' && type[1] == 'a' && type[2] == 't') {
xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/uevent", entryName);
int fd = open(filePath, O_RDONLY);