Commit 032ba36f519699964568bc92be0d11652866706c
Parse battery info from /sys/class/power_supply
Using /proc/acpi/battery is probably an outdated method, but keep it
anyway.
Author: xaizek
Author date (UTC): 2024-04-09 14:46
Committer name: xaizek
Committer date (UTC): 2024-04-09 14:46
Parent(s): c93bc86b5fba7a16ef66a5dad862ef02e97e04c6
Signing key: 99DC5E4DB05F6BE2
Tree: 96f63cb19225e26f2f63b52eee18c20ef5856aa5
File src/Battery.cpp changed (mode: 100644) (index c631cdf..943b32b) |
... |
... |
std::pair<bool, int> Battery::getBatteryState() const |
86 |
86 |
return { |
return { |
87 |
87 |
charged == "charged" || charged == "charging", (remaining*100)/full |
charged == "charged" || charged == "charging", (remaining*100)/full |
88 |
88 |
}; |
}; |
89 |
|
} else { |
|
90 |
|
return { false, -1 }; |
|
91 |
89 |
} |
} |
|
90 |
|
|
|
91 |
|
std::ifstream capacity { "/sys/class/power_supply/BAT0/capacity" }; |
|
92 |
|
std::ifstream status { "/sys/class/power_supply/BAT0/status" }; |
|
93 |
|
if (capacity.is_open() && status.is_open()) { |
|
94 |
|
int level; |
|
95 |
|
std::string state; |
|
96 |
|
|
|
97 |
|
capacity >> level; |
|
98 |
|
status >> state; |
|
99 |
|
|
|
100 |
|
return { |
|
101 |
|
state != "Discharging", level |
|
102 |
|
}; |
|
103 |
|
} |
|
104 |
|
|
|
105 |
|
return { false, -1 }; |
92 |
106 |
} |
} |