Menu

#524 [lxpanel] Battery plugin should support multiple batteries

-
closed-accepted
batt (2)
3
2015-12-02
2015-11-09
No

My laptop has 2 batteries (Lenovo x240). As of 0.8.1 the lxpanel 'batt' plugin has no way to select which battery to monitor, it always shows status of battery 0 (which in my case only gets used when the battery 1 is empty).
The battery plugin of lxpanel should allow setting which battery to monitor. Thus you can have multiple instances of this plugin to show you current status of all your batteries.
Patch against 0.8.1. is attached.

1 Attachments

Discussion

  • Henry Gebhardt

    Henry Gebhardt - 2015-11-10
    • assigned_to: Henry Gebhardt
     
  • Henry Gebhardt

    Henry Gebhardt - 2015-11-10

    Can you also add that it updates immediately if you change the battery number? That should just be a change to the function 'applyConfig()'. I don't have time to do it myself right now. I'll add it to git then.
    Thanks!

     
  • Stanislav Kozina, Ersin

    Hello, thanks for really quick response!
    Please find the updated patch attached (-v2). I added the update of selected battery into the 'applyConfig()', but it takes effect only after the 'update_timout()' is called (ie. after 9 seconds), or if you click on the widget. I think it's a separate problem, I'm fine with this behavior. Should I open a new issue to call update_display() from applyConfig()?

     
  • Henry Gebhardt

    Henry Gebhardt - 2015-11-16

    Thanks, looks good. I think the current update behaviour is OK, but a patch is welcome! Two more questions:

    • Is it safe to assume that all batteries will have the sysfs name "BAT%d"?

    • Is it safe to assume that the first battery is BAT0, and not, say, BAT1? For example, if BAT0 is removed, but BAT1 is present. Then, if someone starts LXDE for the first time, it will try to open BAT0, but not find it, and will never try to look for BAT1.

     
  • Stanislav Kozina, Ersin

    Hi Henry,
    Thanks again for quick response, and sorry for the delay on my side.
    Looks like the names of entries in sysfs are just derived from the ACPI DSDT table;-/ So it depends on the hardware vendor what the names will be. But from the Google search it looks that the BAT0 name is quite standard. I didn't find any other name used except for Android phones. In Linux it looks to be hardcoded as well - see ACPI_BATTERY_DIR_NAME in sbs.c for example (although sbs module is not used on my laptop).
    So I think that the good way to go is to try to look for BAT%d, if not found, pick up n-th battery entry in sysfs. Please see the attached updated patch (-v3). On my desktop (which has no battery at all) this prints following warning on each battery_get() call (ie. each 9 seconds):
    g_warning( "Battery %d not found", battery_number );
    That seems reasonable to me.
    I also renamed s/ACPI_PATH_SYS_POWER_SUPPY/ACPI_PATH_SYS_POWER_SUPPLY just for fun.
    Thanks!

     
    • Henry Gebhardt

      Henry Gebhardt - 2015-11-29

      Thank you, that looks good! Just to be sure, the line "i=battery_number;" should really be "i=0;", right? I have committed the patch with that change.

       
  • Henry Gebhardt

    Henry Gebhardt - 2015-11-29
    • status: open --> closed-accepted
     
  • Stanislav Kozina, Ersin

    Oops, of course it should be. Sorry for my oversight and thank you for fixing it and merge!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.