mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-15 17:47:09 +00:00
Compute mean percentage for multiple batteries.
If a laptop has multiple batteries, compute the mean percentage if the user asks for 'all' instead of a specific battery.
This commit is contained in:
parent
120d6e1f94
commit
ad92c60d6b
19
src/linux.cc
19
src/linux.cc
@ -2095,7 +2095,8 @@ 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;
|
static int rep = 0;
|
||||||
int idx;
|
int idx, n = 0, total_capacity = 0;
|
||||||
|
char battery[8];
|
||||||
char acpi_path[128];
|
char acpi_path[128];
|
||||||
char sysfs_path[128];
|
char sysfs_path[128];
|
||||||
int remaining_capacity = -1;
|
int remaining_capacity = -1;
|
||||||
@ -2105,6 +2106,22 @@ int get_battery_perct(const char *bat)
|
|||||||
|
|
||||||
init_batteries();
|
init_batteries();
|
||||||
|
|
||||||
|
if (!strcmp(bat, "all")) {
|
||||||
|
for (idx = 0; idx < MAX_BATTERY_COUNT; idx++) {
|
||||||
|
snprintf(battery, sizeof(battery) - 1, "BAT%d", idx);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
idx = get_battery_idx(bat);
|
idx = get_battery_idx(bat);
|
||||||
|
|
||||||
/* don't update battery too often */
|
/* don't update battery too often */
|
||||||
|
Loading…
Reference in New Issue
Block a user