1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-26 04:17:33 +00:00

fix battery issues

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@812 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Philip Kovacs 2006-12-12 01:20:10 +00:00
parent 4e8212d978
commit c15f5d485c
2 changed files with 36 additions and 23 deletions

View File

@ -2,6 +2,7 @@
2006-12-11
* Close pop3/imap sockets.
* Fix outstanding battery issues.
2006-12-10
* Fix peek table bug with new portmon code.

View File

@ -1200,6 +1200,7 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat)
{
static int rep, rep2;
char acpi_path[128];
char tmp_battery[64], tmp_time_left[64];
snprintf(acpi_path, 127, ACPI_BATTERY_BASE_PATH "/%s/state", bat);
/* don't update battery too often */
@ -1262,6 +1263,10 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat)
sscanf(buf, "remaining capacity: %d", &remaining_capacity);
}
/* Hellf[i]re notes that remaining capacity can exceed acpi_last_full */
if (remaining_capacity > acpi_last_full)
acpi_last_full = remaining_capacity; /* normalize to 100% */
/* not present */
if (strcmp(present, "no") == 0) {
strncpy(last_battery_str, "not present", 64);
@ -1269,35 +1274,43 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat)
/* charging */
else if (strcmp(charging_state, "charging") == 0) {
if (acpi_last_full != 0 && present_rate > 0) {
snprintf(last_battery_str, 63, "charging %i%% ", (int) (remaining_capacity / acpi_last_full) * 100);
format_seconds(last_battery_str + 14,
63 - 14,
(acpi_last_full -
remaining_capacity) * 60 *
60 / present_rate);
} else if (acpi_last_full != 0
&& present_rate <= 0) {
snprintf(last_battery_str, 64, "charging %d%%",
remaining_capacity * 100 /
acpi_last_full);
/* e.g. charging 75% */
snprintf(tmp_battery, sizeof(tmp_battery)-1, "charging %i%%",
(int) (((float)remaining_capacity / (float)acpi_last_full) * 100));
/* e.g. 2h 37m */
format_seconds(tmp_time_left, sizeof(tmp_time_left)-1,
(long)((float) ((acpi_last_full - remaining_capacity) * 3600) /
(float) present_rate));
/* e.g. charging 75% (2h 37m) */
snprintf (last_battery_str, sizeof(last_battery_str)-1,
"%s (%s)", tmp_battery, tmp_time_left);
} else if (acpi_last_full != 0 && present_rate <= 0) {
snprintf(last_battery_str, sizeof(last_battery_str)-1, "charging %d%%",
(int) ((float) (remaining_capacity * 100) / (float) acpi_last_full));
} else {
strncpy(last_battery_str, "charging", 63);
strncpy(last_battery_str, "charging", sizeof(last_battery_str)-1);
}
}
/* discharging */
else if (strncmp(charging_state, "discharging", 64) == 0) {
if (present_rate > 0) {
snprintf(last_battery_str, 63, "discharging %i%% ", (int)(remaining_capacity / acpi_last_full) * 100);
format_seconds(last_battery_str + 17, 63 - 17,
(remaining_capacity * 60 *
60) / present_rate);
/* e.g. discharging 35% */
snprintf(tmp_battery, sizeof(tmp_battery)-1, "discharging %i%%",
(int) (((float)remaining_capacity / (float)acpi_last_full) * 100));
/* e.g. 1h 12m */
format_seconds(tmp_time_left, sizeof(tmp_time_left)-1,
(long) ((float)(remaining_capacity * 3600) /
(float)present_rate));
/* e.g. discharging 35% (1h 12m) */
snprintf (last_battery_str, sizeof(last_battery_str)-1,
"%s (%s)", tmp_battery, tmp_time_left);
} else if (present_rate == 0) { /* Thanks to Nexox for this one */
snprintf(last_battery_str, 64, "full");
snprintf(last_battery_str, sizeof(last_battery_str)-1, "full");
} else {
snprintf(last_battery_str, 64,
snprintf(last_battery_str, sizeof(last_battery_str)-1,
"discharging %d%%",
remaining_capacity * 100 /
acpi_last_full);
(int) ((float) (remaining_capacity * 100) / (float) acpi_last_full));
}
}
/* charged */
@ -1310,8 +1323,7 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat)
if (acpi_last_full != 0
&& remaining_capacity != acpi_last_full)
snprintf(last_battery_str, 64, "unknown %d%%",
remaining_capacity * 100 /
acpi_last_full);
(int) ((float) (remaining_capacity * 100) / (float) acpi_last_full));
else
strncpy(last_battery_str, "AC", 64);
}