Hi,

suffering from the same problems, I hacked up a working combination of
libacpi + yacpi (which I use) for 2.6.25.  Unfortunately the patch
needs to change the API as I really needed to get to the
global->sysstyle.

So when applying these patches, the so-number needs to be bumped.  In
the README I see that there is another change outstanding
neccessitating such an increment, namely exporting the acpi version in
the structure.  Maybe this can be done together?

Also the new version is not backwards compatible, i.e. it simply
replaces the file names by the new versions.  It should be easy
however to add probes for both versions so that we are backward
compatible.  I was simply not sure how to do that in a suiting elegant
way ;)

Cheers
  Detlev

diff -ur orig/libacpi-0.2/libacpi.c libacpi-0.2/libacpi.c
--- orig/libacpi-0.2/libacpi.c	2008-06-09 18:56:56.000000000 +0200
+++ libacpi-0.2/libacpi.c	2008-06-08 18:23:33.000000000 +0200
@@ -17,7 +17,7 @@
 
 static int read_acpi_battinfo(const int num, const int sysstyle);
 static int read_acpi_battalarm(const int num, const int sysstyle);
-static int read_acpi_battstate(const int num);
+static int read_acpi_battstate(const int num, const int sysstyle);
 static void read_acpi_thermalzones(global_t *globals);
 
 typedef struct {
@@ -195,6 +195,7 @@
 			snprintf(binfo->alarm_file, MAX_NAME, PROC_ACPI "battery/%s/alarm", names[i]);
 		}
 		read_acpi_battinfo(i, globals->sysstyle);
+		read_acpi_battstate(i, globals->sysstyle);
 		read_acpi_battalarm(i, globals->sysstyle);
 		free(names[i]);
 	}
@@ -536,17 +537,17 @@
 			return NOT_PRESENT;
 		}
 
-		snprintf(sysfile, MAX_NAME, "%s/charge_full_design", info->info_file);
+		snprintf(sysfile, MAX_NAME, "%s/energy_full_design", info->info_file);
 		if((buf = get_acpi_content(sysfile)) == NULL)
 			return NOT_SUPPORTED;
 		info->design_cap = strtol(buf, NULL, 10);
 
-		snprintf(sysfile, MAX_NAME, "%s/charge_full", info->info_file);
+		snprintf(sysfile, MAX_NAME, "%s/energy_full", info->info_file);
 		if((buf = get_acpi_content(sysfile)) == NULL)
 			return NOT_SUPPORTED;
 		info->last_full_cap = strtol(buf, NULL, 10);
 
-		snprintf(sysfile, MAX_NAME, "%s/charge_now", info->info_file);
+		snprintf(sysfile, MAX_NAME, "%s/energy_now", info->info_file);
 		if((buf = get_acpi_content(sysfile)) == NULL)
 			return NOT_SUPPORTED;
 		info->remaining_cap = strtol(buf, NULL, 10);
@@ -610,11 +611,29 @@
 
 /* read information for battery num, return 0 on success or negative values on error */
 static int
-read_acpi_battstate(const int num){
+read_acpi_battstate(const int num, const int sysstyle){
 	char *buf = NULL;
 	char *tmp = NULL;
 	battery_t *info = &batteries[num];
 	unsigned int i = 0;
+	char sysfile[MAX_NAME];
+
+	if(sysstyle)
+	{
+		snprintf(sysfile, MAX_NAME, "%s/status", info->info_file);
+		if((buf = get_acpi_content(sysfile)) == NULL)
+			return NOT_SUPPORTED;
+		if(!strcmp(buf, "Discharging"))
+			info->charge_state = C_DISCHARGE;
+		else if(!strcmp(buf, "Charging"))
+			info->charge_state = C_CHARGE;
+		else if(!strcmp(buf, "Full"))
+			info->charge_state = C_CHARGED;
+		else
+			info->charge_state = C_NOINFO;
+			
+		return SUCCESS;
+	}
 
 	if((buf = get_acpi_content(info->state_file)) == NULL)
 		return NOT_SUPPORTED;
@@ -700,10 +719,10 @@
 /* read/refresh information about a given battery num
  * returns 0 on SUCCESS, negative values on errors */
 int
-read_acpi_batt(const int num){
+read_acpi_batt(const int num, global_t *globals){
 	if(num > MAX_ITEMS) return ITEM_EXCEED;
-	read_acpi_battstate(num);
-	read_acpi_battalarm(num, 0);
+	read_acpi_battstate(num, globals->sysstyle);
+	read_acpi_battalarm(num, globals->sysstyle);
 	calc_remain_perc(num);
 	calc_remain_chargetime(num);
 	calc_remain_time(num);
diff -ur orig/libacpi-0.2/libacpi.h libacpi-0.2/libacpi.h
--- orig/libacpi-0.2/libacpi.h	2008-06-09 18:56:56.000000000 +0200
+++ libacpi-0.2/libacpi.h	2008-06-08 15:19:58.000000000 +0200
@@ -237,7 +237,7 @@
  * a struct with it
  * @param num number of battery
  */
-int read_acpi_batt(const int num);
+int read_acpi_batt(const int num, global_t *globals);
 /**
  * Looks up if the ac adapter is plugged in or not
  * and sets the values in a struct
diff -ur orig/libacpi-0.2/test-libacpi.c libacpi-0.2/test-libacpi.c
--- orig/libacpi-0.2/test-libacpi.c	2008-06-09 18:56:56.000000000 +0200
+++ libacpi-0.2/test-libacpi.c	2008-06-08 15:21:44.000000000 +0200
@@ -43,7 +43,7 @@
 		for(i=0;i<global->batt_count;i++){
 			binfo = &batteries[i];
 			/* read current battery values */
-			read_acpi_batt(i);
+			read_acpi_batt(i, global);
 
 			if(binfo->present)
 			{
diff -ur orig/yacpi-3.0/yacpi.c yacpi-3.0/yacpi.c
--- orig/yacpi-3.0/yacpi.c	2007-08-09 18:47:47.000000000 +0200
+++ yacpi-3.0/yacpi.c	2008-06-08 17:52:27.000000000 +0200
@@ -362,7 +363,7 @@
 		binfo = &batteries[i];
 		if(!binfo) return;
 		/* read current battery values */
-		read_acpi_batt(i);
+		read_acpi_batt(i, global);
 		if(binfo && binfo->present){
 			if(t) printf("| %s = %d%%", binfo->name, binfo->percentage);
 			else if (COLS > 48){
-- 
In God we trust.  All others we monitor
                       -- NSA motto

Reply via email to