Skip to content

Commit

Permalink
Hopefully support battery level for new devices
Browse files Browse the repository at this point in the history
  • Loading branch information
shermp committed May 3, 2024
1 parent 6b91113 commit 40a5233
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/nickelclock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
const char nc_qt_property[] = "NickelClock";
const char nc_widget_name[] = "ncLabelWidget";

const char nc_sysfs_gen_bat_cap[] = "/sys/class/power_supply/battery/capacity";
const char nc_sysfs_mc13892_bat_cap[] = "/sys/class/power_supply/mc13892_bat/capacity";
const char* battery_cap_files[] = {
"/sys/class/power_supply/battery/capacity",
"/sys/class/power_supply/mc13892_bat/capacity",
"/sys/class/power_supply/bd71827_bat/capacity"
};

NC *nc = nullptr;

Expand Down Expand Up @@ -281,10 +284,17 @@ QWidget* NC::createBatteryWidget()
int NC::getBatteryLevel()
{
int battery = 100;
if (batteryCapFilename.isEmpty())
batteryCapFilename = QFile::exists(nc_sysfs_gen_bat_cap)
? nc_sysfs_gen_bat_cap
: nc_sysfs_mc13892_bat_cap;
if (batteryCapFilename.isEmpty()) {
for (auto file_name : battery_cap_files) {
if (QFile::exists(file_name)) {
batteryCapFilename = file_name;
break;
}
}
}
if (batteryCapFilename.isEmpty()) {
return battery;
}
QFile bcFile;
bcFile.setFileName(batteryCapFilename);
if (bcFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
Expand Down

0 comments on commit 40a5233

Please sign in to comment.