Search Unity

Question Overriding the HID Fallback - Arcade spinner or triggers that require more than a byte?

Discussion in 'Input System' started by zapposh, Sep 4, 2020.

  1. zapposh

    zapposh

    Joined:
    Nov 12, 2016
    Posts:
    117
    I'm overriding the HID Fallback as explained in the docs here:
    https://docs.unity3d.com/Packages/com.unity.inputsystem@0.9/manual/HID.html

    In need to include a spinner control, that uses 10 bit unsigned, so integers from 0-1023, that then automatically wrap around in either direction. How is this defined.

    Also, the docs use a PS4 controller as an example. Here's a snippet:
    Code (CSharp):
    1.        
    2. [InputControl(name = "leftStick", layout = "Stick", format = "VC2B")]
    3.         [InputControl(name = "leftStick/x", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
    4.         [InputControl(name = "leftStick/left", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp,clampMin=0,clampMax=0.5,invert")]
    5.         [InputControl(name = "leftStick/right", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp,clampMin=0.5,clampMax=1")]
    6.         [InputControl(name = "leftStick/y", offset = 1, format = "BYTE", parameters = "invert,normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
    7.         [InputControl(name = "leftStick/up", offset = 1, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp,clampMin=0,clampMax=0.5,invert")]
    8.         [InputControl(name = "leftStick/down", offset = 1, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp,clampMin=0.5,clampMax=1,invert=false")]
    9.         [FieldOffset(1)] public byte leftStickX;
    10.         [FieldOffset(2)] public byte leftStickY;
    11.  
    In the above case the left stick uses 1 byte for x values and 1 byte for 1 values.
    What if the stick as in my case is represented by a 16 bit 2 complements signed value (range -32767 to 32767) for each axis?

    Thanks
     
  2. LeHaase

    LeHaase

    Joined:
    Dec 21, 2020
    Posts:
    9
    I don't know if this is still relevant but if the input is 16bits long you can use a short instead of a byte. (short = 2bytes)