diff options
author | Leandro A. F. Pereira <leandro@hardinfo.org> | 2007-03-03 16:19:51 +0000 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2007-03-03 16:19:51 +0000 |
commit | f7ab0cb977df0d6eba533a245c93da582b9f5f84 (patch) | |
tree | 1e6c3b94103371e6248391e6f56d0652ffdf0d90 /hardinfo2/arch | |
parent | 6209464ea2c3bc3763bf6170bb4c54a2bfe2d1f4 (diff) |
Better APM battery support
Diffstat (limited to 'hardinfo2/arch')
-rw-r--r-- | hardinfo2/arch/linux/common/battery.h | 56 | ||||
-rw-r--r-- | hardinfo2/arch/linux/common/uptime.h | 1 |
2 files changed, 44 insertions, 13 deletions
diff --git a/hardinfo2/arch/linux/common/battery.h b/hardinfo2/arch/linux/common/battery.h index 7b47fa90..919dc65d 100644 --- a/hardinfo2/arch/linux/common/battery.h +++ b/hardinfo2/arch/linux/common/battery.h @@ -16,6 +16,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include <time.h> + static void __scan_battery_acpi(void) { @@ -130,22 +132,52 @@ __scan_battery_acpi(void) static void __scan_battery_apm(void) { - FILE *procapm; - int percentage; - char trash[10]; + FILE *procapm; + static char *sremaining = NULL, *stotal = NULL; + static unsigned int last_time = 0; + static int percentage = 0; + int ac_bat; + float apm_bios_ver, apm_drv_ver; + char trash[10]; - procapm = fopen("/proc/apm", "r"); - if (!procapm) - return; - - fscanf(procapm, "%s %s %s %s %s %s %d%%", - trash, trash, trash, trash, trash, trash, &percentage); - fclose(procapm); + if (last_time == 0) { + last_time = time(NULL); + sremaining = g_strdup("Estimating"); + stotal = g_strdup("Estimating"); + } + + if ((procapm = fopen("/proc/apm", "r"))) { + int old_percentage = percentage; + + fscanf(procapm, "%f %f %s 0x%x %s %s %d%%", + &apm_drv_ver, &apm_bios_ver, trash, + &ac_bat, trash, trash, &percentage); + fclose(procapm); + + if (old_percentage - percentage > 0) { + g_free(sremaining); + g_free(stotal); + + int secs_remaining = (time(NULL) - last_time) * percentage / + (old_percentage - percentage); + sremaining = seconds_to_string(secs_remaining); + stotal = seconds_to_string((secs_remaining * 100) / percentage); + + last_time = time(NULL); + } + } battery_list = g_strdup_printf("%s\n[Battery (APM)]\n" - "Charge=%d%%\n", + "Charge=%d%%\n" + "Remaining Charge=%s of %s\n" + "Using=%s\n" + "APM driver version=%.2f\n" + "APM BIOS version=%.2f\n", battery_list, - percentage); + percentage, + sremaining, stotal, + ac_bat ? "AC Power" : "Battery", + apm_drv_ver, apm_bios_ver); } static void diff --git a/hardinfo2/arch/linux/common/uptime.h b/hardinfo2/arch/linux/common/uptime.h index cf339bf3..9225c85c 100644 --- a/hardinfo2/arch/linux/common/uptime.h +++ b/hardinfo2/arch/linux/common/uptime.h @@ -50,7 +50,6 @@ computer_get_formatted_uptime() /* FIXME: Use ngettext */ #define plural(x) ((x > 1) ? "s" : "") - if (ui->days < 1) { if (ui->hours < 1) { tmp = |