switchbrew / libnx

Library for Switch Homebrew
https://switchbrew.github.io/libnx/
ISC License
1.26k stars 167 forks source link

Support for HID Vibrations #643

Closed o0Zz closed 3 months ago

o0Zz commented 3 months ago

Hello,

Context I'm working on a fork of sys-con -> https://github.com/o0Zz/sys-con For this fork I would like to add vibration from 3rd party controllers. I am almost there but one API is missing from libnx and I would like to know if there is a way to add it.

Problem/Request hidIsVibrationDeviceMounted returns false for the controller initialized with hiddbgAttachHdlsVirtualDevice I would like a way to set HidVibrationDeviceInfo in any way.

Summary of the investigation Here is a summary of my investigation. my module uses the following APIs:

hiddbgAttachHdlsVirtualDevice(...)
// From here I get the npadId assigned by hiddbgAttachHdlsVirtualDevice with a little trick
hidInitialiseVibrationDevices(...)

hidGetActualVibrationValue(...) //Will always return 0 (even if we set the vibration)

Issue, hidGetActualVibrationValue return everytime 0 (No vibration) and I think the reason why this API returns 0 is because when we attach a new device (hiddbgAttachHdlsVirtualDevice) we cannot inform the OS that we support "vibration". From my investigation, I have the feeling that we need a way to set the HidVibrationDeviceInfo.

I built a small application to set vibration: https://github.com/o0Zz/sys-con/blob/master/source/AppletCompanion/source/main.cpp

This code works perfectly with the official switch controller and it shows vibration "Permitted". However, with the sys-con module the same code does not work and it displays vibration "Not Permitted" for all devices initialized with hiddbgAttachHdlsVirtualDevice.

I'm not sure if my investigation makes sense and I'm not sure how this API can be added but if you have any suggestions I would be happy to hear them ;)

Thanks

yellows8 commented 3 months ago

Don't think HOS supports vibration with hiddbg (#347). Have to use other means, such as mitm etc (https://github.com/ndeadly/MissionControl).

o0Zz commented 3 months ago

@yellows8 thank you for your answer, is it a confirmation or an assumption that the system don't support it ? How can I make sure it really not support it ?

german77 commented 3 months ago

Virtual device is meant to be used as a TAS like controller. Mainly for unit testing as such.

They don't support vibration. If you need vibration you need to mimic a real controller like mission control does

ndeadly commented 3 months ago

FYI, mission control has a (mostly) working implementation of usb support (including vibration) in the works.

o0Zz commented 3 months ago

Thank you both for your answers. What I had in mind when I asked if we're sure these APIs don't exist is that these APIs have mainly been reverse engineered and my question was more along the lines of: Is there any chance that some APIs are still "undiscovered" and could be hiding this feature? I will certainly move to a hook for this feature, I'm not sure yet if I'll go for an hybrid solution (hook + hiddbg) or a full hook - what I liked about this hidbg is the simplicity of use, even if I agree with you, it's not the "best" approach here. However, I didn't notice any input lag, so it does the job very nicely ;)

yellows8 commented 3 months ago

The structs used by 18.0.0 hid for Hdls already match wiki (HdlsDeviceInfo/HdlsState). https://switchbrew.org/wiki/HID_services