garbear / xbmc

XBMC Main Repository
http://xbmc.org
Other
132 stars 53 forks source link

[Enhancement] show controller battery status on in-game OSD #102

Open cdu13a opened 6 years ago

cdu13a commented 6 years ago

It's frustrating to have a controller die during game play. So it would be nice to be able to show the battery status of controllers on in-game OSD.

kodi-game-osd

VelocityRa commented 6 years ago

I don't think gamepad APIs generally offer getting the baterry level. I quickly checked DirectInput, cocoa, SDL and udev and none of them seem to do so.

So, I'm not sure if this is feasible unfortunately.

garbear commented 6 years ago

Are there any APIs out there which expose battery level?

cdu13a commented 6 years ago

It's a battery so It's possible that info would be available from a power management API.

VelocityRa commented 6 years ago

I'd be surprised. This stuff is very controller-specific. If the APIs that interact with controllers don't expose it I'm not sure if anything else would, at least not if you're looking for a generic solution.

VelocityRa commented 6 years ago

I found this config option for Linux: https://cateee.net/lkddb/web-lkddb/HID_BATTERY_STRENGTH.html upower makes use of it, so maybe test it to see if shows battery levels of a connected controller.

Edit: Huh, looks like the driver on linux has support for it for DS4 https://github.com/torvalds/linux/blob/master/drivers/hid/hid-sony.c#L1027-L1056 so maybe the above solution is ok. Don't know for how many controllers it'll work, but it's a start.

For Windows I found this UWP API, but I wouldn't be very hopeful: https://docs.microsoft.com/en-us/windows/uwp/devices-sensors/get-battery-info Also it looks like it's UWP only, which would suck.

garbear commented 6 years ago

So there's some APIs that expose levels. @cdu13a or @VelocityRa would you be willing to add battery level to an API in peripheral.joystick? I can take care of the API changes and all the GUI work.

VelocityRa commented 6 years ago

There's some APIs that expose levels, but that doesn't mean that most controllers' drivers will implement it. What I found is only confirmed working for DS4, on Linux.

I'm right in the middle of exams atm and right after that I'm going on a holiday, will be back at about July 25th. I'll look into it then if noone else will have but if it's Linux-only and not even for every controller I'm not sure if it'd be acceptable.

cdu13a commented 6 years ago

Going to look at peripheral.joystick to see if I would be able to make the required changes. My C++ is rather rusty, but I might be able to figure it out.

I've done a bit more looking at where the battery level info can come from and xinput on windows has https://docs.microsoft.com/en-us/windows/desktop/api/xinput/nf-xinput-xinputgetbatteryinformation

so should be able to do more then just linux.

as for some drivers not implementing the reading of any power supply/battery info. I don't think that is our problem. As long as we can get info for some controllers on each platform, i think we are good.

VelocityRa commented 6 years ago

As long as we can get info for some controllers on each platform, i think we are good

Yeah, just being practical. If 99% of controllers that people use (like Xbox/DS3/DS4 controllers) aren't supported maybe it wouldn't be as worth doing. There's more dev to it than getting the battery level after all (also maintenance).

I've done a bit more looking at where the battery level info can come from and xinput on windows has

Looks promising, maybe make a test program first and test some controllers?

garbear commented 6 years ago

If XInput supports it that's most PC game controllers on windows. That alone makes it worth it.

You should familiarize yourself with the Peripheral API: https://github.com/xbmc/xbmc/blob/master/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Peripheral.h. That's were we'll expose battery info to Kodi. A good first step would be adding battery info to that header file. Then it's just a matter of implementing support in the add-on.