'How to send data to HID device in Unity Input System
I managed to implement the HID device in Unity Input System and I can read from it easily. But how to send data back to the HID device?
This is the IInputDeviceCommandInfo implementation I have:
[StructLayout(LayoutKind.Explicit)]
internal struct MyControlCommand : IInputDeviceCommandInfo
{
public static FourCC Type { get { return new FourCC("HIDO"); } }
[FieldOffset(0)]
public byte res;
[FieldOffset(1)]
public byte magic;
[FieldOffset(2)]
public byte DataType;
[FieldOffset(3)]
public short Data;
public FourCC typeStatic
{
get { return Type; }
}
public static MyControlCommand Create(byte dataType, short data)
{
return new MyControlCommand
{
magic = 0x7e,
DataType = dataType,
Data = data
};
}
}
I wanted to send these bytes:
0
0x7e
0x04
0xfff
So I used:
var c = MyControlCommand.Create(0x04, 0xfff);
var res = current.ExecuteCommand(ref c);
The res variable gets -1, so It's unsuccessful.
I managed to communicate with the device (above bytes worked fine) using HidSharp library and my own HID implementation, but Unity is stubborn...
Thanks for help!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
