Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Input System: Custom HID device on Android

Discussion in 'Input System' started by dingari, Jun 23, 2022.

  1. dingari

    dingari

    Joined:
    Feb 5, 2019
    Posts:
    3
    I have a custom HID device I want to use with the Unity Input System. We have successfully been able to hook it up to Windows and macOS, but Android has given us some problems.

    I found this thread, which kind of just went stale without any clear solution. That user seems to want to do something similar to what we are trying to.

    On Windows and macOS, we've been able to use a state structure to interpret the HID reports from our device. Our device identifies as an HID gamepad, but is matched by our custom device class and streams IMU and motion data to our Unity project. All is well.

    On Android, things go a bit differently. Our device is matched as an AndroidGameController, and if we try to intercept the HID reports / state updates (by implementing
    IInputStateCallbackReceiver
    on the custom device class), we don't see the same report format as we do on Windows and macOS. From the previous thread, we understand that this is because we don't actually get the raw HID report, but rather an
    AndroidGameControllerState
    object that has collected our report into a collection of axes. Is there any way to avoid this?

    We have full control over the HID device descriptor, and are OK with presenting the device as something other than an HID Gamepad. But we haven't been able to get Unity to recognize the device in other configurations.

    We've been able to get a subset of our original input report by packing them up as different "axes" values. However, that is a pretty limited solution and feels way too hacky. Furthermore, it's unclear which axes correspond to actual HID usages (especially the "generic" ones).

    An alternative we've been looking at is implementing a "virtual" device, but before we put in the effort of writing specialized code to access the raw HID report on Android (if that's at all possible), we'd like to exhaust all alternatives.

    Has there been any development on the Android backend lately, or is there anything in the works?

    @Rene-Damm, would be great to get your input on this :)
     
    Last edited: Jun 23, 2022
  2. dingari

    dingari

    Joined:
    Feb 5, 2019
    Posts:
    3
    At this point I'm mainly curious to know if what I want is at all possible? Am I wasting my time trying to get this to work without having the device recognized as an AndroidGamepad?
     
  3. dmytro_at_unity

    dmytro_at_unity

    Unity Technologies

    Joined:
    Feb 12, 2021
    Posts:
    212
    I think if standard android HID drivers are not capable of supporting your device (malformed HID descriptor, non-HID compliant device, not supported usage pages, etc) then unfortunately the only way is to make a plugin to talk to some HID api's directly, like https://developer.android.com/reference/android/bluetooth/BluetoothHidDevice We're currently not planning to support raw HID reports outside of desktop platforms

    If the driver stack does manage to parse HID report correctly, and you get AndroidGameControllerState containing all the required data, I would try to find to which axes it mapped the data to and create a custom device alike how we do a dualshock here https://github.com/Unity-Technologi...ns/Android/AndroidGameController.cs#L219-L223 and here https://github.com/Unity-Technologi...m/Plugins/Android/AndroidSupport.cs#L119-L148