Ejemplo n.º 1
0
        protected void SetupInput()
        {
            if (IsOpen)
            {
                byte[] buffer = CreateInputBuffer();



                __InputBufferPtr = Marshal.AllocHGlobal(buffer.Length);
                Marshal.Copy(buffer, 0, __InputBufferPtr, buffer.Length);


                if (!DeviceGCHandle.IsAllocated)
                {
                    DeviceGCHandle = GCHandle.Alloc(this);



                    // Schedule the device on the current run loop in case it isn't already scheduled
                    Native.IOHIDDeviceScheduleWithRunLoop(__deviceHandle, RunLoop, Native.RunLoopModeDefault);

//					_scheduleWithRunLoop=true;


                    // Register a callback
                    Native.IOHIDDeviceRegisterInputReportCallback(__deviceHandle, __InputBufferPtr, buffer.Length, InputReportCallback,

                                                                  GCHandle.ToIntPtr(DeviceGCHandle));

                    //				_registeredToInputReport=true;
                }
            }
        }
Ejemplo n.º 2
0
        public override HIDReport ReadDefault()
        {
            if (IsOpen == false)
            {
                OpenDevice();
            }



            //do this only once
            if (!DeviceGCHandle.IsAllocated)
            {
                try {
                    DeviceGCHandle = GCHandle.Alloc(this);

                    // The device is not normally available in the InputValueCallback (HandleDeviceValueReceived), so we include
                    // the device identifier as the context variable, so we can identify it and figure out the device later.


                    Native.IOHIDDeviceRegisterInputValueCallback(__deviceHandle, DeviceValueReceived, GCHandle.ToIntPtr(DeviceGCHandle));
                    //_registeredToInputReport=true;

                    Native.IOHIDDeviceScheduleWithRunLoop(__deviceHandle, RunLoop, Native.RunLoopModeDefault);
                    //_scheduleWithRunLoop=true;
                } catch (Exception e) {
                    UnityEngine.Debug.LogException(e);
                }
            }

            return(__lastHIDReport);
        }