/// <summary> /// This method will construct all the member classes and enumerate all the sensors /// </summary> void CMainWindow::InitializeResource() { // Set the dialog icon NuiViewer::SetIcon(m_hWnd); // Set window minimum track size m_minTrackWidth = GetWindowSize(m_hWnd).cx; // Load url string LoadStringW(GetModuleHandle(0), IDS_MOREINFOURL, m_moreInfoLinkUrl, MaxStringChars); // Set text font style SendMessageW(GetHandle(IDC_CONNECTEDDEVICESTEXT), WM_SETFONT, (WPARAM)LargeTextFont, 0); SendMessageW(GetHandle(IDC_REQUIREDSENSORTEXT), WM_SETFONT, (WPARAM)LargeTextFont, 0); SendMessageW(GetHandle(IDC_STATUSTEXT), WM_SETFONT, (WPARAM)LargeTextFont, 0); // Set the logo picture HBITMAP hLogoImage = nullptr; EnsureImageLoaded(hLogoImage, IDB_LOGO); SendMessageW(GetHandle(IDC_LOGOPICTURE), STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hLogoImage); // Create sensor list instance m_pSensorListControl = new SensorListControl(GetHandle(IDC_KINECTSENSORLIST)); // Create status log list instance m_pStatusLogListControl = new StatusLogListControl(GetHandle(IDC_STATUSLOGLIST)); // Create kinect window manager instance m_pKinectWindowMgr = new KinectWindowManager(m_hWnd); // Construct all the sensors EnumerateSensors(); // Upate layout and show/hide status UpdateLayoutAndShowStatus(); }
XnStatus XnSensorIO::OpenDevice(const XnChar* strPath) { XnStatus nRetVal; XnUSBDeviceSpeed DevSpeed; nRetVal = xnUSBInit(); if (nRetVal != XN_STATUS_OK && nRetVal != XN_STATUS_USB_ALREADY_INIT) return nRetVal; xnLogVerbose(XN_MASK_DEVICE_IO, "Connecting to USB device..."); if (strPath == NULL || strcmp(strPath, "*:0") == 0) { // support old style API XnConnectionString aConnections[1]; XnUInt32 nCount = 1; nRetVal = EnumerateSensors(aConnections, &nCount); if (nRetVal != XN_STATUS_OK && nRetVal != XN_STATUS_OUTPUT_BUFFER_OVERFLOW) { return nRetVal; } strPath = aConnections[0]; } // try to open the device xnLogVerbose(XN_MASK_DEVICE_IO, "Trying to open sensor '%s'...", strPath); nRetVal = xnUSBOpenDeviceByPath(strPath, &m_pSensorHandle->USBDevice); XN_IS_STATUS_OK(nRetVal); nRetVal = xnUSBGetDeviceSpeed(m_pSensorHandle->USBDevice, &DevSpeed); XN_IS_STATUS_OK(nRetVal); if (DevSpeed != XN_USB_DEVICE_HIGH_SPEED) { XN_LOG_WARNING_RETURN(XN_STATUS_USB_UNKNOWN_DEVICE_SPEED, XN_MASK_DEVICE_IO, "Device is not high speed!"); } // on older firmwares, control was sent over BULK endpoints. Check if this is the case xnLogVerbose(XN_MASK_DEVICE_IO, "Trying to open endpoint 0x4 for control out (for old firmwares)..."); nRetVal = xnUSBOpenEndPoint(m_pSensorHandle->USBDevice, 0x4, XN_USB_EP_BULK, XN_USB_DIRECTION_OUT, &m_pSensorHandle->ControlConnection.ControlOutConnectionEp); if (nRetVal == XN_STATUS_USB_ENDPOINT_NOT_FOUND || nRetVal == XN_STATUS_USB_WRONG_ENDPOINT_TYPE || nRetVal == XN_STATUS_USB_WRONG_ENDPOINT_DIRECTION) { // this is not the case. use regular control endpoint (0) m_pSensorHandle->ControlConnection.bIsBulk = FALSE; } else { XN_IS_STATUS_OK(nRetVal); xnLogVerbose(XN_MASK_DEVICE_IO, "Opening endpoint 0x85 for control in..."); nRetVal = xnUSBOpenEndPoint(m_pSensorHandle->USBDevice, 0x85, XN_USB_EP_BULK, XN_USB_DIRECTION_IN, &m_pSensorHandle->ControlConnection.ControlInConnectionEp); XN_IS_STATUS_OK(nRetVal); m_pSensorHandle->ControlConnection.bIsBulk = TRUE; } nRetVal = IsSensorLowBandwidth(strPath, &m_bIsLowBandwidth); XN_IS_STATUS_OK(nRetVal); xnLogInfo(XN_MASK_DEVICE_IO, "Connected to USB device%s", m_bIsLowBandwidth ? " (LowBand)" : ""); strcpy(m_strDeviceName, strPath); return XN_STATUS_OK; }