* battstat_applet patches
@ 2002-09-06 3:08 Troy Schultz
0 siblings, 0 replies; only message in thread
From: Troy Schultz @ 2002-09-06 3:08 UTC (permalink / raw)
To: ACPI Development - Sourceforge; +Cc: Daniel Wagenaar
[-- Attachment #1: Type: text/plain, Size: 437 bytes --]
I have just finished several changes to the battstat_applet 2.0.13 to
work with the latest ACPI. The changes also add battery time remaining
in the tooltip for the applet. These have been tested on my Compaq
Presario 2710 with kernel 2.4.19 and ACPI version 20020821.
The original battstat_applet source can be downloaded from
http://sourceforge.net/projects/battstat/
If anyone is interested here are my patches;
- Best Regards
[-- Attachment #2: battstat_applet-2.0.13-patch.diff --]
[-- Type: text/plain, Size: 11366 bytes --]
--- acpi-linux.c.orig Wed Sep 4 17:40:08 2002
+++ acpi-linux.c Thu Sep 5 22:35:51 2002
@@ -21,6 +21,12 @@
// ACPI battery read-out functions for Linux >= 2.4.12
// October 2001 by Lennart Poettering <lennart-mdGvqq1h2p8n5izryJqWLw@public.gmane.org>
+/* Additional changes September 2002 by Troy Schultz <tschultz-zzOxFVvAfJPQT0dZR+AlfA@public.gmane.org>
+ - changed acpi handling for newer format
+ - added support for battery time remaining
+ - added code to prevent division by zero, returns zero result
+*/
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -91,13 +97,13 @@
// the ACPI kernel interface in /proc
gboolean acpi_linux_read(struct apm_info *apminfo)
{
- guint32 max_capacity, low_capacity, critical_capacity, remain;
+ guint32 max_capacity, low_capacity, critical_capacity, remain, present_rate;
gboolean charging, ac_online;
FILE *f;
// apminfo.ac_line_status must be one when on ac power
// apminfo.battery_status must be 0 for high, 1 for low, 2 for critical, 3 for charging
- // apminfo.battery_percentage must contain batter charge percentage
+ // apminfo.battery_percentage must contain battery charge percentage
// apminfo.battery_flags & 0x8 must be nonzero when charging
g_assert(apminfo);
@@ -106,11 +112,11 @@
low_capacity = 0;
critical_capacity = 0;
- if ((f = fopen("/proc/acpi/battery/1/info", "r")))
+ if ((f = fopen("/proc/acpi/battery/BAT1/info", "r")))
{
- max_capacity = al_get_field_int(f, "Design Capacity");
- low_capacity = al_get_field_int(f, "Design Capacity Warning");
- critical_capacity = al_get_field_int(f, "Design Capacity Low");
+ max_capacity = al_get_field_int(f, "last full capacity");
+ low_capacity = al_get_field_int(f, "design capacity warning");
+ critical_capacity = al_get_field_int(f, "design capacity low");
fclose(f);
}
@@ -121,35 +127,45 @@
charging = FALSE;
remain = 0;
- if ((f = fopen("/proc/acpi/battery/1/status", "r")))
+ if ((f = fopen("/proc/acpi/battery/BAT1/state", "r")))
{
gchar *s;
gchar tmp[256];
- if ((s = al_get_field(f, "State", tmp, sizeof(tmp))))
+ if ((s = al_get_field(f, "charging state", tmp, sizeof(tmp))))
charging = strcmp(s, "charging") == 0;
- remain = al_get_field_int(f, "Remaining Capacity");
+ present_rate = al_get_field_int(f, "present rate");
+ remain = al_get_field_int(f, "remaining capacity");
fclose(f);
}
ac_online = FALSE;
- if ((f = fopen("/proc/acpi/ac_adapter/0/status", "r")))
+ if ((f = fopen("/proc/acpi/ac_adapter/ACAD/state", "r")))
{
gchar *s;
gchar tmp[256];
- if ((s = al_get_field(f, "Status", tmp, sizeof(tmp))))
+ if ((s = al_get_field(f, "state", tmp, sizeof(tmp))))
ac_online = strcmp(s, "on-line") == 0;
fclose(f);
}
+ if( present_rate > 0 ) {
+ apminfo->battery_time = (remain*60)/present_rate;
+ } else {
+ apminfo->battery_time = 0;
+ }
apminfo->ac_line_status = ac_online ? 1 : 0;
apminfo->battery_status = remain < low_capacity ? 1 : remain < critical_capacity ? 2 : 0;
- apminfo->battery_percentage = (int) (remain/(float)max_capacity*100);
+ if( max_capacity > 0 ){
+ apminfo->battery_percentage = (int) (remain/(float)max_capacity*100);
+ } else {
+ apminfo->battery_percentage = 0;
+ }
apminfo->battery_flags = charging ? 0x8 : 0;
return TRUE;
--- battstat_applet.c.orig Thu Sep 5 22:46:40 2002
+++ battstat_applet.c Thu Sep 5 22:21:23 2002
@@ -20,6 +20,10 @@
$Id: battstat_applet.c,v 1.23 2001/11/04 23:41:22 jdthood Exp $
*/
+/* Additional changes September 2002 by Troy Schultz <tschultz-zzOxFVvAfJPQT0dZR+AlfA@public.gmane.org>
+ - added support for time remaining
+*/
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -316,6 +320,8 @@
static guint last_batt_state=1000;
static guint last_pixmap_index=1000;
static guint last_charging=1000;
+ guint batt_remain_Hr;
+ guint batt_remain_Min;
guint batt_life;
guint acline_status;
guint batt_state;
@@ -374,6 +380,8 @@
batt_state = apminfo.battery_status;
batt_life = (guint) apminfo.battery_percentage;
charging = (apminfo.battery_flags & 0x8) ? TRUE : FALSE;
+ batt_remain_Hr = (guint) apminfo.battery_time / 60;
+ batt_remain_Min = (guint) apminfo.battery_time % 60;
#else
acline_status = 1;
batt_state = 0;
@@ -415,8 +423,8 @@
) {
/* Warn that battery dropped below red_val */
if(battery->lowbattnotification) {
- snprintf(new_label, sizeof(new_label),_("Battery low (%d%%) and AC is offline"),
- batt_life);
+ snprintf(new_label, sizeof(new_label),_("Battery low (%d%%) [%d:%d remain] and AC is offline"),
+ batt_life,batt_remain_Hr, batt_remain_Min);
gnome_warning_dialog(new_label);
if(battery->beep)
@@ -457,12 +465,12 @@
if(!battery->showbattery && !battery->showpercent) {
if(acline_status == 0) {
snprintf(new_label, sizeof(new_label),
- _("System is running on battery power\nBattery: %d%% (%s)"),
- batt_life, _(status[batt_state]));
+ _("System is running on battery power.\n Battery: %d%% (%s) [%d:%d remain]"),
+ batt_life, _(status[batt_state]),batt_remain_Hr, batt_remain_Min);
} else {
snprintf(new_label, sizeof(new_label),
- _("System is running on AC power\nBattery: %d%% (%s)"),
- batt_life, _(status[batt_state]));
+ _("System is running on AC power.\n Battery: %d%% (%s) [%d:%d remain]"),
+ batt_life, _(status[batt_state]), batt_remain_Hr, batt_remain_Min);
}
} else {
if(acline_status == 0) {
@@ -615,16 +623,16 @@
snprintf(new_string, sizeof(new_string),
/* This string will display as a tooltip over the battery frame
when the computer is using battery power.*/
- _("System is running on battery power. Battery: %d%% (%s)"),
+ _("System is running on battery power.\n Battery: %d%% (%s) [%d:%d remain]"),
batt_life,
- _(status[batt_state]));
+ _(status[batt_state]),batt_remain_Hr, batt_remain_Min);
} else {
snprintf(new_string, sizeof(new_string),
/* This string will display as a tooltip over the battery frame
when the computer is using AC power.*/
- _("System is running on AC power. Battery: %d%% (%s)"),
+ _("System is running on AC power. Battery: %d%% (%s) [%d:%d remain]"),
batt_life,
- _(status[batt_state]));
+ _(status[batt_state]),batt_remain_Hr, batt_remain_Min);
}
} else {
if(acline_status == 0) {
@@ -648,9 +656,9 @@
/* Displayed as a tooltip over the battery meter when there is
a battery present. %d will hold the current charge and %s will
hold the status of the battery, (High, Low, Critical, Charging. */
- (_("Battery: %d%% (%s)")),
+ (_("Battery: %d%% (%s) [%d:%d remain]")),
batt_life,
- _(status[batt_state]));
+ _(status[batt_state]),batt_remain_Hr, batt_remain_Min);
} else {
snprintf(new_string, sizeof(new_string),
/* Displayed as a tooltip over the battery meter when no
@@ -668,7 +676,8 @@
gettext(new_string),
NULL);
- if (DEBUG) printf("Percent: %d, Status: %s\n", batt_life, status[batt_state]);
+ if (DEBUG) printf("Percent: %d [%d:%d remain], Status: %s\n", batt_life, batt_remain_Hr,
+ batt_remain_Min, status[batt_state]);
}
last_charging = charging;
@@ -795,6 +804,8 @@
guint acline_status;
guint batt_state;
guint batt_life;
+ guint batt_remain_Hr;
+ guint batt_remain_Min;
gchar *status[]={
/* The following four messages will be displayed as tooltips over
the battery meter.
@@ -824,6 +835,8 @@
acline_status = apminfo.ac_line_status ? 1 : 0;
batt_state = apminfo.battery_status;
batt_life = apminfo.battery_percentage;
+ batt_remain_Hr = (guint) apminfo.battery_time / 60;
+ batt_remain_Min = (guint) apminfo.battery_time % 60;
#else
acline_status = 1;
batt_state = 0;
@@ -893,15 +906,15 @@
/* This string will display as a tooltip over the status frame
when the computer is using battery power and the battery meter
and percent meter is hidden by the user.*/
- _("System is running on battery power. Battery: %d%% (%s)"),
- batt_life, _(status[batt_state]));
+ _("System is running on battery power.\n Battery: %d%% (%s) [%d:%d remain]"),
+ batt_life, _(status[batt_state]),batt_remain_Hr, batt_remain_Min);
} else {
snprintf(new_label, sizeof(new_label),
/* This string will display as a tooltip over the status frame
when the computer is using AC power and the battery meter
and percent meter is hidden by the user.*/
- _("System is running on AC power. Battery: %d%% (%s)"),
- batt_life, _(status[batt_state]));
+ _("System is running on AC power.\n Battery: %d%% (%s) [%d:%d remain]"),
+ batt_life, _(status[batt_state]),batt_remain_Hr, batt_remain_Min);
}
gtk_tooltips_set_tip (battstat->ac_tip,
battstat->eventstatus,
@@ -973,16 +986,16 @@
/* This string will display as a tooltip over the status frame
when the computer is using battery power and the battery meter
and percent meter is hidden by the user.*/
- _("System is running on battery power\nBattery: %d%% (%s)"),
- batt_life, _(status[batt_state]));
+ _("System is running on battery power.\n Battery: %d%% (%s) [%d:%d remain]"),
+ batt_life, _(status[batt_state]),batt_remain_Hr, batt_remain_Min);
} else {
/* 1 = AC power. I should really test it explicitly here. */
snprintf(new_label, sizeof(new_label),
/* This string will display as a tooltip over the status frame
when the computer is using AC power and the battery meter
and percent meter is hidden by the user.*/
- _("System is running on AC power\nBattery: %d%% (%s)"),
- batt_life, _(status[batt_state]));
+ _("System is running on AC power.\n Battery: %d%% (%s) [%d:%d remain]"),
+ batt_life, _(status[batt_state]),batt_remain_Hr, batt_remain_Min);
}
gtk_tooltips_set_tip (battstat->ac_tip,
battstat->eventstatus,
@@ -994,13 +1007,13 @@
snprintf(new_label, sizeof(new_label),
/* This string will display as a tooltip over the status frame
when the computer is using battery power.*/
- _("System is running on battery power"));
+ _("System is running on battery power."));
} else {
/* 1 = AC power. I should really test it explicitly here. */
snprintf(new_label, sizeof(new_label),
/* This string will display as a tooltip over the status frame
when the computer is using AC power.*/
- _("System is running on AC power"));
+ _("System is running on AC power."));
}
gtk_tooltips_set_tip (battstat->ac_tip,
battstat->eventstatus,
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2002-09-06 3:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-06 3:08 battstat_applet patches Troy Schultz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox