valr / cbatticon

A lightweight and fast battery icon that sits in your system tray
GNU General Public License v2.0
166 stars 39 forks source link

Battery status "Unknown" causes empty icon #10

Closed XeCycle closed 11 years ago

XeCycle commented 11 years ago

Sometimes (for me) /sys/class/power_supply/BAT1/status shows "Unknown", and cbatticon shows an empty icon. I'd suggest using some default icon names, e.g. "battery-full", "battery-low" for unknown states.

valr commented 11 years ago

Empty icon is not reported when status is unknown but only when the battery is reported as missing i.e. not when the file 'status' contains 'unknown' but when the file 'present' is not '1' (probably '0'). Can you check that on your system ?

What machine type do you have ? Any hardware problem ? Any known buggy driver ?

XeCycle commented 11 years ago

Valère Monseur notifications@github.com writes:

Empty icon is not reported when status is unknown but only when the battery is reported as missing i.e. not when the file 'status' contains 'unknown' but when the file 'present' is not '1' (probably '0'). Can you check that on your system ?

Though cannot reproduce it now, I remember 'present' to be 1 the last time 'status' shows 'Unknown'. And it did show an empty icon.

What machine type do you have ? Any hardware problem ? Any known buggy driver ?

A Lenovo laptop. There are some hardware problems with my machine, but should be unrelated --- my Wi-Fi card and the radeon driver are buggy.

Carl Lei (XeCycle) Department of Physics, Shanghai Jiao Tong University OpenPGP public key: 7795E591 Fingerprint: 1FB6 7F1F D45D F681 C845 27F7 8D71 8EC4 7795 E591

XeCycle commented 11 years ago

@valr Here's a fresh screenshot taken just now. cbat-bug The empty icon is cbatticon, the normal icon is another battery monitoring script I wrote myself.

valr commented 11 years ago

Great, thanks for the info. Indeed, now I see the sequence of operations and the problem.

In fact, the tray icon is first created using the function gtk_status_icon_new. It's the emtpy icon you see. And I see two cases (not only this one) that don't trigger a change of icon in the function update_tray_icon_state: NOT_CHARGING and UNKNOWN.

To be complete, they should be handled also. I don't know yet how exactly, but I'll have a look at it.

valr commented 11 years ago

I've pushed a commit to set 'battery-empty' or 'battery-missing' (depending on the icon type chosen) in case of unknown status. Can you have a look ?

XeCycle commented 11 years ago

Hmm, it did show an icon, stating "battery status is unknown!". The icon is like the battery-missing icon --- but the battery is actually there, and capacity near full. I guess "Unknown" on my laptop is used to represent "AC connected, battery not full, but not charging" state. This icon may be misleading. I suggest choosing the icon by capacity.

valr commented 11 years ago

Well, there is no dedicated icon for 'unknown' status, showing full capacity or empty capacity is maybe not a good idea, so what is possible then is only to show the capacity.

But here there are 2 options: plugged in or not (i.e. charging or discharging), these are 2 different sets of icons.

It's impossible to know it only by looking at the battery information. Possibly the AC information could help i.e. I would have to find the main supply (type 'Mains' in https://github.com/torvalds/linux/blob/master/drivers/power/power_supply_sysfs.c) and look at the value of the 'online' file that should be 1 in case of main power supply plugged in or 0 if not plugged in.

Could you tell me what you have in your /sys/class/power_supply/xxx/online when the battery status in 'unknown' ? (xxx is the your main supply i.e. type = 'Mains' ; mine is ADP1 but yours can be different).

Thanks

XeCycle commented 11 years ago

$ cat ACAD/online BAT1/status BAT1/capacity 1 Unknown 99 Here they are.

valr commented 11 years ago

Thanks. I will make the change to provide the icon by "capacity" (as you suggested) and the type of icon will be plugged-in or not depending of the online status of the main power supply.

Regarding the capacity field you mentioned, it's currently not used. cbatticon uses energy_now, energy_full, power_now (or their equivalent charge_xxx) and performs calculation to get the percentage and remaining time.

I will not change this and still uses the get_battery_remaining_charge_info (&percentage, &time). Then we'll see if this works on your side. Or maybe you can already check if those values look valid when status is unknown.

XeCycle commented 11 years ago

Thanks. It seems to me that the capacity field is a precalculated percentage, so I'm using this field in my own script.

valr commented 11 years ago

I've pushed another commit. In this one, cbatticon tries guessing the status by looking at the main power supply (AC).

