Package: xfce4-battery-plugin
Version: 0.5.0-7
Severity: normal
Tags: patch

The following kernel patch corrects the meaning of the contents of the 
sysfs battery status directory, but breaks the "time remaining" 
calculation in xfce4-battery-plugin.

current_now is should contain a value of the current being drawn at this 
instant, but in older kernels would contain whatever units the ACPI 
interface reported, which could be either current or power.

The attached patch fixes things, but may break existing installations 
with older kernels.


commit 558073dd56707864f09d563b64e7c37c021e89d2
Author: Alexey Starikovskiy <[EMAIL PROTECTED]>
Date:   Fri Nov 21 22:41:01 2008 +0800

    ACPI: battery: Convert discharge energy rate to current properly

    ACPI battery interface reports its state either in mW or in mA, and
    discharge rate in your case is reported in mW. power_supply interface
    does not have such a parameter, so current_now parameter is used
    for all cases. But in case of mW, reported discharge should
    be converted into mA.

    Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
    Tested-by: Ferenc Wagner <[EMAIL PROTECTED]>
    Signed-off-by: Len Brown <[EMAIL PROTECTED]>


-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing'), (500, 'stable'), (99, 
'experimental')
Architecture: i386 (i686)

Kernel: Linux 2.6.28-rc7
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages xfce4-battery-plugin depends on:
ii  libatk1.0-0                   1.22.0-1   The ATK accessibility toolkit
ii  libc6                         2.7-16     GNU C Library: Shared libraries
ii  libcairo2                     1.6.4-6.1  The Cairo 2D vector graphics libra
ii  libglib2.0-0                  2.16.6-1   The GLib library of C routines
ii  libgtk2.0-0                   2.12.11-4  The GTK+ graphical user interface 
ii  libpango1.0-0                 1.20.5-3   Layout and rendering of internatio
ii  libxfce4util4                 4.4.2-3    Utility functions library for Xfce
ii  libxfcegui4-4                 4.4.2-4    Basic GUI C functions for Xfce4
ii  xfce4-panel                   4.4.2-6    The Xfce4 desktop environment pane

xfce4-battery-plugin recommends no packages.

xfce4-battery-plugin suggests no packages.

-- no debconf information
--- xfce4-battery-plugin-0.5.0.old/panel-plugin/libacpi.c	2008-12-02 21:58:22.195437494 +0000
+++ xfce4-battery-plugin-0.5.0/panel-plugin/libacpi.c	2008-12-02 21:56:43.200260028 +0000
@@ -726,6 +726,7 @@
 	DIR *sysfs;
 	struct dirent *propety;
 	char *name;
+	int energy_in_watts = 0;
 
 	sysfs = opendir(batteries[battery]);
 	if (sysfs == 0)
@@ -769,6 +770,9 @@
 			sprintf(buf,"%s/%s",batteries[battery], name);
 			acpistate->rcapacity = read_sysfs_int(buf);
 			acpistate->percentage = (((float) acpistate->rcapacity)/acpiinfo->last_full_capacity) * 100;
+			if (strcmp(name,"energy_now") == 0) {
+				energy_in_watts = 1;
+			}
 		}
 		if (strcmp(name,"current_now") == 0)
 		{
@@ -776,8 +780,6 @@
 			acpistate->prate = read_sysfs_int(buf);
 			if ( acpistate->prate < 0 )
 				acpistate->prate = 0;
-			if ( acpistate->prate > 0 )
-				acpistate->rtime = (((float) acpistate->rcapacity) / acpistate->prate) * 60;
 		}
 		if (strcmp(name,"voltage_now") == 0)
 		{
@@ -785,6 +787,14 @@
 			acpistate->pvoltage = read_sysfs_int(buf);
 		}
 	}
+
+	if ( acpistate->prate > 0 ) {
+		if (energy_in_watts) {
+			acpistate->prate = (((float) acpistate->prate) * ((float) acpistate->pvoltage) / 1000000.0);
+		}
+		acpistate->rtime = (((float) acpistate->rcapacity) / acpistate->prate) * 60;
+	}
+
 	closedir(sysfs);
 	return acpiinfo->present;
 }

Reply via email to