summaryrefslogtreecommitdiff
path: root/hardinfo2
diff options
context:
space:
mode:
authorLeandro A. F. Pereira <leandro@hardinfo.org>2007-03-03 16:19:51 +0000
committerLeandro A. F. Pereira <leandro@hardinfo.org>2007-03-03 16:19:51 +0000
commitf7ab0cb977df0d6eba533a245c93da582b9f5f84 (patch)
tree1e6c3b94103371e6248391e6f56d0652ffdf0d90 /hardinfo2
parent6209464ea2c3bc3763bf6170bb4c54a2bfe2d1f4 (diff)
Better APM battery support
Diffstat (limited to 'hardinfo2')
-rw-r--r--hardinfo2/arch/linux/common/battery.h56
-rw-r--r--hardinfo2/arch/linux/common/uptime.h1
-rw-r--r--hardinfo2/hardinfo.h3
-rw-r--r--hardinfo2/util.c30
4 files changed, 76 insertions, 14 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 =
diff --git a/hardinfo2/hardinfo.h b/hardinfo2/hardinfo.h
index e05521d3..97d3aeea 100644
--- a/hardinfo2/hardinfo.h
+++ b/hardinfo2/hardinfo.h
@@ -87,7 +87,8 @@ void nonblock_sleep(guint msec);
void open_url(gchar *url);
GSList *modules_load_selected(void);
GSList *modules_load_all(void);
-ModuleAbout *module_get_about(ShellModule *module);
+ModuleAbout *module_get_about(ShellModule *module);
+gchar *seconds_to_string(unsigned int seconds);
void module_entry_scan_all_except(ModuleEntry *entries, gint except_entry);
void module_entry_scan_all(ModuleEntry *entries);
diff --git a/hardinfo2/util.c b/hardinfo2/util.c
index 288dda6c..265ebd3a 100644
--- a/hardinfo2/util.c
+++ b/hardinfo2/util.c
@@ -33,6 +33,36 @@
#define MiB 1048576
#define GiB 1073741824
+gchar *seconds_to_string(unsigned int seconds)
+{
+ unsigned int hours, minutes, days;
+
+ minutes = seconds / 60;
+ hours = minutes / 60;
+ minutes %= 60;
+ days = hours / 24;
+ hours %= 24;
+
+#define plural(x) ((x > 1) ? "s" : "")
+
+ if (days < 1) {
+ if (hours < 1) {
+ return g_strdup_printf("%d minute%s", minutes,
+ plural(minutes));
+ } else {
+ return g_strdup_printf("%d hour%s, %d minute%s",
+ hours,
+ plural(hours), minutes,
+ plural(minutes));
+ }
+ }
+
+ return g_strdup_printf("%d day%s, %d hour%s and %d minute%s",
+ days, plural(days), hours,
+ plural(hours), minutes,
+ plural(minutes));
+}
+
inline gchar *size_human_readable(gfloat size)
{
if (size < KiB)