Skip to contentSkip to conversation

new patch for battstat_applet-2.0.13

PATCH Troy Schultz 2 participants 2 messages Sep 6, 2002 1 message not in the archive ACPI

lore
Share & tools
lore
#0 lore raw

Sorry, but there was a small problem with the patch I posted. Also I have included some basic instructions for applying the patch.

Here is the patch for battstat_applet, it now includes proper formatting for single digit times.

The original battstat_applet source can be downloaded from
http://sourceforge.net/projects/battstat/

Download the battstat_applet-2.0.13 and extract the source tree, then change to the main directory of the battstat_applet.

To test the patch:
patch -p1 --dry-run -i battstat_applet-2.0.13-patch.diff

To apply the patch if the test was OK:
patch -p1 -i battstat_applet-2.0.13-patch.diff

Then follow the build/install instructions and then you should have a working battstat_applet under gnome.

Not all notebooks return the necessary information from the battery, but if your's does then things should work fine.

Best Regards
- Troy

src/acpi-linux.c renamed from src/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;
src/battstat_applet.c renamed from src/battstat_applet.c.orig +36 -23

162 lines not on this page · raw message

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Il ven, 2002-09-06 alle 19:21, Troy Schultz ha scritto:

Quoted 2 lines

Sorry, but there was a small problem with the patch I posted. Also I have included some basic instructions for applying the patch.

unfortunately you can bet on having BAT1 or anything like that. i have BAT0. the right thing to do is to scan the directory and use the names you find at runtime, not hardcoded ones.

Signature · 5 lines
Federico Di Gregorio
Debian GNU/Linux Developer & Italian Press Contact        [email protected]
INIT.D Developer                                           fog-NGVKUo/i/[email protected]
  Spesso crescere ed andare a vivere da soli è l'unico modo di restare
   bambini.                                             -- Alice Fontana