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.
Created attachment 963 patch to correct battery display on FreeBSD Oops, didn't see the attachment link... Here is the patch.
Created attachment 971 another patch This is the another patch that obtain the battery information by calling ioctl().
And which of those patches works best?
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).
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.
Created attachment 1013 Battery information on FreeBSD using sysctl
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,
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 ;).
*** Bug 7041 has been marked as a duplicate of this bug. ***
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.
(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.
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.
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 ?