We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3485 - SDL_GetPowerInfo reads battery status for PS4 controller
Summary: SDL_GetPowerInfo reads battery status for PS4 controller
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: 2.0.4
Hardware: x86_64 Linux
: P2 minor
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-10 13:19 UTC by Jesper Stefansson
Modified: 2017-05-28 11:18 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jesper Stefansson 2016-11-10 13:19:47 UTC
When a PS4 controller is connected to a Linux PC a call to SDL_GetPowerInfo is reading its battery status. This behaviour seems incorrect and most likely occurs due to how SDL is reading battery status from /sys/class/power_supply, in which the PS4 controller makes its battery accessible.

ls -l /sys/class/power_supply/
lrwxrwxrwx 1 root root 0 Nov  9 16:52 sony_controller_battery_1c:66:6d:30:f1:09 -> ../../devices/pci0000:00/0000:00:14.0/usb3/3-6/3-6:1.0/0003:054C:05C4.0004/power_supply/sony_controller_battery_1c:66:6d:30:f1:09/

The behaviour was reproduced using SDL 2.0.4 with no other battery source connected.
Comment 1 Ryan C. Gordon 2017-05-28 03:16:57 UTC
Okay, so I looked to see if there's some field in /sys/class/power_supply that says "this is just a thing with a battery" verses "this a battery that keeps the system going" and there doesn't appear to be one.

The UPower developers asked about this very issue on the kernel mailing list for Wacom tablets that did the same thing:

http://lkml.iu.edu/hypermail/linux/kernel/1106.2/02961.html

...saying, "I really don't want to blacklist 'battery_wacom' as that seems like such a hack."

But that was 2011, and it doesn't look like the kernel provided an interface to fix this, so here's the Fedora project blacklisting battery_wacom in UPower...

https://lists.fedoraproject.org/pipermail/scm-commits/2011-September/655901.html


So basically: my limited research suggests UPower is doing the work to filter out known devices in this regard, so the solution here is for SDL to talk to UPower, which we actually already have a FIXME for. I'll try to write that soon.

--ryan.
Comment 2 Ryan C. Gordon 2017-05-28 11:18:10 UTC
I've now implemented UPower support in https://hg.libsdl.org/SDL/rev/5be3faa49e54, so I believe this bug should be fixed.

(Please reopen it if your PS4 controller is still causing this problem, but there's an explicit check in the patch to ignore input devices with batteries, so we should be okay here, I think.)

--ryan.