From f7aeae2c01db5ed7c6795b0195594c4957439955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Tue, 17 Feb 2009 22:19:25 -0700 Subject: [PATCH] Fix shown battery status patch. Fix shown battery status when the battery is not charging any more but is not full charged patch sf.net id #2556056 (thanks Martin). --- ChangeLog | 2 ++ src/linux.c | 58 +++++++++++++++++++++++++++-------------------------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2227328b..002410da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,8 @@ * Fix nvidia memory frequency reading patch sf.net id #2493134 * Patch to clarify things in conky.conf sf.net id #2548805 (thanks Carpathia). + * Fix shown battery status when the battery is not charging any more but + is not full charged patch sf.net id #2556056 (thanks Martin) 2009-02-15 * Added out_to_x diff --git a/src/linux.c b/src/linux.c index 41d7bd1c..8a9386a6 100644 --- a/src/linux.c +++ b/src/linux.c @@ -1665,8 +1665,8 @@ void get_battery_stuff(char *buffer, unsigned int n, const char *bat, int item) else strncpy(last_battery_str[idx], "AC", 64); } - } else if (acpi_bat_fp[idx] != NULL) { - /* ACPI */ + } else if (acpi_bat_fp[idx] != NULL) { + /* ACPI */ int present_rate = -1; int remaining_capacity = -1; char charging_state[64]; @@ -1688,7 +1688,7 @@ void get_battery_stuff(char *buffer, unsigned int n, const char *bat, int item) break; } if (sscanf(b, "last full capacity: %d", - &acpi_last_full[idx]) != 0) { + &acpi_last_full[idx]) != 0) { break; } } @@ -1728,54 +1728,54 @@ void get_battery_stuff(char *buffer, unsigned int n, const char *bat, int item) /* not present */ if (strcmp(present, "no") == 0) { strncpy(last_battery_str[idx], "not present", 64); - /* charging */ + /* charging */ } else if (strcmp(charging_state, "charging") == 0) { if (acpi_last_full[idx] != 0 && present_rate > 0) { /* e.g. charging 75% */ snprintf(last_battery_str[idx], - sizeof(last_battery_str[idx]) - 1, "charging %i%%", - (int) ((remaining_capacity * 100) / acpi_last_full[idx])); + sizeof(last_battery_str[idx]) - 1, "charging %i%%", + (int) ((remaining_capacity * 100) / acpi_last_full[idx])); /* e.g. 2h 37m */ format_seconds(last_battery_time_str[idx], - sizeof(last_battery_time_str[idx]) - 1, - (long) (((acpi_last_full[idx] - remaining_capacity) * - 3600) / present_rate)); + sizeof(last_battery_time_str[idx]) - 1, + (long) (((acpi_last_full[idx] - remaining_capacity) * + 3600) / present_rate)); } else if (acpi_last_full[idx] != 0 && present_rate <= 0) { snprintf(last_battery_str[idx], - sizeof(last_battery_str[idx]) - 1, "charging %d%%", - (int) ((remaining_capacity * 100) / acpi_last_full[idx])); + sizeof(last_battery_str[idx]) - 1, "charging %d%%", + (int) ((remaining_capacity * 100) / acpi_last_full[idx])); snprintf(last_battery_time_str[idx], - sizeof(last_battery_time_str[idx]) - 1, "unknown"); + sizeof(last_battery_time_str[idx]) - 1, "unknown"); } else { strncpy(last_battery_str[idx], "charging", - sizeof(last_battery_str[idx]) - 1); + sizeof(last_battery_str[idx]) - 1); snprintf(last_battery_time_str[idx], - sizeof(last_battery_time_str[idx]) - 1, "unknown"); + sizeof(last_battery_time_str[idx]) - 1, "unknown"); } - /* discharging */ + /* discharging */ } else if (strncmp(charging_state, "discharging", 64) == 0) { if (present_rate > 0) { /* e.g. discharging 35% */ snprintf(last_battery_str[idx], - sizeof(last_battery_str[idx]) - 1, "discharging %i%%", - (int) ((remaining_capacity * 100) / acpi_last_full[idx])); + sizeof(last_battery_str[idx]) - 1, "discharging %i%%", + (int) ((remaining_capacity * 100) / acpi_last_full[idx])); /* e.g. 1h 12m */ format_seconds(last_battery_time_str[idx], - sizeof(last_battery_time_str[idx]) - 1, - (long) ((remaining_capacity * 3600) / present_rate)); + sizeof(last_battery_time_str[idx]) - 1, + (long) ((remaining_capacity * 3600) / present_rate)); } else if (present_rate == 0) { /* Thanks to Nexox for this one */ snprintf(last_battery_str[idx], - sizeof(last_battery_str[idx]) - 1, "full"); + sizeof(last_battery_str[idx]) - 1, "full"); snprintf(last_battery_time_str[idx], - sizeof(last_battery_time_str[idx]) - 1, "unknown"); + sizeof(last_battery_time_str[idx]) - 1, "unknown"); } else { snprintf(last_battery_str[idx], - sizeof(last_battery_str[idx]) - 1, "discharging %d%%", - (int) ((remaining_capacity * 100) / acpi_last_full[idx])); + sizeof(last_battery_str[idx]) - 1, "discharging %d%%", + (int) ((remaining_capacity * 100) / acpi_last_full[idx])); snprintf(last_battery_time_str[idx], - sizeof(last_battery_time_str[idx]) - 1, "unknown"); + sizeof(last_battery_time_str[idx]) - 1, "unknown"); } - /* charged */ + /* charged */ } else if (strncmp(charging_state, "charged", 64) == 0) { /* thanks to Lukas Zapletal */ /* Below happens with the second battery on my X40, @@ -1785,12 +1785,14 @@ void get_battery_stuff(char *buffer, unsigned int n, const char *bat, int item) } else { strcpy(last_battery_str[idx], "charged"); } - /* unknown, probably full / AC */ + /* unknown, probably full / AC */ } else { - if (acpi_last_full[idx] != 0 + if (strncmp(charging_state, "Full", 64) == 0) { + strncpy(last_battery_str[idx], "full", 64); + } else if (acpi_last_full[idx] != 0 && remaining_capacity != acpi_last_full[idx]) { snprintf(last_battery_str[idx], 64, "unknown %d%%", - (int) ((remaining_capacity * 100) / acpi_last_full[idx])); + (int) ((remaining_capacity * 100) / acpi_last_full[idx])); } else { strncpy(last_battery_str[idx], "AC", 64); }