Unity setting up custom HID item
So I'm trying to have a Grayhill touch encoder work with Unity on Linux.
When I run sudo cat /dev/usb/hiddev0 | hexdump -C
I am able view raw data from the for the custom HID.
00003560 37 00 01 00 81 ff ff ff 01 00 70 ff 01 00 00 00 |7.........p.....|
00003570 01 00 70 ff 00 00 00 00 01 00 70 ff 01 00 00 00 |..p.......p.....|
The 81 ff ff ff
occurs when I turn right on the HID.
It'll change to 7f 00 00 00
when I turn left.
All the other values remain the same.
I used the official HID documentation to build the following class
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Layouts;
using UnityEditor;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.Utilities;
[StructLayout(LayoutKind.Explicit, Size = 32)]
public class GrayhillControllerReport2 : IInputStateTypeInfo
{
public FourCC format => new FourCC('H', 'I', 'D');
//Bytes that change
[FieldOffset(0)] public byte ReportID;
[FieldOffset(1)] public byte ScreenNumber;
[FieldOffset(2)] public byte Reserved;
[FieldOffset(3)] public byte EventID;
[InputControl(name = "Encoder", layout = "Button")][FieldOffset(4)] public byte Encoder;
[InputControl(name = "TapMask", layout = "Button")][FieldOffset(5)] public short TapMask;
[InputControl(name = "SwipeMask", layout = "Button")][FieldOffset(7)] public byte SwipeMask;
//bytes not changing
[InputControl(name = "Byte8", layout = "Button")][FieldOffset(8)] public byte Byte8;
[InputControl(name = "Byte9", layout = "Button")][FieldOffset(9)] public byte Byte9;
[InputControl(name = "Byte10", layout = "Button")][FieldOffset(10)] public byte Byte10;
[InputControl(name = "Byte11", layout = "Button")][FieldOffset(11)] public byte Byte11;
[InputControl(name = "Byte12", layout = "Button")][FieldOffset(12)] public byte Byte12;
[InputControl(name = "Byte13", layout = "Button")][FieldOffset(13)] public byte Byte13;
[InputControl(name = "Byte14", layout = "Button")][FieldOffset(14)] public byte Byte14;
[InputControl(name = "Byte15", layout = "Button")][FieldOffset(15)] public byte Byte15;
[InputControl(name = "Byte16", layout = "Button")][FieldOffset(16)] public byte Byte16;
[InputControl(name = "Byte17", layout = "Button")][FieldOffset(17)] public byte Byte17;
[InputControl(name = "Byte18", layout = "Button")][FieldOffset(18)] public byte Byte18;
[InputControl(name = "Byte19", layout = "Button")][FieldOffset(19)] public byte Byte19;
[InputControl(name = "Byte20", layout = "Button")][FieldOffset(20)] public byte Byte20;
[InputControl(name = "Byte21", layout = "Button")][FieldOffset(21)] public byte Byte21;
[InputControl(name = "Byte22", layout = "Button")][FieldOffset(22)] public byte Byte22;
[InputControl(name = "Byte24", layout = "Button")][FieldOffset(24)] public byte Byte24;
[InputControl(name = "Byte25", layout = "Button")][FieldOffset(25)] public byte Byte25;
[InputControl(name = "Byte26", layout = "Button")][FieldOffset(26)] public byte Byte26;
[InputControl(name = "Byte27", layout = "Button")][FieldOffset(27)] public byte Byte27;
[InputControl(name = "Byte28", layout = "Button")][FieldOffset(28)] public byte Byte28;
[InputControl(name = "Byte29", layout = "Button")][FieldOffset(29)] public byte Byte29;
[InputControl(name = "Byte30", layout = "Button")][FieldOffset(30)] public byte Byte30;
[InputControl(name = "Byte31", layout = "Button")][FieldOffset(31)] public byte Byte31;
[InputControl(name = "Byte32", layout = "Button")][FieldOffset(32)] public byte Byte32;
}
[InputControlLayout(stateType = typeof(GrayhillControllerReport2))]
#if UNITY_EDITOR
[InitializeOnLoad]
#endif
public class GrayhillHID : InputDevice
{
static GrayhillHID()
{
InputSystem.RegisterLayout<GrayhillHID>("GrayhillINFO",
matches: new InputDeviceMatcher()
.WithInterface("HID")
.WithCapability("idVendor", 0x1658) // VID
.WithCapability("idProduct ", 0x0060)); // PID
}
[RuntimeInitializeOnLoadMethod]
static void Init() { Debug.Log("Startup"); }
}
The following image is the built input controller which would be attached to a gameobject.
Problem is input controller listening and input debugger can not hear anything from the HID.
The PID and HID addresses are from the HID's manual directly, and they also appear when I inspect the HID in CMD. I have no clue why Unity won't read anything from my HID.
I can clearly read data from cmd, but not Unity.
EDIT: looking at raw memory
I get:
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
when viewing raw memory of my HID in input debugger.
I'm 99% sure I'm linking my VID / PID correctly because I can view the HID information in CMD.
It's frustrating because a lot of the documentation online is for the Experimental Input system which got depreciated around a year ago and was replaced with InputSystem. A lot of the old functions do not work on the new stuff.