Search Unity

HID Sharp - Human Interface Device

Discussion in 'Scripting' started by Spy-Shifty, Jul 7, 2015.

  1. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    Hi guys,

    does anyone made some experience with the HID Sharp lib and unity?
    http://www.zer7.com/software/hidsharp

    I tried it and it works... But its really slow on data receiving and I don't know why....
    I have a abstract device class...

    Code (CSharp):
    1. public abstract class Device {
    2.     public HidDevice HidDevice { get; private set; }
    3.  
    4.     protected event EventHandler ReadedData;
    5.     protected HidStream stream;
    6.     protected byte[] readBuffer;
    7.  
    8.     public void LoadDevice(HidDevice device) {
    9.         HidDevice = device;
    10.         HidDevice.TryOpen(out stream);
    11.         //ReadInput();
    12.         Thread t = new Thread(new ThreadStart(ReadData));
    13.         t.Start();
    14.     }
    15.  
    16.     private void ReadData() {
    17.         while (true) {
    18.             lock (stream) {
    19.                 readBuffer = stream.Read();
    20.             }
    21.             if (ReadedData != null) {
    22.                 ReadedData(this, EventArgs.Empty);
    23.             }
    24.             Thread.Sleep(100);
    25.         }
    26.     }
    27. }
    If I decrease the Thread.Sleep value, nothing will be readed anymore.
    Perhaps I miss something or I did something wrong...

    Hope someone can help me :)
    Thanks in advance!


    PS. I want to use this for steering wheel and force feedback... so I cant use unity's standard input system...
    And I also read this article http://unity3de.blogspot.de/2014/06/unity-input-manger-pain-is-spreading.html
    But the tool has bugs and the source is terrible...