示例#1
0
        private void handleLostDevice(ref LEAP_DEVICE_EVENT deviceMsg)
        {
            Device lost = _devices.FindDeviceByHandle(deviceMsg.device.handle);

            if (lost != null)
            {
                _devices.Remove(lost);
                this.LeapDeviceLost.Dispatch(this, new DeviceEventArgs(lost));
            }
        }
示例#2
0
        private void handleDevice(ref LEAP_DEVICE_EVENT deviceMsg)
        {
            IntPtr deviceHandle = deviceMsg.device.handle;

            if (deviceHandle == IntPtr.Zero)
            {
                return;
            }

            LEAP_DEVICE_INFO deviceInfo = new LEAP_DEVICE_INFO();
            eLeapRS          result;

            IntPtr device;

            result = LeapC.OpenDevice(deviceMsg.device, out device);
            if (result != eLeapRS.eLeapRS_Success)
            {
                return;
            }

            deviceInfo.serial = IntPtr.Zero;
            deviceInfo.size   = (uint)Marshal.SizeOf(deviceInfo);
            result            = LeapC.GetDeviceInfo(device, ref deviceInfo); //Query the serial length
            if (result != eLeapRS.eLeapRS_Success)
            {
                return;
            }

            deviceInfo.serial = Marshal.AllocCoTaskMem((int)deviceInfo.serial_length);
            result            = LeapC.GetDeviceInfo(device, ref deviceInfo); //Query the serial

            if (result == eLeapRS.eLeapRS_Success)
            {
                Device apiDevice = new Device(deviceHandle,
                                              device,
                                              deviceInfo.h_fov,              //radians
                                              deviceInfo.v_fov,              //radians
                                              deviceInfo.range / 1000.0f,    //to mm
                                              deviceInfo.baseline / 1000.0f, //to mm
                                              (Device.DeviceType)deviceInfo.type,
                                              deviceInfo.status,
                                              Marshal.PtrToStringAnsi(deviceInfo.serial));
                Marshal.FreeCoTaskMem(deviceInfo.serial);
                _devices.AddOrUpdate(apiDevice);

                if (LeapDevice != null)
                {
                    LeapDevice.DispatchOnContext(this, EventContext, new DeviceEventArgs(apiDevice));
                }
            }
        }
        private void handleDevice(ref LEAP_DEVICE_EVENT deviceMsg)
        {
            IntPtr deviceHandle = deviceMsg.device.handle;

            if (deviceHandle == IntPtr.Zero)
            {
                return;
            }

            LEAP_DEVICE_INFO deviceInfo = new LEAP_DEVICE_INFO();
            eLeapRS          result;

            IntPtr device;

            result = LeapC.OpenDevice(deviceMsg.device, out device);
            uint defaultLength = 14;

            deviceInfo.serial_length = defaultLength;
            deviceInfo.serial        = Marshal.AllocCoTaskMem((int)defaultLength);
            deviceInfo.size          = (uint)Marshal.SizeOf(deviceInfo);
            result = LeapC.GetDeviceInfo(device, out deviceInfo);

            if (result == eLeapRS.eLeapRS_InsufficientBuffer)
            {
                Marshal.FreeCoTaskMem(deviceInfo.serial);
                deviceInfo.serial = Marshal.AllocCoTaskMem((int)deviceInfo.serial_length);
                deviceInfo.size   = (uint)Marshal.SizeOf(deviceInfo);
                result            = LeapC.GetDeviceInfo(deviceHandle, out deviceInfo);
            }

            if (result == eLeapRS.eLeapRS_Success)
            {
                Device apiDevice = new Device(deviceHandle,
                                              deviceInfo.h_fov,           //radians
                                              deviceInfo.v_fov,           //radians
                                              deviceInfo.range / 1000,    //to mm
                                              deviceInfo.baseline / 1000, //to mm
                                              (deviceInfo.caps == (UInt32)eLeapDeviceCaps.eLeapDeviceCaps_Embedded),
                                              (deviceInfo.status == (UInt32)eLeapDeviceStatus.eLeapDeviceStatus_Streaming),
                                              Marshal.PtrToStringAnsi(deviceInfo.serial));
                Marshal.FreeCoTaskMem(deviceInfo.serial);
                _devices.AddOrUpdate(apiDevice);
                this.LeapDevice.Dispatch(this, new DeviceEventArgs(apiDevice));
            }
        }