If AC is not plugged-in, status is considered as 'discharging'. If AC is plugged-in and percentage >= 99 then status is considered as 'charged' If AC is plugged-in and percentage < 99 then status is considered as 'charging'

I'm not using (yet) the capacity field but still using the xxx_charge_info to get percentage and time. Can you check this ?

XeCycle commented 11 years ago

Thanks, it works fine now.

gberenfield commented 10 years ago

This issue seems to be back for me. Using Arch on a Lenovo Thinkpad. I thought it might be issue #10 but building/using the latest commit in debug mode shows the icons being found just fine.

If I unplug my ac adapter, the icon returns and I get debug output with everything looking right. When I plug it back in, no debug output and the icon disappears.

'acpi' shows Battery 0: Unknown, 95% with the ac adapter plugged in.

valr commented 10 years ago

Hi, this seems to be another case of bugged driver/battery. Could you send me the content of the file 'online' from your main power supply in /sys/class/power_supply/xxx with 'type' Mains ? and the content of the files 'present' and 'status' from your battery ? Please, send me above info both with cable plugged and unplugged. (remark for me: add these info in the debug output later on)

gberenfield commented 10 years ago

Certainly, here you go:

On Battery


[/sys/class/power_supply/AC] λ cat online 0


[/sys/class/power_supply/BAT0] λ cat present 1 [/sys/class/power_supply/BAT0] λ cat status Discharging

On Power


[/sys/class/power_supply/AC] λ cat online 1


[/sys/class/power_supply/BAT0] λ cat present 1 [/sys/class/power_supply/BAT0] λ cat status Charging

And the kernel info FYI: λ uname -a Linux mu 3.15.4-1-ARCH #1 SMP PREEMPT Mon Jul 7 07:42:54 CEST 2014 x86_64 GNU/Linux

This is a Lenovo T440p Thinkpad. I'm sure this is ultimately a kernel power driver problem like you say, due to the following:

On Battery


λ acpi Battery 0: Discharging, 98%, 03:36:29 remaining

On Power


λ acpi Battery 0: Unknown, 98%

But thank you for you help! Let me know if you need anything else.

Kind Regards Greg

valr commented 10 years ago

Thanks. I'll have a look at it but I'm off for a few days. It will be in the coming days when I'm back

valr commented 10 years ago

@gberenfield: I've added other debug information in the code. Could you run cbatticon with -d (debug) option and send me the information when on battery and on power ? Thanks

gberenfield commented 10 years ago

Sure, here you go:

On Power/AC:

ac path     : /sys/class/power_supply/AC
batt path   : /sys/class/power_supply/BAT0
batt present: 1
batt status : 1 - Unknown
ac online   : 1
batt present: 1
batt status : 1 - Unknown
ac online   : 1
batt present: 1
batt status : 1 - Unknown
ac online   : 1
batt present: 1
batt status : 1 - Unknown
ac online   : 1

And on Battery:

batt present: 1
batt status : 4 - Discharging
battery     : Battery is discharging (95% remaining)
time        :  2 hours, 43 minutes remaining
tooltip     : Battery is discharging (95% remaining)
tooltip     :  2 hours, 43 minutes remaining
icon        : battery-full
batt present: 1
batt status : 4 - Discharging
battery     : Battery is discharging (95% remaining)
time        :  2 hours, 33 minutes remaining
tooltip     : Battery is discharging (95% remaining)
tooltip     :  2 hours, 33 minutes remaining
icon        : battery-full
batt present: 1
batt status : 4 - Discharging
battery     : Battery is discharging (95% remaining)
time        :  2 hours, 41 minutes remaining
tooltip     : Battery is discharging (95% remaining)
tooltip     :  2 hours, 41 minutes remaining
icon        : battery-full
gberenfield commented 10 years ago

Odd, I re-ran it with it plugged in to see if the icon showed up this time and then it just plain worked:

Power/AC:

ac path     : /sys/class/power_supply/AC
batt path   : /sys/class/power_supply/BAT0
batt present: 1
batt status : 3 - Charging
battery     : Battery is charging (95%)
time        :  6 minutes remaining
tooltip     : Battery is charging (95%)
tooltip     :  6 minutes remaining
icon        : battery-full-charging
batt present: 1
batt status : 3 - Charging
battery     : Battery is charging (95%)
time        :  6 minutes remaining
tooltip     : Battery is charging (95%)
tooltip     :  6 minutes remaining
icon        : battery-full-charging
valr commented 10 years ago

Well, it's quite unstable.

Anyway, it seems that together with the Unknown status, some of the measures (remaining capacity, full capacity, current rate) are not available.

