mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-06 05:17:57 +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:
parent
4e8212d978
commit
c15f5d485c
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
2006-12-11
|
2006-12-11
|
||||||
* Close pop3/imap sockets.
|
* Close pop3/imap sockets.
|
||||||
|
* Fix outstanding battery issues.
|
||||||
|
|
||||||
2006-12-10
|
2006-12-10
|
||||||
* Fix peek table bug with new portmon code.
|
* Fix peek table bug with new portmon code.
|
||||||
|
56
src/linux.c
56
src/linux.c
@ -1200,6 +1200,7 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat)
|
|||||||
{
|
{
|
||||||
static int rep, rep2;
|
static int rep, rep2;
|
||||||
char acpi_path[128];
|
char acpi_path[128];
|
||||||
|
char tmp_battery[64], tmp_time_left[64];
|
||||||
snprintf(acpi_path, 127, ACPI_BATTERY_BASE_PATH "/%s/state", bat);
|
snprintf(acpi_path, 127, ACPI_BATTERY_BASE_PATH "/%s/state", bat);
|
||||||
|
|
||||||
/* don't update battery too often */
|
/* 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);
|
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 */
|
/* not present */
|
||||||
if (strcmp(present, "no") == 0) {
|
if (strcmp(present, "no") == 0) {
|
||||||
strncpy(last_battery_str, "not present", 64);
|
strncpy(last_battery_str, "not present", 64);
|
||||||
@ -1269,35 +1274,43 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat)
|
|||||||
/* charging */
|
/* charging */
|
||||||
else if (strcmp(charging_state, "charging") == 0) {
|
else if (strcmp(charging_state, "charging") == 0) {
|
||||||
if (acpi_last_full != 0 && present_rate > 0) {
|
if (acpi_last_full != 0 && present_rate > 0) {
|
||||||
snprintf(last_battery_str, 63, "charging %i%% ", (int) (remaining_capacity / acpi_last_full) * 100);
|
/* e.g. charging 75% */
|
||||||
format_seconds(last_battery_str + 14,
|
snprintf(tmp_battery, sizeof(tmp_battery)-1, "charging %i%%",
|
||||||
63 - 14,
|
(int) (((float)remaining_capacity / (float)acpi_last_full) * 100));
|
||||||
(acpi_last_full -
|
/* e.g. 2h 37m */
|
||||||
remaining_capacity) * 60 *
|
format_seconds(tmp_time_left, sizeof(tmp_time_left)-1,
|
||||||
60 / present_rate);
|
(long)((float) ((acpi_last_full - remaining_capacity) * 3600) /
|
||||||
} else if (acpi_last_full != 0
|
(float) present_rate));
|
||||||
&& present_rate <= 0) {
|
/* e.g. charging 75% (2h 37m) */
|
||||||
snprintf(last_battery_str, 64, "charging %d%%",
|
snprintf (last_battery_str, sizeof(last_battery_str)-1,
|
||||||
remaining_capacity * 100 /
|
"%s (%s)", tmp_battery, tmp_time_left);
|
||||||
acpi_last_full);
|
|
||||||
|
} 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 {
|
} else {
|
||||||
strncpy(last_battery_str, "charging", 63);
|
strncpy(last_battery_str, "charging", sizeof(last_battery_str)-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* discharging */
|
/* discharging */
|
||||||
else if (strncmp(charging_state, "discharging", 64) == 0) {
|
else if (strncmp(charging_state, "discharging", 64) == 0) {
|
||||||
if (present_rate > 0) {
|
if (present_rate > 0) {
|
||||||
snprintf(last_battery_str, 63, "discharging %i%% ", (int)(remaining_capacity / acpi_last_full) * 100);
|
/* e.g. discharging 35% */
|
||||||
format_seconds(last_battery_str + 17, 63 - 17,
|
snprintf(tmp_battery, sizeof(tmp_battery)-1, "discharging %i%%",
|
||||||
(remaining_capacity * 60 *
|
(int) (((float)remaining_capacity / (float)acpi_last_full) * 100));
|
||||||
60) / present_rate);
|
/* 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 */
|
} 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 {
|
} else {
|
||||||
snprintf(last_battery_str, 64,
|
snprintf(last_battery_str, sizeof(last_battery_str)-1,
|
||||||
"discharging %d%%",
|
"discharging %d%%",
|
||||||
remaining_capacity * 100 /
|
(int) ((float) (remaining_capacity * 100) / (float) acpi_last_full));
|
||||||
acpi_last_full);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* charged */
|
/* charged */
|
||||||
@ -1310,8 +1323,7 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat)
|
|||||||
if (acpi_last_full != 0
|
if (acpi_last_full != 0
|
||||||
&& remaining_capacity != acpi_last_full)
|
&& remaining_capacity != acpi_last_full)
|
||||||
snprintf(last_battery_str, 64, "unknown %d%%",
|
snprintf(last_battery_str, 64, "unknown %d%%",
|
||||||
remaining_capacity * 100 /
|
(int) ((float) (remaining_capacity * 100) / (float) acpi_last_full));
|
||||||
acpi_last_full);
|
|
||||||
else
|
else
|
||||||
strncpy(last_battery_str, "AC", 64);
|
strncpy(last_battery_str, "AC", 64);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user