示例#4
0
        //Run in Polster thread, fills in object queues
        private void processMessages()
        {
            try
            {
                eLeapRS result;
                _leapInit.Dispatch <LeapEventArgs>(this, new LeapEventArgs(LeapEvent.EVENT_INIT));
                while (true)
                {
                    LEAP_CONNECTION_MESSAGE _msg = new LEAP_CONNECTION_MESSAGE();
                    lock (_connLocker) {
                        if (_leapConnection == IntPtr.Zero)
                        {
                            break;
                        }
                        uint timeout = 1000;
                        result = LeapC.PollConnection(_leapConnection, timeout, ref _msg);
                    }

                    if (result != eLeapRS.eLeapRS_Success)
                    {
                        reportAbnormalResults("LeapC PollConnection call was ", result);
                        continue;
                    }

                    switch (_msg.type)
                    {
                    case eLeapEventType.eLeapEventType_Connection:
                        LEAP_CONNECTION_EVENT connection_evt = StructMarshal <LEAP_CONNECTION_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleConnection(ref connection_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ConnectionLost:
                        LEAP_CONNECTION_LOST_EVENT connection_lost_evt = StructMarshal <LEAP_CONNECTION_LOST_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleConnectionLost(ref connection_lost_evt);
                        break;

                    case eLeapEventType.eLeapEventType_Device:
                        LEAP_DEVICE_EVENT device_evt = StructMarshal <LEAP_DEVICE_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleDevice(ref device_evt);
                        break;

                    case eLeapEventType.eLeapEventType_DeviceLost:
                        LEAP_DEVICE_EVENT device_lost_evt = StructMarshal <LEAP_DEVICE_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleLostDevice(ref device_lost_evt);
                        break;

                    case eLeapEventType.eLeapEventType_DeviceFailure:
                        LEAP_DEVICE_FAILURE_EVENT device_failure_evt = StructMarshal <LEAP_DEVICE_FAILURE_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleFailedDevice(ref device_failure_evt);
                        break;

                    case eLeapEventType.eLeapEventType_Tracking:
                        LEAP_TRACKING_EVENT tracking_evt = StructMarshal <LEAP_TRACKING_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleTrackingMessage(ref tracking_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ImageComplete:
                        completeCount++;
                        LEAP_IMAGE_COMPLETE_EVENT image_complete_evt = StructMarshal <LEAP_IMAGE_COMPLETE_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleImageCompletion(ref image_complete_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ImageRequestError:
                        failedCount++;
                        LEAP_IMAGE_FRAME_REQUEST_ERROR_EVENT failed_image_evt = StructMarshal <LEAP_IMAGE_FRAME_REQUEST_ERROR_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleFailedImageRequest(ref failed_image_evt);
                        break;

                    case eLeapEventType.eLeapEventType_LogEvent:
                        LEAP_LOG_EVENT log_evt = StructMarshal <LEAP_LOG_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        reportLogMessage(ref log_evt);
                        break;

                    case eLeapEventType.eLeapEventType_PolicyChange:
                        LEAP_POLICY_EVENT policy_evt = StructMarshal <LEAP_POLICY_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handlePolicyChange(ref policy_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ConfigChange:
                        LEAP_CONFIG_CHANGE_EVENT config_change_evt = StructMarshal <LEAP_CONFIG_CHANGE_EVENT> .PtrToStruct(_msg.eventStructPtr);

                        handleConfigChange(ref config_change_evt);
                        break;

                    case eLeapEventType.eLeapEventType_ConfigResponse:
                        handleConfigResponse(ref _msg);
                        break;

                    default:
                        //discard unknown message types
                        Logger.Log("Unhandled message type " + Enum.GetName(typeof(eLeapEventType), _msg.type));
                        break;
                    } //switch on _msg.type
                }     //while running
            }
            catch (Exception e)
            {
                Logger.Log("Exception: " + e);
                this.Cleanup();
            }
        }
示例#5
0
        //Run in Polster thread, fills in object queues
        private void processMessages()
        {
            try
            {
                eLeapRS result;
                LeapInit.Dispatch <LeapEventArgs>(this, new LeapEventArgs(LeapEvent.EVENT_INIT));
                while (_isRunning)
                {
                    if (_leapConnection != IntPtr.Zero)
                    {
                        LEAP_CONNECTION_MESSAGE _msg = new LEAP_CONNECTION_MESSAGE();
                        uint timeout = 1000;
                        result = LeapC.PollConnection(_leapConnection, timeout, ref _msg);
                        reportAbnormalResults("LeapC PollConnection call was ", result);
                        if (result == eLeapRS.eLeapRS_Success)
                        {
                            switch (_msg.type)
                            {
                            case eLeapEventType.eLeapEventType_Connection:
                                LEAP_CONNECTION_EVENT connection_evt = LeapC.PtrToStruct <LEAP_CONNECTION_EVENT>(_msg.eventStructPtr);
                                handleConnection(ref connection_evt);
                                break;

                            case eLeapEventType.eLeapEventType_ConnectionLost:
                                LEAP_CONNECTION_LOST_EVENT connection_lost_evt = LeapC.PtrToStruct <LEAP_CONNECTION_LOST_EVENT>(_msg.eventStructPtr);
                                handleConnectionLost(ref connection_lost_evt);
                                break;

                            case eLeapEventType.eLeapEventType_Device:
                                LEAP_DEVICE_EVENT device_evt = LeapC.PtrToStruct <LEAP_DEVICE_EVENT>(_msg.eventStructPtr);
                                handleDevice(ref device_evt);
                                break;

                            case eLeapEventType.eLeapEventType_DeviceLost:
                                LEAP_DEVICE_EVENT device_lost_evt = LeapC.PtrToStruct <LEAP_DEVICE_EVENT>(_msg.eventStructPtr);
                                handleLostDevice(ref device_lost_evt);
                                break;

                            case eLeapEventType.eLeapEventType_DeviceFailure:
                                LEAP_DEVICE_FAILURE_EVENT device_failure_evt = LeapC.PtrToStruct <LEAP_DEVICE_FAILURE_EVENT>(_msg.eventStructPtr);
                                handleFailedDevice(ref device_failure_evt);
                                break;

                            case eLeapEventType.eLeapEventType_Tracking:
                                LEAP_TRACKING_EVENT tracking_evt = LeapC.PtrToStruct <LEAP_TRACKING_EVENT>(_msg.eventStructPtr);
                                handleTrackingMessage(ref tracking_evt);
                                break;

                            case eLeapEventType.eLeapEventType_ImageComplete:
                                completeCount++;
                                LEAP_IMAGE_COMPLETE_EVENT image_complete_evt = LeapC.PtrToStruct <LEAP_IMAGE_COMPLETE_EVENT>(_msg.eventStructPtr);
                                handleImageCompletion(ref image_complete_evt);
                                break;

                            case eLeapEventType.eLeapEventType_ImageRequestError:
                                failedCount++;
                                LEAP_IMAGE_FRAME_REQUEST_ERROR_EVENT failed_image_evt = LeapC.PtrToStruct <LEAP_IMAGE_FRAME_REQUEST_ERROR_EVENT>(_msg.eventStructPtr);
                                handleFailedImageRequest(ref failed_image_evt);
                                break;

                            case eLeapEventType.eLeapEventType_TrackedQuad:
                                LEAP_TRACKED_QUAD_EVENT quad_evt = LeapC.PtrToStruct <LEAP_TRACKED_QUAD_EVENT>(_msg.eventStructPtr);
                                handleQuadMessage(ref quad_evt);
                                break;

                            case eLeapEventType.eLeapEventType_LogEvent:
                                LEAP_LOG_EVENT log_evt = LeapC.PtrToStruct <LEAP_LOG_EVENT>(_msg.eventStructPtr);
                                reportLogMessage(ref log_evt);
                                break;

                            case eLeapEventType.eLeapEventType_PolicyChange:
                                LEAP_POLICY_EVENT policy_evt = LeapC.PtrToStruct <LEAP_POLICY_EVENT>(_msg.eventStructPtr);
                                handlePolicyChange(ref policy_evt);
                                break;

                            case eLeapEventType.eLeapEventType_ConfigChange:
                                LEAP_CONFIG_CHANGE_EVENT config_change_evt = LeapC.PtrToStruct <LEAP_CONFIG_CHANGE_EVENT>(_msg.eventStructPtr);
                                handleConfigChange(ref config_change_evt);
                                break;

                            case eLeapEventType.eLeapEventType_ConfigResponse:
                                handleConfigResponse(ref _msg);
                                break;

                            default:
                                //discard unknown message types
                                Logger.Log("Unhandled message type " + Enum.GetName(typeof(eLeapEventType), _msg.type));
                                break;
                            } //switch on _msg.type
                        }     // if valid _msg.type
                        else if (result == eLeapRS.eLeapRS_NotConnected)
                        {
                            this.LeapConnectionLost.Dispatch <ConnectionLostEventArgs>(this, new ConnectionLostEventArgs());
                            result = LeapC.CreateConnection(out _leapConnection);
                            reportAbnormalResults("LeapC CreateConnection call was ", result);
                            result = LeapC.OpenConnection(_leapConnection);
                            reportAbnormalResults("LeapC OpenConnection call was ", result);
                        }
                    } // if have connection handle
                }     //while running
            }
            catch (Exception e)
            {
                Logger.Log("Exception: " + e);
            }
        }