/* * Start checking received data from SIGService. */ void AvatarController::checkRecvSIGServiceData() { CheckRecvSIGServiceData checkRecvSIGServiceData; // Execute in another thread. boost::thread thCheckRecvData(boost::bind(&CheckRecvSIGServiceData::run, &checkRecvSIGServiceData, this->m_srv)); }
/** * @brief main routine */ void OculusRiftDK1Device::run() { init(); this->readIniFile(); //this->setSigServiceName(); sigverse::SIGService sigService(this->serviceName); this->initializeSigService(sigService); // check receive SIGService data by another thread CheckRecvSIGServiceData checkRecvSIGServiceData; boost::thread thCheckRecvData(&CheckRecvSIGServiceData::run, &checkRecvSIGServiceData, &sigService); bool sendSuccessPrev = false; while (1) { if (_kbhit()){ int key = _getch(); if (key == 'r'){ pFusionResult->Reset(); std::cout << "Reset Orientation." << std::endl; } } float r_yaw, r_pitch, r_roll; OVR::Quatf q = pFusionResult->GetOrientation(); OVR::Matrix4f bodyFrameMatrix(q); q.GetEulerAngles<OVR::Axis_Y, OVR::Axis_X, OVR::Axis_Z>(&r_yaw, &r_pitch, &r_roll); // std::cout << "yaw, pitch, roll = " << r_yaw << "," << r_pitch << "," << r_roll << std::endl; OculusRiftDK1SensorData sensorData; sensorData.setEulerAngle(r_yaw, r_pitch, r_roll); if (this->sendMessageFlag) { const std::string sensorDataMessage = sensorData.encodeSensorData(); const std::string messageHeader = this->generateMessageHeader(); const std::string message = messageHeader + sensorDataMessage; this->sendMessage(sigService, message); OculusRiftDK1SensorData tmp; std::map<std::string, std::vector<std::string> > sensorDataMap = tmp.decodeSensorData(message); tmp.setSensorData(sensorDataMap); } Sleep(10); } sigService.disconnect(); std::cout << "end program" << std::endl; Sleep(2000); }
///@brief Execute a device. int MyoDevice::run() { try { // Read the initialize file. this->readIniFile(); // Prepare to use SIGService. this->sigService.setName(this->serviceName); this->initializeSigService(sigService); // check receive SIGService data by another thread CheckRecvSIGServiceData checkRecvSIGServiceData; boost::thread thCheckRecvData(&CheckRecvSIGServiceData::run, &checkRecvSIGServiceData, &this->sigService); // First, we create a Hub with our application identifier. Be sure not to use the com.example namespace when // publishing your application. The Hub provides access to one or more Myos. myo::Hub hub("org.sigverse.myoplugin"); std::cout << "Attempting to find a Myo..." << std::endl; // Next, we attempt to find a Myo to use. If a Myo is already paired in Myo Connect, this will return that Myo // immediately. // waitForMyo() takes a timeout value in milliseconds. In this case we will try to find a Myo for 10 seconds, and // if that fails, the function will return a null pointer. myo::Myo* myo = hub.waitForMyo(10000); // If waitForMyo() returned a null pointer, we failed to find a Myo, so exit with an error message. if (!myo) { throw std::runtime_error("Unable to find a Myo!"); } // We've found a Myo. std::cout << "Connected to a Myo armband!" << std::endl << std::endl; // Next we enable EMG streaming on the found Myo. myo->setStreamEmg(myo::Myo::streamEmgEnabled); // Next we construct an instance of our DeviceListener, so that we can register it with the Hub. DataCollector collector; // Hub::addListener() takes the address of any object whose class inherits from DeviceListener, and will cause // Hub::run() to send events to all registered device listeners. hub.addListener(&collector); // Finally we enter our main loop. while (true) { // In each iteration of our main loop, we run the Myo event loop for a set number of milliseconds. // In this case, we wish to update our display 20 times a second, so we run for 1000/20 milliseconds. hub.run(1000/20); // After processing events, we call the print() member function we defined above to print out the values we've // obtained from any events that have occurred. MyoSensorData sensorData = collector.getSensorData(); // Send message to SigServer. std::string messageHeader = this->generateMessageHeader(); std::string sensorDataMessage = sensorData.encodeSensorData(); std::string message = messageHeader + sensorDataMessage; this->sendMessage(this->sigService, message); // std::cout << message << std::endl; } sigService.disconnect(); } catch (std::exception &ex) { std::cout << "run ERR :" << ex.what() << std::endl; throw ex; } return 0; }