Re: [ACPI-sppt] ACPI is now ok - but how about status ?

Sebastian Henschel <[email protected]>
Newsgroups gmane.linux.acpi.support
Message-ID <[email protected]>
hola fernando..

* Fernando Caprio Jr <[email protected]> [2003-06-21 11:17 +0200]:

> 	and window maker acpi applet shows nothing.

would you please try the attached patch for wmacpi-1.34. it makes the
battery status available for my machine. the problem is, that wmacpi
only checks if one or more subdirectories in /proc/acpi/battery/ exist
and does not check in /proc/acpi/battery/(BAT1|CMB0|*)/state if it really
exists.

cheers,
 sebastian
-- 
::: sebastian henschel
::: kodeaffe
::: lynx -source http://www.kodeaffe.de/shensche.pub | gpg --import
batt_present.diff (text/plain, 1.6 KB)
diff -Naur wmacpi-1.34/libacpi.c wmacpi/libacpi.c
--- wmacpi-1.34/libacpi.c	2003-06-20 17:43:17.000000000 +0200
+++ wmacpi/libacpi.c	2003-06-20 17:44:40.000000000 +0200
@@ -22,6 +22,29 @@
 /* local proto */
 int acpi_get_design_cap(int battery);
 
+int battery_is_present (char *fnam)
+{
+   FILE *acpi;
+   char buf[512], present[4];
+   char *ptr;
+
+   if (!(acpi = fopen(fnam, "r"))) return 0;
+    
+   fread(buf, 512, 1, acpi);
+   fclose(acpi);
+
+   if ((ptr = strstr(buf, "present")))
+   {
+	   ptr += 25;
+	   sscanf(ptr, "%s", present);
+      if (strstr (present, "no")) return 0;
+   }
+
+   return 1;
+}
+
+
+
 /* see if we have ACPI support and check version */
 int power_init(void)
 {
@@ -60,15 +83,17 @@
     while ((batt = readdir(battdir))) {
 	name = batt->d_name;
 	
-	/* skip . and .. */
-	if (!strncmp(".", name, 1) || !strncmp("..", name, 2))
-	    continue;
-
-	sprintf(batteries[batt_count], "/proc/acpi/battery/%s/state", name);
-	sprintf(battinfo[batt_count], "/proc/acpi/battery/%s/info", name);
-	eprint(1, "battery detected at %s\n", batteries[batt_count]);
-	batt_count++;
-    }
+	   /* skip . and .. */
+	   if (!strncmp(".", name, 1) || !strncmp("..", name, 2)) continue;
+
+	   sprintf(batteries[batt_count], "/proc/acpi/battery/%s/state", name);
+      /* check if battery is really present */
+      if (battery_is_present (batteries[batt_count])) {
+	      sprintf(battinfo[batt_count], "/proc/acpi/battery/%s/info", name);
+	      eprint(1, "battery detected at %s\n", batteries[batt_count]);
+	      batt_count++;
+      }
+   }
     closedir(battdir);
 
     /* tell user some info */
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+9HvfreHfL3pi+bQRAhqOAJ4wnPFSZ8dXxnmr/jjNJpcnVjJdowCfYhpL
bw1AH9z9IieyJgKi5qBJ8aU=
=art1
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.