Merge pull request #1495 from 0cc4m/master

Battery module support for rk817
This commit is contained in:
Alex 2022-04-05 16:39:08 +02:00 committed by GitHub
commit d5b76bd8b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 5 deletions

View File

@ -88,8 +88,9 @@ void waybar::modules::Battery::refreshBatteries() {
auto dir_name = node.path().filename(); auto dir_name = node.path().filename();
auto bat_defined = config_["bat"].isString(); auto bat_defined = config_["bat"].isString();
if (((bat_defined && dir_name == config_["bat"].asString()) || !bat_defined) && if (((bat_defined && dir_name == config_["bat"].asString()) || !bat_defined) &&
fs::exists(node.path() / "capacity") && fs::exists(node.path() / "uevent") && (fs::exists(node.path() / "capacity") || fs::exists(node.path() / "charge_now")) &&
fs::exists(node.path() / "status") && fs::exists(node.path() / "type")) { fs::exists(node.path() / "uevent") && fs::exists(node.path() / "status") &&
fs::exists(node.path() / "type")) {
std::string type; std::string type;
std::ifstream(node.path() / "type") >> type; std::ifstream(node.path() / "type") >> type;
@ -168,14 +169,21 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
// Some battery will report current and charge in μA/μAh. // Some battery will report current and charge in μA/μAh.
// Scale these by the voltage to get μW/μWh. // Scale these by the voltage to get μW/μWh.
if (fs::exists(bat / "current_now")) { if (fs::exists(bat / "current_now") || fs::exists(bat / "current_avg")) {
uint32_t voltage_now; uint32_t voltage_now;
uint32_t current_now; uint32_t current_now;
uint32_t charge_now; uint32_t charge_now;
uint32_t charge_full; uint32_t charge_full;
uint32_t charge_full_design; uint32_t charge_full_design;
std::ifstream(bat / "voltage_now") >> voltage_now; // Some batteries have only *_avg, not *_now
std::ifstream(bat / "current_now") >> current_now; if (fs::exists(bat / "voltage_now"))
std::ifstream(bat / "voltage_now") >> voltage_now;
else
std::ifstream(bat / "voltage_avg") >> voltage_now;
if (fs::exists(bat / "current_now"))
std::ifstream(bat / "current_now") >> current_now;
else
std::ifstream(bat / "current_avg") >> current_now;
std::ifstream(bat / "charge_full") >> charge_full; std::ifstream(bat / "charge_full") >> charge_full;
std::ifstream(bat / "charge_full_design") >> charge_full_design; std::ifstream(bat / "charge_full_design") >> charge_full_design;
if (fs::exists(bat / "charge_now")) if (fs::exists(bat / "charge_now"))