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 5051 - Switch Pro Controller hidapi driver does not report battery levels when connected via Bluetooth
Summary: Switch Pro Controller hidapi driver does not report battery levels when conne...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: 2.0.12
Hardware: x86 Windows 10
: P2 minor
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-22 07:04 UTC by bluenaxela+sdl
Modified: 2020-03-22 18:01 UTC (History)
0 users

See Also:


Attachments
Patch to src/joystick/hidapi/SDL_hidapi_switch.c which applies to SDL2 2.0.12 (3.27 KB, patch)
2020-03-22 07:04 UTC, bluenaxela+sdl
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description bluenaxela+sdl 2020-03-22 07:04:57 UTC
Created attachment 4275 [details]
Patch to src/joystick/hidapi/SDL_hidapi_switch.c which applies to SDL2 2.0.12

I've noticed that the Switch Pro Controller hidapi driver does not report battery levels when connected via Bluetooth, despite having code for setting joystick->epowerlevel.

This is caused by the driver always using k_eSwitchInputReportIDs_SimpleControllerState via Bluetooth. Using that mode means that the state reports you get back from the controller do not include battery state. Not using the full controller state over Bluetooth effectively makes this driver's support for setting joystick->epowerlevel entirely pointless, only ever reporting SDL_JOYSTICK_POWER_WIRED.

Is there a reason this was set to only use SimpleControllerState via Bluetooth?

I've attached a patch I'm using to allow getting battery level for the Switch Pro Controller.

A couple notes about this patch:
1) It changes LoadStickCalibration to accept the input_mode that is selected, because that's really what should determine what is used for stick extents, since stick extents differ between the modes.
2) In my patch I only use FullControllerState when the vid/pid matches the official Switch Pro Controller, as a cautionary measure in case some third-party controllers have problems with FullControllerState mode via Bluetooth (I noticed a HORI Wireless Switch Pad I had seemed to not read controller calibration correctly for stick extents. Maybe it's calibration data was uninitialized on account of having never been used with a Switch? I'm unsure, though if that guess is right maybe SDL2 should be detecting an uninitiated calibration state and using some sensible defaults)
Comment 1 Sam Lantinga 2020-03-22 18:01:33 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/37af808e6222