void Rift_Tracker::StartTracker(QFrame*) { System::Init(Log::ConfigureDefaultLog(LogMask_All)); pManager = DeviceManager::Create(); if (pManager != NULL) { DeviceEnumerator<OVR::SensorDevice> enumerator = pManager->EnumerateDevices<OVR::SensorDevice>(); if (enumerator.IsAvailable()) { pSensor = enumerator.CreateDevice(); if (pSensor){ pSFusion = new OVR::SensorFusion(); pSFusion->Reset(); pSFusion->AttachToSensor(pSensor); }else{ QMessageBox::warning(0,"FaceTrackNoIR Error", "Unable to create Rift sensor",QMessageBox::Ok,QMessageBox::NoButton); } }else{ QMessageBox::warning(0,"FaceTrackNoIR Error", "Unable to enumerate Rift tracker",QMessageBox::Ok,QMessageBox::NoButton); } }else{ QMessageBox::warning(0,"FaceTrackNoIR Error", "Unable to start Rift tracker",QMessageBox::Ok,QMessageBox::NoButton); } }
DeviceEnumerator<> DeviceManagerImpl::EnumerateDevicesEx(const DeviceEnumerationArgs& args) { Lock::Locker deviceLock(GetLock()); if (Devices.IsEmpty()) return DeviceEnumerator<>(); DeviceCreateDesc* firstDeviceDesc = Devices.GetFirst(); DeviceEnumerator<> e = enumeratorFromHandle(DeviceHandle(firstDeviceDesc), args); if (!args.MatchRule(firstDeviceDesc->Type, firstDeviceDesc->Enumerated)) { e.Next(); } return e; }
int GlobalState::EnumerateDevices() { // Need to use separate lock for device enumeration, as pManager->GetHandlerLock() // would produce deadlocks here. Lock::Locker lock(&EnumerationLock); EnumeratedDevices.Clear(); DeviceEnumerator<HMDDevice> e = pManager->EnumerateDevices<HMDDevice>(); while(e.IsAvailable()) { EnumeratedDevices.PushBack(DeviceHandle(e)); e.Next(); } return (int)EnumeratedDevices.GetSize(); }
int InputTestApp::OnStartup(int argc, const char** argv) { if (!pPlatform->SetupWindow(1200,800)) return 1; pManager = *DeviceManager::Create(); // This initialization logic supports running two sensors at the same time. DeviceEnumerator<SensorDevice> isensor = pManager->EnumerateDevices<SensorDevice>(); DeviceEnumerator<SensorDevice> oculusSensor; DeviceEnumerator<SensorDevice> oculusSensor2; while(isensor) { DeviceInfo di; if (isensor.GetDeviceInfo(&di)) { if (strstr(di.ProductName, "Tracker")) { if (!oculusSensor) oculusSensor = isensor; else if (!oculusSensor2) oculusSensor2 = isensor; } } isensor.Next(); } if (oculusSensor) { pSensor = *oculusSensor.CreateDevice(); if (pSensor) pSensor->SetRange(SensorRange(4 * 9.81f, 8 * Math<float>::Pi, 1.0f), true); if (oculusSensor2) { // Second Oculus sensor, useful for comparing firmware behavior & settings. pSensor2 = *oculusSensor2.CreateDevice(); if (pSensor2) pSensor2->SetRange(SensorRange(4 * 9.81f, 8 * Math<float>::Pi, 1.0f), true); } } oculusSensor.Clear(); oculusSensor2.Clear(); /* DeviceHandle hHMD = pManager->EnumerateDevices<HMDDevice>(); HMDInfo hmdInfo; if (hHMD) { hHMD.GetDeviceInfo(&hmdInfo); } */ if (pSensor) SFusion.AttachToSensor(pSensor); if (pSensor2) SFusion2.AttachToSensor(pSensor2); /* // Test rotation: This give rotations clockwise (CW) while looking from // origin in the direction of the axis. Vector3f xV(1,0,0); Vector3f zV(0,0,1); Vector3f rxV = Matrix4f::RotationZ(DegreeToRad(10.0f)).Transform(xV); Vector3f ryV = Matrix4f::RotationY(DegreeToRad(10.0f)).Transform(xV); Vector3f rzV = Matrix4f::RotationX(DegreeToRad(10.0f)).Transform(zV); */ // Report relative mouse motion (not absolute position) // pPlatform->SetMouseMode(Mouse_Relative); const char* graphics = "d3d10"; for (int i = 1; i < argc; i++) if (!strcmp(argv[i], "-r") && i < argc-1) graphics = argv[i+1]; pRender = pPlatform->SetupGraphics(OVR_DEFAULT_RENDER_DEVICE_SET, graphics, RendererParams()); //WireframeFill = pRender->CreateSimpleFill(Fill::F_Wireframe); // *** Rotating Box pBox = *new Container; pBox->Add(Ptr<Model>( *Model::CreateAxisFaceColorBox(-2.0f, 2.0f, Color(0, 0xAA, 0), // x = green -1.0f, 1.0f, Color(0xAA,0, 0), // y = red -1.0f, 1.0f, Color(0, 0, 0xAA)) )); // z = blue // Drop-down line from box, to make it easier to see differences in angle. Ptr<Model> downLine = *new Model(Prim_Lines); downLine->AddLine(Vertex(0.0f,-4.5f, 0.0f, 0xFFE0B0B0), Vertex(0.0f, 0.0f, 0.0f, 0xFFE0B0B0)); pBox->Add(downLine); Sc.World.Add(pBox); // Secondary rotating coordinate object, if we have two values. if (pSensor2) { pBox2 = *new Container; // Drop-down line from box, to make it easier to see differences in angle. Ptr<Model> lines = *new Model(Prim_Lines); lines->AddLine(Vertex( 0.0f,-4.0f, 0.0f, 0xFFA07070), // -Y Vertex( 0.0f, 0.0f, 0.0f, 0xFFA07070)); lines->AddLine(Vertex(-4.0f, 0.0f, 0.0f, 0xFF70A070), // -X Vertex( 0.0f, 0.0f, 0.0f, 0xFF70A070)); lines->AddLine(Vertex( 0.0f, 0.0f,-4.0f, 0xFF7070A0), // -Z Vertex( 0.0f, 0.0f, 0.0f, 0xFF7070A0)); pBox2->Add(lines); Sc.World.Add(pBox2); } // *** World axis X,Y,Z rendering. pAxes = *new Model(Prim_Lines); pAxes->AddLine(Vertex(-8.0f, 0.0f, 0.0f, 0xFF40FF40), Vertex( 8.0f, 0.0f, 0.0f, 0xFF40FF40)); // X pAxes->AddLine(Vertex( 7.6f, 0.4f, 0.4f, 0xFF40FF40), Vertex( 8.0f, 0.0f, 0.0f, 0xFF40FF40)); // X - arrow pAxes->AddLine(Vertex( 7.6f,-0.4f,-0.4f, 0xFF40FF40), Vertex( 8.0f, 0.0f, 0.0f, 0xFF40FF40)); // X - arrow pAxes->AddLine(Vertex( 0.0f,-8.0f, 0.0f, 0xFFFF4040), Vertex( 0.0f, 8.0f, 0.0f, 0xFFFF4040)); // Y pAxes->AddLine(Vertex( 0.4f, 7.6f, 0.0f, 0xFFFF4040), Vertex( 0.0f, 8.0f, 0.0f, 0xFFFF4040)); // Y - arrow pAxes->AddLine(Vertex(-0.4f, 7.6f, 0.0f, 0xFFFF4040), Vertex( 0.0f, 8.0f, 0.0f, 0xFFFF4040)); // Y pAxes->AddLine(Vertex( 0.0f, 0.0f,-8.0f, 0xFF4040FF), Vertex( 0.0f, 0.0f, 8.0f, 0xFF4040FF)); // Z pAxes->AddLine(Vertex( 0.4f, 0.0f, 7.6f, 0xFF4040FF), Vertex( 0.0f, 0.0f, 8.0f, 0xFF4040FF)); // Z - arrow pAxes->AddLine(Vertex(-0.4f, 0.0f, 7.6f, 0xFF4040FF), Vertex( 0.0f, 0.0f, 8.0f, 0xFF4040FF)); // Z - arrow Sc.World.Add(pAxes); SetView(CurrentView); LastUpdate = pPlatform->GetAppTime(); return 0; }
HRESULT Rayman2InputFix_DirectInputA::EnumDevices(DWORD dwDevType, LPDIENUMDEVICESCALLBACKA lpCallback, LPVOID pvRef, DWORD dwFlags) { Debug("DI: EnumDevices called\n"); Debug("dwDevType == %d\n", dwDevType); #if 1 HRESULT hr; // The bug: Rayman 2 expects EnumDevices to give results in a certain // order, where gamepads come before the keyboard. DirectInput makes // no guarantee about the order. // The fix: Call DirectInput's EnumDevices, then sort the results in // an order where gamepads come first, then give them to Rayman 2. typedef std::list<DIDEVICEINSTANCEA> DeviceInstanceList; struct DeviceEnumerator { DeviceInstanceList devices; static BOOL FAR PASCAL Callback(LPCDIDEVICEINSTANCEA lpddi, LPVOID pvRef) { DeviceEnumerator* self = (DeviceEnumerator*)pvRef; self->devices.push_back(*lpddi); return DIENUM_CONTINUE; } bool Contains(const GUID& guidInstance) { for (DeviceInstanceList::const_iterator it = devices.begin(); it != devices.end(); ++it) { if (it->guidInstance == guidInstance) { return true; } } return false; } }; DeviceEnumerator joystickDevices; hr = m_realDirectInput->EnumDevices(DIDEVTYPE_JOYSTICK, DeviceEnumerator::Callback, &joystickDevices, dwFlags); if (FAILED(hr)) { return hr; } DeviceEnumerator allDevices; hr = m_realDirectInput->EnumDevices(0, DeviceEnumerator::Callback, &allDevices, dwFlags); if (FAILED(hr)) { return hr; } DeviceInstanceList sortedDevices; if (dwDevType == 0 || dwDevType == DIDEVTYPE_JOYSTICK) { // Add all devices in gameDevices for (DeviceInstanceList::const_iterator it = joystickDevices.devices.begin(); it != joystickDevices.devices.end(); ++it) { sortedDevices.push_back(*it); } } if (dwDevType == 0) { // Then, add all devices in allDevices that aren't in gameDevices for (DeviceInstanceList::const_iterator it = allDevices.devices.begin(); it != allDevices.devices.end(); ++it) { if (!joystickDevices.Contains(it->guidInstance)) { sortedDevices.push_back(*it); } } } for (DeviceInstanceList::const_iterator it = sortedDevices.begin(); it != sortedDevices.end(); ++it) { OutputDebugStringA("Enumerating Product: "); OutputDebugStringA(it->tszProductName); OutputDebugStringA(" Instance: "); OutputDebugStringA(it->tszInstanceName); OutputDebugStringA("\n"); if (lpCallback(&*it, pvRef) == DIENUM_STOP) { break; } } return DI_OK; #else return m_realDirectInput->EnumDevices(dwDevType, lpCallback, pvRef, dwFlags); #endif }
bool DeviceTypeManager::update_connected_devices() { bool success = false; // Don't do any connection opening/closing until all pending bluetooth operations are finished if (can_update_connected_devices()) { const int maxDeviceCount = getMaxDevices(); ServerDeviceViewPtr *temp_device_list = new ServerDeviceViewPtr[maxDeviceCount]; bool bSendControllerUpdatedNotification = false; // Step 1 // See if any devices shuffled order OR if any new controllers were attached. // Migrate open devices to a new temp list in the order // that they appear in the device enumerator. { DeviceEnumerator *enumerator = allocate_device_enumerator(); while (enumerator->is_valid()) { // Find device index for the device with the matching device path int device_id = find_open_device_device_id(enumerator); // Existing device case (Most common) if (device_id != -1) { // Fetch the device from it's existing device slot ServerDeviceViewPtr existingDevice = getDeviceViewPtr(device_id); // Move it to the same slot in the temp list temp_device_list[device_id] = existingDevice; // Remove it from the previous list m_deviceViews[device_id] = ServerDeviceViewPtr(); } // New controller connected case else { int device_id = find_first_closed_device_device_id(); if (device_id != -1) { // Fetch the controller from it's existing controller slot ServerDeviceViewPtr existingDevice = getDeviceViewPtr(device_id); // Move it to the available slot existingDevice->setDeviceID(static_cast<int>(device_id)); temp_device_list[device_id] = existingDevice; // Remove it from the previous list m_deviceViews[device_id] = ServerDeviceViewPtr(); // Attempt to open the device if (existingDevice->open(enumerator)) { const char *device_type_name = CommonDeviceState::getDeviceTypeString(existingDevice->getDevice()->getDeviceType()); SERVER_LOG_INFO("DeviceTypeManager::update_connected_devices") << "Device device_id " << device_id << " (" << device_type_name << ") connected"; bSendControllerUpdatedNotification = true; } } else { SERVER_LOG_ERROR("DeviceTypeManager::update_connected_devices") << "Can't connect any more new devices. Too many open device."; break; } } enumerator->next(); } free_device_enumerator(enumerator); } // Step 2 // Close any remaining open controllers not listed in the device enumerator. // Copy over any closed controllers to the temp. for (int existing_device_id = 0; existing_device_id < maxDeviceCount; ++existing_device_id) { ServerDeviceViewPtr existingDevice = getDeviceViewPtr(existing_device_id); if (existingDevice) { // Any "open" controllers remaining in the old list need to be closed // since they no longer appear in the connected device list. // This probably shouldn't happen very often (at all?) as polling should catch // disconnected controllers first. if (existingDevice->getIsOpen()) { const char *device_type_name = CommonDeviceState::getDeviceTypeString(existingDevice->getDevice()->getDeviceType()); SERVER_LOG_WARNING("DeviceTypeManager::update_connected_devices") << "Closing device " << existing_device_id << " (" << device_type_name << ") since it's no longer in the device list."; existingDevice->close(); bSendControllerUpdatedNotification = true; } // Move it to the temp slot temp_device_list[existing_device_id] = existingDevice; // Remove it from the previous list m_deviceViews[existing_device_id] = ServerDeviceViewPtr(); } } // Step 3 // Copy the temp controller list back over top the original list for (int device_id = 0; device_id < maxDeviceCount; ++device_id) { m_deviceViews[device_id] = temp_device_list[device_id]; } if (bSendControllerUpdatedNotification) { send_device_list_changed_notification(); } delete[] temp_device_list; success = true; } return success; }