private static void SendThread() { while (true) { lock (WriteQueue) { if (WriteQueue.Count != 0) { WriteQueueData wqd = WriteQueue.Dequeue(); int res = HIDapi.hid_write(wqd.pointer, wqd.data, new UIntPtr(Convert.ToUInt32(wqd.data.Length))); if (res == -1) Debug.LogError("HidAPI reports error " + res + " on write: " + Marshal.PtrToStringUni(HIDapi.hid_error(wqd.pointer))); else if (Debug_Messages) Debug.Log("Sent " + res + "b: [" + wqd.data[0].ToString("X").PadLeft(2, '0') + "] " + BitConverter.ToString(wqd.data, 1)); } } Thread.Sleep(MaxWriteFrequency); } }
public static int SendRaw(IntPtr hidapi_handle, byte[] data) { if (hidapi_handle == IntPtr.Zero) return -2; if (WriteQueue == null) { WriteQueue = new Queue<WriteQueueData>(); SendThreadObj = new Thread(new ThreadStart(SendThread)); SendThreadObj.Start(); } WriteQueueData wqd = new WriteQueueData(); wqd.pointer = hidapi_handle; wqd.data = data; lock (WriteQueue) WriteQueue.Enqueue(wqd); return 0; }
/// \brief Sends RAW DATA to the given bluetooth HID device. This is essentially a wrapper around HIDApi. /// \param hidapi_wiimote The HIDApi device handle to write to. /// \param data The data to write. /// \sa Wiimote::SendWithType(OutputDataType, byte[]) /// \warning DO NOT use this unless you absolutely need to bypass the given Wiimote communication functions. /// Use the functionality provided by Wiimote instead. public static int SendRaw(IntPtr hidapi_wiimote, byte[] data) { if (hidapi_wiimote == IntPtr.Zero) return -2; if (WriteQueue == null) { WriteQueue = new Queue<WriteQueueData>(); SendThreadObj = new Thread(new ThreadStart(SendThread)); SendThreadObj.Start(); } WriteQueueData wqd = new WriteQueueData(); wqd.pointer = hidapi_wiimote; wqd.data = data; lock (WriteQueue) WriteQueue.Enqueue(wqd); return 0; // TODO: Better error handling }
public static int SendRaw(IntPtr hidapi_handle, byte[] data) { if (hidapi_handle == IntPtr.Zero) { return(-2); } if (WriteQueue == null) { WriteQueue = new Queue <WriteQueueData>(); SendThreadObj = new Thread(new ThreadStart(SendThread)); SendThreadObj.Start(); } WriteQueueData wqd = new WriteQueueData(); wqd.pointer = hidapi_handle; wqd.data = data; lock (WriteQueue) WriteQueue.Enqueue(wqd); return(0); }