battstat_applet patches
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
acpi-linux.c renamed from acpi-linux.c.orig +28 -12
@@ -21,6 +21,12 @@// ACPI battery read-out functions for Linux >= 2.4.12 // October 2001 by Lennart Poettering <[email protected]> +/* Additional changes September 2002 by Troy Schultz <[email protected]> +- 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 renamed from battstat_applet.c.orig +36 -23
162 lines not on this page · raw message