summaryrefslogtreecommitdiffstats
path: root/BatteryMeter.c
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2010-11-20 19:13:12 +0000
committerHisham Muhammad <hisham@gobolinux.org>2010-11-20 19:13:12 +0000
commit3fcbcbfda65c04bc0ba801dedfdc793a98663e58 (patch)
tree5702e6c0de74d027096023c22dd44b5869601510 /BatteryMeter.c
parent5fd1436a9240465a320194be5a69b93a62b542f7 (diff)
Improve battery meter support (thanks to Richard W.) Closes #3063541.
Diffstat (limited to 'BatteryMeter.c')
-rw-r--r--BatteryMeter.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/BatteryMeter.c b/BatteryMeter.c
index 466a525a..36b90e7d 100644
--- a/BatteryMeter.c
+++ b/BatteryMeter.c
@@ -234,7 +234,6 @@ static double getProcBatData() {
return 0;
double percent = totalFull > 0 ? ((double) totalRemain * 100) / (double) totalFull : 0;
-
return percent;
}
@@ -270,8 +269,27 @@ static double getSysBatData() {
return 0;
}
- totalFull += parseUevent(file, "POWER_SUPPLY_ENERGY_FULL=");
- totalRemain += parseUevent(file, "POWER_SUPPLY_ENERGY_NOW=");
+ if ((totalFull += parseUevent(file, "POWER_SUPPLY_ENERGY_FULL="))) {
+ totalRemain += parseUevent(file, "POWER_SUPPLY_ENERGY_NOW=");
+ } else {
+ //reset file pointer
+ if (fseek(file, 0, SEEK_SET) < 0) {
+ fclose(file);
+ return 0;
+ }
+ }
+
+ //Some systems have it as CHARGE instead of ENERGY.
+ if ((totalFull += parseUevent(file, "POWER_SUPPLY_CHARGE_FULL="))) {
+ totalRemain += parseUevent(file, "POWER_SUPPLY_CHARGE_NOW=");
+ } else {
+ //reset file pointer
+ if (fseek(file, 0, SEEK_SET) < 0) {
+ fclose(file);
+ return 0;
+ }
+ }
+
fclose(file);
}
@@ -282,6 +300,7 @@ static double getSysBatData() {
static void BatteryMeter_setValues(Meter * this, char *buffer, int len) {
double percent = getProcBatData();
+
if (percent == 0) {
percent = getSysBatData();
if (percent == 0) {

© 2014-2024 Faster IT GmbH | imprint | privacy policy