Bug#298766: gnome-applets: battstat don't show correct values at startup on some hardware

Marco Innocenti Marco Innocenti <dot0037@iperbole.bologna.it>, 298766@bugs.debian.org
Wed, 9 Mar 2005 21:21:19 +0100


--u3/rZRmxL6MmkK24
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Package: gnome-applets
Version: 2.8.2-1
Severity: minor
Tags: patch

Battstat on my laptop (Toshiba P20-311) don't show the correct value of the
charge of the battery at startup. I have to wait several minutes to get it.
I've made some test and discoveded that "cat /proc/acpi/battery/BAT1/*"
give the wrong value the first few time.
So I patched battstat_applet.c to get acpiinfo 10 times at startup.
It works for me and don't think would harm others.


-- System Information:
Debian Release: 3.1
  APT prefers unstable
  APT policy: (500, 'unstable'), (101, 'experimental')
Architecture: i386 (i686)
Kernel: Linux 2.6.10-1-686-smp
Locale: LANG=it_IT@euro, LC_CTYPE=it_IT@euro (charmap=ISO-8859-15)

Versions of packages gnome-applets depends on:
ii  gnome-applets-data   2.8.2-1             Various applets for GNOME 2 panel 
ii  gnome-panel          2.8.2-2             launcher and docking facility for 
ii  gstreamer0.8-alsa [g 0.8.7-3             ALSA plugin for GStreamer
ii  gstreamer0.8-esd [gs 0.8.7-3             Enlightened Sound Daemon plugin fo
ii  gstreamer0.8-oss [gs 0.8.7-3             OSS plugin for GStreamer
ii  libapm1              3.2.2-3             Library for interacting with APM d
ii  libart-2.0-2         2.3.17-1            Library of functions for 2D graphi
ii  libatk1.0-0          1.8.0-4             The ATK accessibility toolkit
ii  libbonobo2-0         2.8.1-2             Bonobo CORBA interfaces library
ii  libbonoboui2-0       2.8.1-2             The Bonobo UI library
ii  libc6                2.3.2.ds1-20        GNU C Library: Shared libraries an
ii  libgail-common       1.8.2-1             GNOME Accessibility Implementation
ii  libgail17            1.8.2-1             GNOME Accessibility Implementation
ii  libgconf2-4          2.8.1-4             GNOME configuration database syste
ii  libgcrypt11          1.2.0-11            LGPL Crypto library - runtime libr
ii  libglade2-0          1:2.4.2-2           library to load .glade files at ru
ii  libglib2.0-0         2.6.3-1             The GLib library of C routines
ii  libgnome2-0          2.8.1-2             The GNOME 2 library - runtime file
ii  libgnomecanvas2-0    2.8.0-1             A powerful object-oriented display
ii  libgnomeui-0         2.8.1-3             The GNOME 2 libraries (User Interf
ii  libgnomevfs2-0       2.8.4-2             The GNOME virtual file-system libr
ii  libgnutls11          1.0.16-13           GNU TLS library - runtime library
ii  libgstreamer-plugins 0.8.7-3             Various GStreamer libraries and li
ii  libgstreamer0.8-0    0.8.9-1             Core GStreamer libraries, plugins,
ii  libgtk2.0-0          2.6.2-4             The GTK+ graphical user interface 
ii  libgtop2-2           2.6.0-4             Libraries for gtop system monitori
ii  libice6              4.3.0.dfsg.1-12.0.1 Inter-Client Exchange library
ii  liborbit2            1:2.10.5-0.1        libraries for ORBit2 - a CORBA ORB
ii  libpanel-applet2-0   2.8.2-2             library for GNOME 2 panel applets
ii  libpango1.0-0        1.8.1-1             Layout and rendering of internatio
ii  libpopt0             1.7-5               lib for parsing cmdline parameters
ii  libsm6               4.3.0.dfsg.1-12.0.1 X Window System Session Management
ii  libx11-6             4.3.0.dfsg.1-12.0.1 X Window System protocol client li
ii  libxklavier8         1.03-1              X Keyboard Extension high-level AP
ii  libxml2              2.6.16-3            GNOME XML library
ii  xlibs                4.3.0.dfsg.1-12     X Keyboard Extension (XKB) configu
ii  zlib1g               1:1.2.2-4           compression library - runtime

-- no debconf information

-- 
Ciao
     Marco Innocenti

--u3/rZRmxL6MmkK24
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="battstat.diff"

diff -r -u gnome-applets-2.8.2.orig/battstat/battstat_applet.c gnome-applets-2.8.2/battstat/battstat_applet.c
--- gnome-applets-2.8.2.orig/battstat/battstat_applet.c	2005-03-09 20:58:00.302510520 +0100
+++ gnome-applets-2.8.2/battstat/battstat_applet.c	2005-03-09 17:24:47.000000000 +0100
@@ -232,7 +232,7 @@
 
 #ifdef __linux__
 struct acpi_info acpiinfo;
-gboolean using_acpi;
+gboolean using_acpi, started_now=TRUE;
 int acpi_count;
 #endif
 
@@ -310,6 +310,14 @@
    * Updated by David Moore <dcm@acm.org> 5/29/2003 to poll less and
    *   use ACPI events. */
   if (using_acpi && acpiinfo.event_fd >= 0) {
+    /* By Marco Innocenti <m.innocenti@cineca.it> 09/03/2005
+     * Some hardware need several requests to warm up and give correct results. */
+    if (started_now) {
+	started_now=FALSE;
+	for (acpi_count=1; acpi_count < 10; acpi_count++) {
+	    acpi_linux_read(&apminfo, &acpiinfo);
+	}
+    }
     if (acpi_count <= 0) {
       /* Only call this one out of 30 calls to apm_readinfo() (every 30 seconds)
        * since reading the ACPI system takes CPU cycles. */

--u3/rZRmxL6MmkK24--