~mil/sxmo-tickets#243: 
No battery level in status bar on Nexus 5

On my Nexus 5 I don't see the battery level in the status bar. The reason is that the script sxmo-utils/scripts/core/sxmo_statusbar.sh assumes to find the battery level in /sys/class/power_supply/*-battery/capacity. But on my Nexus 5, the path is /sys/class/power_supply/battery/capacity.

This simple patch could fix the status on the Nexus 5 while (probably) keep it working on other devices:

diff --git a/scripts/core/sxmo_statusbar.sh b/scripts/core/sxmo_statusbar.sh
index ae62a9d..76eef93 100755
--- a/scripts/core/sxmo_statusbar.sh
+++ b/scripts/core/sxmo_statusbar.sh
@@ -54,9 +54,9 @@ update() {
        fi

        # Battery pct
-       PCT="$(cat /sys/class/power_supply/*-battery/capacity)"
+       PCT="$(cat /sys/class/power_supply/*battery/capacity)"
        BATSTATUS="$(
-               cat /sys/class/power_supply/*-battery/status |
+               cat /sys/class/power_supply/*battery/status |
                cut -c1
        )"
        if [ "$BATSTATUS" = "C" ]; then

Could this cause problems on other devices? Like matching more than one folder when *battery is used as glob pattern!?

Status
REPORTED
Submitter
~maxgyver83
Assigned to
No-one
Submitted
3 months ago
Updated
17 days ago
Labels
bug ready

~anjan 3 months ago

Hi ~maxgyver83,

I would prefer if we made the battery cat issue by using the device profiles from this patch: https://lists.sr.ht/~mil/sxmo-devel/patches/22251 rather than file globbing.

Do you have this file on the nexus 5? /sys/firmware/devicetree/base/compatible. That is required for the device profiles to work.

~anjan 3 months ago

~craftyguy says that what is in that patch "could be expanded, e.g. some function to try base/compatible from the DT, then maybe look elsewhere for other clues about the device type, for selecting the right profile"

Might be worthwhile exploring in case nexus 5 doesnt have that file.

~maxgyver83 3 months ago

Sounds good! /sys/firmware/devicetree/base/compatible exists on my Nexus 5 and it contains: lge,hammerheadqcom,msm8974.

~craftyguy 3 months ago

Great, so you can add a new script in the sxmo-utils repo under scripts/deviceprofile/hammerheadqcom.sh, that can set something like BATTERY_DEVICE=/sys/class/power_supply/foo/status (use real path, obviously :P). Then in sxmo_statusbar.sh use that value if that var is set, else default to the glob (to preserve existing behavior).

Though at some point it might make more sense to do away with default values for these things and just have a profile for every device, including the Pinephone? (a bigger question to the sxmo maintainers/folks)

~anjan closed duplicate ticket #253 2 months ago

~anjan 2 months ago

We added support for custom battery locations in deviceprofiles with this patch: https://lists.sr.ht/~mil/sxmo-devel/patches/22787

Feel free to add the nexus and other devices.

Cheers!

~sorsha a month ago

Hi,

This bug still persists on my PinePhone.

BATTERY_DEVICE="${BATTERY_DEVICE:-"/sys/class/power_supply/*-battery"}"
PCT="$(cat "$BATTERY_DEVICE"/capacity)"
cat: '/sys/class/power_supply/*-battery/capacity': No such file or directory

This works for me:

BATTERY_DEVICE="$(eval echo /sys/class/power_supply/*-battery)"

BR

~proycon a month ago

I can reproduce the problem on my pinephone as well, I think something went wrong when we accepted that patch, will fix...

~proycon a month ago

Actually, I see ~stacyharper already fixed this in commit 200ecfa1a72ca87913e27b22f90cb40c7280d715 (in the latest git master tree)

~stacyharper a month ago

Yes sorry for not pointed this earlier !

~noneofyourbusiness a month ago

you could also have replaced PCT="$(cat "$BATTERY_DEVICE"/capacity)" with PCT="$(eval cat "$BATTERY_DEVICE"/capacity)" but hardcoding the path also works

~maxgyver83 19 days ago

Thanks for all your answers and patches and sorry for my late reply. I have tested the master branch and it works when I add a device profile for my Nexus 5. I have created this patch for adding it: https://lists.sr.ht/~mil/sxmo-devel/patches/23640

~maxgyver83 REPORTED FIXED 17 days ago

~anjan FIXED REPORTED 17 days ago

~anjan 17 days ago

Please dont mark as fixed, we have to keep track of issues that are fixed in the git HEAD but not in a release.

~maxgyver83 17 days ago

OK, I see!

Register here or Log in to comment, or comment via email.