I've added a few more debug info to display which of the measure is not available.

Can you rerun cbatticon in debug mode and send me the info ? I think that I'll have enough info after that. Then I'll see if a solution can be implemented or not.

gberenfield commented 10 years ago

Power/AC:

λ cbatticon -d
ac path      : /sys/class/power_supply/AC
batt path    : /sys/class/power_supply/BAT0
batt present : 1
batt status  : 2 - Full
battery      : Battery is charged!
tooltip      : Battery is charged!
icon         : battery-full-charged
batt present : 1
batt status  : 2 - Full
battery      : Battery is charged!
tooltip      : Battery is charged!
icon         : battery-full-charged

Battery:

λ cbatticon -d                                                                                                                                                            
ac path      : /sys/class/power_supply/AC
batt path    : /sys/class/power_supply/BAT0
batt present : 1
batt status  : 4 - Discharging
battery      : Battery is discharging (99% remaining)
time         :  2 hours, 33 minutes remaining
tooltip      : Battery is discharging (99% remaining)
tooltip      :  2 hours, 33 minutes remaining
icon         : battery-full
batt present : 1
batt status  : 4 - Discharging
battery      : Battery is discharging (99% remaining)
time         :  2 hours, 23 minutes remaining
tooltip      : Battery is discharging (99% remaining)
tooltip      :  2 hours, 23 minutes remaining
icon         : battery-full
valr commented 10 years ago

Thanks, can you provide me also the info when the status becomes unknown ? Above cases are ok.

gberenfield commented 10 years ago

Just tried it again and am getting this on Power/AC: Sorry it's not overly helpful I think.

λ cbatticon -d              
ac path      : /sys/class/power_supply/AC
batt path    : /sys/class/power_supply/BAT0
batt present : 1
batt status  : 1 - Unknown
ac online    : 1
battery      : Battery is charged!
tooltip      : Battery is charged!
icon         : battery-full-charged
batt present : 1
batt status  : 1 - Unknown
ac online    : 1
battery      : Battery is charged!
tooltip      : Battery is charged!
icon         : battery-full-charged
valr commented 10 years ago

Indeed, it's not what I was expecting. But I'm a bit lost now. In your original post, you mentioned icon was disappearing, but here the icon is battery-full-charged, do you see it ? In other words, do you have 3 different cases when on AC ? 1) working normally 2) Unknown status and icon visible 3) Unknown status and icon not visible

gberenfield commented 10 years ago

Yes, 3-cases although right now, it seems I can only get the icon on battery..

Currently, unplugging/re-plugging in power isn't getting the icon back (and battery status 1 - Unknown)

valr commented 10 years ago

Do you mean that the last debug output above does not display the icon ? I mean even with the icon name mentioned: "icon : battery-full-charged" ?

gberenfield commented 10 years ago

If the power adapter's plugged in and batt status : 1 - Unknown, no icon. If the power adapter's plugged in and batt status : 2 - Full, I get the icon (ac version).

And yes, the comment above (3-cases) had no icon with the power adapter plugged in.

valr commented 10 years ago

Well, if the icon name is mentioned, you should see the icon (I become crazy :-) Which icon theme do you use ?

gberenfield commented 10 years ago

Typically 'notification' but since I've been building from the git repo, I've just been letting it default (just running cbatticon -d)

valr commented 10 years ago

The icon theme, not the icon type. I'm using faenza: http://gnome-look.org/content/show.php/Faenza?content=128143). Which theme do you use ?

gberenfield commented 10 years ago

Sorry, actually not sure.. Using Arch with openbox as the wm..

valr commented 10 years ago

Could you install lxappearance i.e. pacman -S lxappearance, run it and tell me what icon theme you have ? Thanks

gberenfield commented 10 years ago

Faenza-CrunchBang-Dark After seeing that, I see that I'm using Arch's community/faenza-icon-theme (installed)

valr commented 10 years ago

Honestly I'm a bit out of ideas. If the icon name is listed in the debug output, icon should be visible. Can you select the faenza theme (in lxappearance) and not faenza-crunchbang-dark and test again ?

gberenfield commented 10 years ago

Well it's odd.. I'm going to try a different icon theme and see where that get's me. Thanks for all your efforts!!

valr commented 9 years ago

@gberenfield : I've just fixed a bug causing the icon to disappear. Fix is included in latest release 1.4.2 Maybe it was the problem you had. Feel free to give cbatticon another try. Cheers.

gberenfield commented 9 years ago

Thanks! Will try it for a while and let you know how it goes.