Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Linux: fixes sysfs battery discovery #946

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion linux/Battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down