Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Help Wanted Custom data layout for SpaceNavigator

Discussion in 'Input System' started by PatHightree, Aug 20, 2020.

  1. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    287
    Hi there,
    I'm trying to get my SpaceNavigator to play nice with the Input System, but I can't figure out how to tell it to use 16 bit floats.
    This is the HID descriptor and my wip output
    upload_2020-8-20_22-38-59.png

    Using this code
    Code (CSharp):
    1.    
    2. [InputControl(name = "translation", offset = 8, format = "VC3S", layout = "Vector3", displayName = "Translation")]
    3.     [InputControl(name = "translation/x", defaultState = 0.0f, format = "SHRT", parameters = "normalize,normalizeMin=-32768,normalizeMax=32768,normalizeZero=0.0")]
    4.     [InputControl(name = "translation/y", defaultState = 0.0f, format = "SHRT", parameters = "normalize,normalizeMin=-32768,normalizeMax=32768,normalizeZero=0.0")]
    5.     [InputControl(name = "translation/z", defaultState = 0.0f, format = "SHRT", parameters = "normalize,normalizeMin=-32768,normalizeMax=32768,normalizeZero=0.0")]
    6.  
     

    Attached Files:

  2. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    287
    Another attempt.
    Without the custom device, the rotation data is received correctly by the input system.
    The rotation values (rx,ry,rz) change when I move the device.
    But the translation (x,y,z) data is mangled up in the stick input and not changing at all, the z value is identical to rz.
    upload_2020-8-22_11-59-55.png

    So my next attempt was to recreate the the part which does work (the receiving of the rotation data) in a custom device.
    I duplicated it as best I could, but I'm not receiving any data.
    Code (CSharp):
    1.  
    2. [InputControl(name = "rx", offset = 1, format = "SHRT", layout = "Axis", displayName = "RX")]
    3. public int rx;
    4. [InputControl(name = "ry", offset = 3, format = "SHRT", layout = "Axis", displayName = "RY")]
    5. public int ry;
    6. [InputControl(name = "rz", offset = 5, format = "SHRT", layout = "Axis", displayName = "RZ")]
    7. public int rz;
    upload_2020-8-22_12-4-26.png
    What's suspicious is that the events log shows my FourCC format "MINE" when I don't touch the device, but HID when I move it. Suggesting that my device registration is not working correctly.
    (source is attached to post)

    Code (CSharp):
    1.         InputSystem.RegisterLayout<CustomDevice>(
    2.             matches: new InputDeviceMatcher()
    3.                 .WithInterface("HID")
    4.                 .WithCapability("vendorId", 0x46D) // 3DConnexion
    5.                 .WithCapability("productId", 0xC626)); // SpaceNavigator
     

    Attached Files:

    Last edited: Aug 22, 2020
  3. Tongpan2020

    Tongpan2020

    Joined:
    Nov 4, 2020
    Posts:
    2


    Joined:
    Today
    Posts:
    1
    New
    Hi PatHightree

    Your space navigator driver runs well in game tab, but it crush in built application. The error is
    "NotSupportedException: Specified method is not supported.
    at (wrapper cominterop) TDx.TDxInput.DeviceClass..ctor()"

    I saw some threads mentioned this problem. But I can't find a solution. I tested the version 1.5.3. It doesn't fix the problem.

    Can you tell me how to fix this issue?

    Thanks
     
  4. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    287
    I'm still trying to get the input system to read my SpaceNavigator
    I found this C++ code which reads the HID data layout correctly and I'm trying to convert this now (source)

    Code (CSharp):
    1. UINT processSpaceMouseProRawData(BYTE* rawDataBuffer, DWORD rawDataSize) {
    2.     if (rawDataSize >= SMP_RAW_DATA_SIZE) {
    3.         switch (rawDataBuffer[0]) {
    4.             case 1:{    //SMP_MOVE_CHANNEL
    5.                 INT16 x_val = static_cast<INT16>(rawDataBuffer[1] | (rawDataBuffer[2] << 8));
    6.                 INT16 y_val = static_cast<INT16>(rawDataBuffer[3] | (rawDataBuffer[4] << 8));
    7.                 INT16 z_val = static_cast<INT16>(rawDataBuffer[5] | (rawDataBuffer[6] << 8));
    8.                 std::cout << "M:" << x_val << SEPARATOR << y_val << SEPARATOR << z_val << std::endl;
    9.             } break;
    10.             case 2: {    //SMP_ROTATE_CHANNEL
    11.                 INT16 pitch_val = static_cast<INT16>(rawDataBuffer[1] | (rawDataBuffer[2] << 8));
    12.                 INT16 roll_val = static_cast<INT16>(rawDataBuffer[3] | (rawDataBuffer[4] << 8));
    13.                 INT16 yaw_val = static_cast<INT16>(rawDataBuffer[5] | (rawDataBuffer[6] << 8));
    14.                 std::cout << "R:" << pitch_val << SEPARATOR << roll_val << SEPARATOR << yaw_val << std::endl;
    15.             } break;
    16.             case 3: {    //SMP_BUTTON_CHANNEL
    17.                 std::cout << "B:" << static_cast<unsigned int>(rawDataBuffer[1]) << SEPARATOR
    18.                     << static_cast<unsigned int>(rawDataBuffer[2]) << SEPARATOR
    19.                     << static_cast<unsigned int>(rawDataBuffer[3]) << SEPARATOR
    20.                     << static_cast<unsigned int>(rawDataBuffer[4]) << std::endl;
    21.             } break;
    22.         default:
    23.             break;
    24.         }
    25.     }
    26.  
    27.     return 0;
    28. }
    This told me a couple of things
    • The device reports its data in multiple reports, which is why the autogenerated mapping doesn't work
      I'm trying to figure out how to read data using the ReportID
    • The data is in short values
    • The bytes are ordered little-endian
    This is the device description.which confirms that the data is divided into 2 ReportID's
    Does anybody have sample code on how to read multiple reports ?

    @Rene-Damm
    You mentioned (long time ago) that you have one at the office, could you maybe have a look at it ?
    But I guess you're likely working remote instead of at the office though :\
     
  5. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    287
  6. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    287
    Ok, I got my code working based on that sample.
    But it requires that the project is changed to allow unsafe code, is there any way to avoid requiring such project-wide modifications ?

    [edit]
    Hmm, the second code sample in that thread doesn't use unsafe code.
    Gonna look into that.
     
    Last edited: Feb 6, 2021
unityunity