From c4bf55b5423e679b7e0c618b3490dbf3f2d8db42 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Sun, 26 Mar 2006 01:47:55 +0000 Subject: [PATCH] freebsd battery patch git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@613 7f574dfc-610e-0410-a909-a81674777703 --- AUTHORS | 1 + ChangeLog | 1 + src/freebsd.c | 36 ++++++++++++++++++++++++++++++------ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/AUTHORS b/AUTHORS index 18e578e4..2a5d6a3d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -128,6 +128,7 @@ Pascal Eberhard Petr Holub fix autotools on FreeBSD in autogen.sh + Improved battery readout on FreeBSD Philip Kovacs tcp port monitor with hashing functionality diff --git a/ChangeLog b/ChangeLog index 53532d66..f15545f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ 2006-03-25 * Added XMMS2 patch 1456203 from Lassi Selander + * Added FreeBSD battery patch 1456008 from Petr Holub 2006-03-21 * Fixed ${top(_mem)} related code on FreeBSD (with help of Petr diff --git a/src/freebsd.c b/src/freebsd.c index 414f79c7..14c103b4 100644 --- a/src/freebsd.c +++ b/src/freebsd.c @@ -347,17 +347,41 @@ get_acpi_temperature(int fd) void get_battery_stuff(char *buf, unsigned int n, const char *bat) { - int battime; + int battime, batcapacity, batstate, ac; if (GETSYSCTL("hw.acpi.battery.time", battime)) (void) fprintf(stderr, "Cannot read sysctl \"hw.acpi.battery.time\"\n"); + if (GETSYSCTL("hw.acpi.battery.life", batcapacity)) + (void) fprintf(stderr, + "Cannot read sysctl \"hw.acpi.battery.life\"\n"); + + if (GETSYSCTL("hw.acpi.battery.state", batstate)) + (void) fprintf(stderr, + "Cannot read sysctl \"hw.acpi.battery.state\"\n"); + + if (GETSYSCTL("hw.acpi.acline", ac)) + (void) fprintf(stderr, + "Cannot read sysctl \"hw.acpi.acline\"\n"); + + if (batstate == 1) { + if (battime != -1) + snprintf(buf, n, "remaining %d%% (%d:%2.2d)", + batcapacity, battime / 60, battime % 60); + else + /* no time estimate available yet */ + snprintf(buf, n, "remaining %d%%", + batcapacity); + if (ac == 1) + (void) fprintf(stderr, "Discharging while on AC!\n"); + } else { + snprintf(buf, n, batstate == 2 ? "charging (%d%%)" : "charged (%d%%)", batcapacity); + if (batstate != 2 && batstate != 0) + (void) fprintf(stderr, "Unknow battery state %d!\n", batstate); + if (ac == 0) + (void) fprintf(stderr, "Charging while not on AC!\n"); + } - if (battime != -1) - snprintf(buf, n, "Discharging, remaining %d:%2.2d", - battime / 60, battime % 60); - else - snprintf(buf, n, "Battery is charging"); } int