! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
Battery level is not shown when using ACPI on FreeBSD
Status:
RESOLVED: FIXED
Product:
Xfce4-battery-plugin
Component:
General

Comments

Description Emmanuel Viaud 2007-01-24 20:20:47 CET
Hello.

I am using XFCE 4.4.0 with version 0.5.0 of the battery panel plug-in on FreeBSD 6.2 RELEASE on an IBM Thinkpad T43.

Overview :
The level of the battery (either in percent or in the graphical display) stays at 0 even if the battery is fully loaded.

Steps :
1) load the battery plug-in and check the "display percentage" button

Actual results :
The percentage stays at 0 (and thus an alarm is issued if the AC cord is unplugged)

Expected results :
Display the correct battery level

More details :
The problem seems to lie in the way the acpi functions from libacpi.c & the display functions from battery.c interact.

As a matter of fact, in the read_acpi_state function from libacpi.c, the way of calculating the current state of the battery differs according to the OS :
 - on linux, it uses a formula (line 574) and sets both the percentage and the rcapacity member of the ACPIstate structure
 - on FreeBSD, it only sets the percentage member

But, in battery.c (from line 340), no distinction is made between the two OS and the calculation of the charge value is done in both cases using the rcapacity member (which is still at 0 in the FreeBSD case). Thus, the displayed value is always 0.

A very quick & (very) dirty proof of concept patch is available on http://emmanuel.viaud.free.fr/patch_battery_c. It solves the problem on my computer by actually differentiating between the linux case and the FreeBSD one. With that patch applied, the correct value (the same as the one read by using sysctl by hand) is displayed (the time seems to be correct too).

Hope this helps.
Thanks for your work and best regards.
Comment 1 Emmanuel Viaud 2007-01-24 20:22:42 CET
Created attachment 963 
patch to correct battery display on FreeBSD

Oops, didn't see the attachment link... Here is the patch.
Comment 2 Shigeru Fujiwara 2007-01-28 18:13:55 CET
Created attachment 971 
another patch

This is the another patch that obtain the battery information by calling ioctl().
Comment 3 Nick Schermer editbugs 2007-01-29 08:15:17 CET
And which of those patches works best?
Comment 4 Emmanuel Viaud 2007-01-29 09:12:27 CET
As I said, my patch is not a really good one. It was mainly posted to point at the origin of the problem. As a matter fact, there are two ways to correct the problem :
 1) correct the way the informations are gathered in libacpi.c and the data structure is filled (this is what is done in Shigeru Fujiwara's patch, albeit using another method than the one currently used)
 2) specialize the way we get and display the informations in battery.c (directly using the values available through the sysctl interface)

Personally I tend to prefer the first solution (well, I suppose that it is best to put all the OS dependent part in a single file and keep a mostly OS agnostic bettery.c but I don't know if it is completely feasible as I don't know the source code well enough).
Comment 5 Shigeru Fujiwara 2007-01-29 18:20:42 CET
In FreeBSD, I could not obtain each battery's remaining capacity by sysctl(), so I obtained it by ioctl().

By the way, is it necessary to obtain the remaining capacity of each battery truly by this program primarily? If this program needs only the sum total value of all batteries, it appropriate to make this into an interface with each OS.

(In reply to comment #4)
> Personally I tend to prefer the first solution (well, I suppose that it is best
> to put all the OS dependent part in a single file and keep a mostly OS agnostic
> bettery.c 

Therefore, I agree with your opinion.
Comment 6 Harald Servat 2007-03-01 10:33:42 CET
Created attachment 1013 
Battery information on FreeBSD using sysctl
Comment 7 Harald Servat 2007-03-01 14:00:43 CET
  Hey!, where's my text? :(

  Ok, I'd the same problem on my laptop (IBM T42p, FBSD 6.2). I've attached a sample code just to show how to get battery information with sysctl (it works for me), maybe could be a great idea to change ioctl calls into sysctl calls?

  Here's the information I can gather with sysctl

hw.acpi.battery.life: 64
hw.acpi.battery.time: 117
hw.acpi.battery.state: 1
hw.acpi.battery.units: 1
hw.acpi.battery.info_expire: 5
hw.acpi.acline: 0

Regards,
Comment 8 Nick Schermer editbugs 2007-03-14 18:05:37 CET
If the patch of Shigeru Fujiwara works w/o problems for all of you I'll commit it in trunk. I'm not using FreeBSD so I'm waiting for a working patch ;).
Comment 9 Florian Rivoal editbugs 2010-12-28 15:17:34 CET
*** Bug 7041 has been marked as a duplicate of this bug. ***
Comment 10 Florian Rivoal editbugs 2011-02-26 15:02:26 CET
Can someone who uses freebsd comment on how good that patch is in long term use? I'd commit it, but I don't currently have a test system.
Comment 11 John Marshall 2011-03-21 11:54:13 CET
(In reply to comment #10)
> Can someone who uses freebsd comment on how good that patch is in long term
> use? I'd commit it, but I don't currently have a test system.

I'm not a programmer and can't comment on the quality of the patch except to say that it "works for me". I realigned the patch submitted by Shigeru Fujiwara so that it applies cleanly to the 1.0.0 panel-plugin/libacpi.c file. Builds and works on FreeBSD 8.2-RELEASE i386 with Xfce 4.8.0 on an IBM ThinkPad T43.
Comment 12 John Marshall 2011-03-21 12:14:34 CET
Created attachment 3574 
Patch 2 realigned to apply to panel-plugin/libacpi.c in 1.0.0

This is the patch submitted by Shigeru Fujiwara realigned to apply cleanly to the 1.0.0 version of libacpi.c. This is the patch referred to by me in Comment 11.
Comment 13 Landry Breuil editbugs 2012-04-17 21:49:29 CEST
Patch applied in http://git.xfce.org/panel-plugins/xfce4-battery-plugin/commit/?id=5fdc701440f97cee111a2a47c85f7d838aab7e13

Can someone using FreeBSD test the plugin from git to confirm it works now ?

Bug #2814

Reported by:
Emmanuel Viaud
Reported on: 2007-01-24
Last modified on: 2012-04-17
Duplicates (1):
  • 7041 [patch] Fix showing of battery status of FreeBSD (x86, Gentoo/FreeBSD)

People

Assignee:
Xfce-Goodies Maintainers
CC List:
5 users

Version

Version:
0.5.1 or older

Attachments

patch to correct battery display on FreeBSD (648 bytes, patch)
2007-01-24 20:22 CET , Emmanuel Viaud
no flags
another patch (1.87 KB, patch)
2007-01-28 18:13 CET , Shigeru Fujiwara
no flags
Battery information on FreeBSD using sysctl (792 bytes, text/x-csrc)
2007-03-01 10:33 CET , Harald Servat
no flags
Patch 2 realigned to apply to panel-plugin/libacpi.c in 1.0.0 (1.94 KB, patch)
2011-03-21 12:14 CET , John Marshall
no flags

Additional information