Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

T.16000M read "Left hand/Right hand" switch?

Discussion in 'Input System' started by NovaDynamics, Apr 21, 2020.

  1. NovaDynamics

    NovaDynamics

    Joined:
    Sep 6, 2017
    Posts:
    25
    I am using two dual T.16000M Joysticks, and with the help of this post have successfully mapped them out into "Left handed" and "Right handed" Joysticks:

    Code (CSharp):
    1.  
    2.         List<InputDevice> joysticks = new List<InputDevice>();
    3.  
    4.         foreach (InputDevice device in InputSystem.devices)
    5.         {
    6.             if (device.description.product == "T.16000M") joysticks.Add(device);
    7.         }
    8.        
    9.         InputSystem.SetDeviceUsage(joysticks[0], CommonUsages.LeftHand);
    10.         InputSystem.SetDeviceUsage(joysticks[1], CommonUsages.RightHand);
    The only issue is that the joysticks are identical, so there is no way of guaranteeing that the left and right sticks are actually mapped to the correct hand.

    The sticks have switches on the bottom of them that allow you to set "Left" or "Right", but they aren't mapped to any inputs.
    I opened the input debugger and flipped the switches and I can see events appear in the events window, but there are no changes shown when I compair the states before and after the switch is flipped.

    How would I move forward with reading the state of the switch on each joystick?
    EState.png EDiff.png
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Not sure I understand. Usages have no impact on events. You can see the usage being applied in the top section of the device debugger window (where it says "Usages: LeftHand").

    You can get the usages applied to a device via its "usages" property.

    You can bind to controls on devices with specific usages as mentioned in the other post.
     
  3. NovaDynamics

    NovaDynamics

    Joined:
    Sep 6, 2017
    Posts:
    25
    Sorry, hopefully I can clarify myself a little bit :p
    I am writing an application designed to be used specifically with two identical T.16000 joysticks, one for each hand (identical from a software at least). Unfortunately, there is no way of telling from software which joystick is physically left, and which is right.

    What I am attempting to do is read the value of the switch on the bottom of the stick (see photo) and use that to map the usage of the stick to LeftHand or RightHand accordingly.

    This is the switch I was talking about when I mentioned that it triggered an event when I flipped it, but the state of the joystick didn't change.
    IMG_20200422_072829153.jpg
     
  4. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Oh, I see. Unfortunately, I'd consider the chances of being able to read out the state of that switch slim.

    If you're *really* lucky, they include the value in the HID input report (if they do it's either a control on the device or, if it has a vendor-specific usage, just a blob of binary data in the input report). But I strongly doubt that. If not that, they *may* allow querying the state through a feature descriptor but there's not currently a way in the input system to get to those (we support only HID input and output reports ATM). But there's a good chance the switch is a hardware-side only thing that simply alters how the joystick internally does things.

    What I'd probably recommend is to either have a way for the user to go through a "press button on left joystick... press button on right joystick" kind of sequence or to assign it blindly and have a way to swap the assignment (and remember it in prefs).
     
  5. NovaDynamics

    NovaDynamics

    Joined:
    Sep 6, 2017
    Posts:
    25
    Ok, I did some testing and I may have gotten lucky. I get a state change when I flip the switch but no controls are updated. I viewed the raw memory of the state before and after and I am able to spot a difference:
    I am completely clueless on what to do with this new found knowledge or even if it really means anything...
    StateChange.png
     
  6. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Interesting :) So basically, all you need is to first find out whether that maps to a control in the HID descriptor.

    Does any of the InputControls on the device change state when you flip the switch?
     
  7. NovaDynamics

    NovaDynamics

    Joined:
    Sep 6, 2017
    Posts:
    25
    No, none of the controls for the device change. That must mean I need to add an entry to the HID descriptor some how?
     
  8. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    One way is to set up a custom HID with the given bit (#26) mapped to a control.

    An alternative way is to either listen for events for the device and just read out the bit directly from the event and act on that. Or you can copy the raw state from the device using CopyState() and then query the bit.

    Yet another alternative is to inject the control into the generated layout.

    Code (CSharp):
    1. InputSystem.RegisterLayoutOverride(@"
    2.    {
    3.        ""name"" : ""T16000MWithLeftRightSwitch"",
    4.        ""extend"" : ""HID::Thrustmaster T.16000M"",
    5.        ""controls"" : [
    6.            { ""name"" : ""leftRightSwitch"", ""layout"" : ""Button"", ""bit"" : 26, ""sizeInBits"" : 1 }
    7.        ]
    8.    }
    9. ");
    This should add a "leftRightSwitch" button corresponding to bit #26.
     
  9. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Ah doh, except it's bit 29 not 26 :)
     
  10. NovaDynamics

    NovaDynamics

    Joined:
    Sep 6, 2017
    Posts:
    25
    That works well! I did however have to add "offset" :0 to make it function properly.
    I can't seem to find a CopyState function anywhere though. Is it not in InputSystem.InputControlExtensions?
    Code (CSharp):
    1. InputSystem.RegisterLayoutOverride(@"
    2.           {
    3.               ""name"" : ""T16000MWithLeftRightSwitch"",
    4.               ""extend"" : ""HID::Thrustmaster T.16000M"",
    5.               ""controls"" : [
    6.                   { ""name"" : ""leftRightSwitch"", ""layout"" : ""Button"", ""offset"" : 0, ""bit"" : 29, ""sizeInBits"" : 1 }
    7.               ]
    8.           }
    9.        ");
     
  11. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Ah right, yeah, the device builder will put it at the end of the device otherwise.

    It's here.
     
  12. NovaDynamics

    NovaDynamics

    Joined:
    Sep 6, 2017
    Posts:
    25
    Thank you for all your help! Much appreciated.
     
  13. mrslysly

    mrslysly

    Joined:
    Apr 7, 2022
    Posts:
    1
  14. Zockchster

    Zockchster

    Joined:
    Jan 23, 2019
    Posts:
    1
    molokoTBR1000 and Vakaryan like this.
  15. molokoTBR1000

    molokoTBR1000

    Joined:
    Feb 7, 2023
    Posts:
    1
    this will save time, thanks