mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-02-15 10:21:38 +00:00
Merge pull request #44 from ldx/allbattperct
Compute mean percentage for multiple batteries.
This commit is contained in:
commit
3696f0ea51
@ -411,7 +411,8 @@
|
||||
</term>
|
||||
<listitem>Battery percentage remaining of ACPI battery in a
|
||||
bar. ACPI battery number can be given as argument (default
|
||||
is BAT0).
|
||||
is BAT0, use all to get the mean percentage remaining for
|
||||
all batteries).
|
||||
<para /></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
@ -423,7 +424,8 @@
|
||||
</term>
|
||||
<listitem>Battery percentage remaining for ACPI battery.
|
||||
ACPI battery number can be given as argument (default is
|
||||
BAT0).
|
||||
BAT0, use all to get the mean percentage remaining for
|
||||
all batteries).
|
||||
<para /></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
|
33
src/linux.cc
33
src/linux.cc
@ -2092,7 +2092,7 @@ void get_battery_short_status(char *buffer, unsigned int n, const char *bat)
|
||||
}
|
||||
}
|
||||
|
||||
int get_battery_perct(const char *bat)
|
||||
int _get_battery_perct(const char *bat)
|
||||
{
|
||||
static int rep = 0;
|
||||
int idx;
|
||||
@ -2103,8 +2103,6 @@ int get_battery_perct(const char *bat)
|
||||
snprintf(acpi_path, 127, ACPI_BATTERY_BASE_PATH "/%s/state", bat);
|
||||
snprintf(sysfs_path, 127, SYSFS_BATTERY_BASE_PATH "/%s/uevent", bat);
|
||||
|
||||
init_batteries();
|
||||
|
||||
idx = get_battery_idx(bat);
|
||||
|
||||
/* don't update battery too often */
|
||||
@ -2195,6 +2193,35 @@ int get_battery_perct(const char *bat)
|
||||
return last_battery_perct[idx];
|
||||
}
|
||||
|
||||
int get_battery_perct(const char *bat)
|
||||
{
|
||||
int idx, n = 0, total_capacity = 0, remaining_capacity;;
|
||||
#define BATTERY_LEN 8
|
||||
char battery[BATTERY_LEN];
|
||||
|
||||
init_batteries();
|
||||
|
||||
/* Check if user asked for the mean percentage of all batteries. */
|
||||
if (!strcmp(bat, "all")) {
|
||||
for (idx = 0; idx < MAX_BATTERY_COUNT; idx++) {
|
||||
snprintf(battery, BATTERY_LEN - 1, "BAT%d", idx);
|
||||
#undef BATTERY_LEN
|
||||
remaining_capacity = _get_battery_perct(battery);
|
||||
if (remaining_capacity > 0) {
|
||||
total_capacity += remaining_capacity;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
if (n == 0)
|
||||
return 0;
|
||||
else
|
||||
return total_capacity / n;
|
||||
} else {
|
||||
return _get_battery_perct(bat);
|
||||
}
|
||||
}
|
||||
|
||||
double get_battery_perct_bar(struct text_object *obj)
|
||||
{
|
||||
int idx;
|
||||
|
Loading…
x
Reference in New Issue
Block a user