//static void input_callback(void *context, IOReturn ret, void *sender, //IOHIDReportType type, uint32_t id, uint8_t *data, CFIndex len) internal void InputReportCallback( IntPtr inContext, // context from IOHIDDeviceRegisterInputReportCallback IOReturn inResult, // completion result for the input report operation IOHIDDeviceRef inSender, // IOHIDDeviceRef of the device this report is from Native.IOHIDReportType inType, // the report type uint inReportID, // the report ID IntPtr inReport, // pointer to the report data int inReportLength) { GenericHIDDevice hidDevice; if (inContext != IntPtr.Zero) { hidDevice = (GenericHIDDevice)GCHandle.FromIntPtr(inContext).Target; if (hidDevice.__deviceHandle != inSender) { return; } byte[] buffer = new byte[hidDevice.InputReportByteLength]; Marshal.Copy(inReport, buffer, 0, hidDevice.InputReportByteLength); hidDevice.__lastHIDReport.Data = buffer; hidDevice.__lastHIDReport.Status = HIDReport.ReadStatus.Success; //UnityEngine.Debug.Log (BitConverter.ToString (buffer)); hidDevice.IsReadInProgress = false; //Marshal.FreeHGlobal (inReport); //Native.IOHIDDeviceRegisterInputReportCallback (hidDevice.__deviceHandle, IntPtr.Zero, 0, IntPtr.Zero, IntPtr.Zero); hidDevice.InputAutoResetEvent.Set(); } else { UnityEngine.Debug.LogError("InputReportCallback inContext ZeroPointer"); } }
internal void OutputReportCallback( IntPtr inContext, // context from IOHIDDeviceRegisterInputReportCallback IOReturn inResult, // completion result for the input report operation IOHIDDeviceRef inSender, // IOHIDDeviceRef of the device this report is from Native.IOHIDReportType inType, // the report type uint inReportID, // the report ID IntPtr inReport, // pointer to the report data int inReportLength) { GenericHIDDevice hidDevice; if (inContext != IntPtr.Zero) { hidDevice = (GenericHIDDevice)GCHandle.FromIntPtr(inContext).Target; hidDevice.OutputAutoResetEvent.Set(); } else { UnityEngine.Debug.LogError("OutputReportCallback inContext ZeroPointer"); } }