int ConfigurationFile::AutoBind(const string& directory, const string& file) { ConfigurationFile refConfigFile; int ret = refConfigFile.ReadConfigFile(directory, file); if(ret >= 0) { for(int i=0; i<MAX_CONTROLLERS; ++i) { Controller* refController = refConfigFile.GetController(i); Controller* modController = GetController(i); for(int j=0; j<MAX_PROFILES; ++j) { Profile* refConfig = refController->GetProfile(j); Profile* modConfig = modController->GetProfile(j); modConfig->SetTrigger(*refConfig->GetTrigger()); modConfig->SetIntensityList(*refConfig->GetIntensityList()); AutoBindMappers<ControlMapper>(refConfig->GetButtonMapperList(), modConfig->GetButtonMapperList()); AutoBindMappers<ControlMapper>(refConfig->GetAxisMapperList(), modConfig->GetAxisMapperList()); } } } return ret; }
/*! *============================================================================= * * \brief Grabber::setProfile * \param name * \return * *============================================================================= */ bool Grabber::setProfile(Voxel::String name) { bool rc = false; const Map<int, Voxel::String> &profiles = _depthCamera->getCameraProfileNames(); for (auto &p: profiles) { std::cout << "Checking (" << p.second << ") against name (" << name << ")" << std::endl; if (p.second == name) { int profile_id = p.first; ConfigurationFile *c = _depthCamera->configFile.getCameraProfile(p.first); if (c && c->getLocation() == ConfigurationFile::IN_CAMERA) { if (_depthCamera->setCameraProfile(profile_id)) { rc = true; break; } } } } return rc; }
void ConfigurationFile::GetLabels(const string& directory, const string& file, list<string>& button_labels, list<string>& axis_labels) { ConfigurationFile configFile; configFile.SetCheckDevices(false); if(configFile.ReadConfigFile(directory, file) >= 0) { configFile.GetLabels(button_labels, axis_labels); } }
int ConfigurationFile::ConvertSensitivity(const string& directory, const string& file) { ConfigurationFile refConfigFile; int ret = refConfigFile.ReadConfigFile(directory, file); if(ret >= 0) { for(int i=0; i<MAX_CONTROLLERS; ++i) { Controller* refController = refConfigFile.GetController(i); Controller* modController = GetController(i); int refdpi = refController->GetMouseDPI(); int dpi = modController->GetMouseDPI(); if(refdpi && dpi && refdpi != dpi) { for(int k=0; k<MAX_PROFILES; ++k) { Profile* modConfig = modController->GetProfile(k); list<ControlMapper>* modAxisMappers = modConfig->GetAxisMapperList(); for(list<ControlMapper>::iterator itModControlMappers = modAxisMappers->begin(); itModControlMappers!=modAxisMappers->end(); ++itModControlMappers) { if(itModControlMappers->GetDevice()->GetType() == "mouse" && itModControlMappers->GetEvent()->GetType() == "axis") { double val = atof(itModControlMappers->GetEvent()->GetMultiplier().c_str()); double exp = atof(itModControlMappers->GetEvent()->GetExponent().c_str()); val = val * pow((double)dpi / refdpi, exp); ostringstream ios; ios << setprecision(2) << val; itModControlMappers->GetEvent()->SetMultiplier(ios.str()); } } } modController->SetMouseDPI(refdpi); } } } return ret; }
bool TOFApp::setProfile(Voxel::String name) { bool rc = false; const Map<int, Voxel::String> &profiles = _depthCamera->getCameraProfileNames(); for (auto &p: profiles) { if (p.second == name) { int profile_id = p.first; ConfigurationFile *c = _depthCamera->configFile.getCameraProfile(p.first); if (c && c->getLocation() == ConfigurationFile::IN_CAMERA) { if (_depthCamera->setCameraProfile(profile_id)) { rc = true; break; } } } } return rc; }
bool TOFApp::connect() { const vector<DevicePtr> &devices = _sys.scan(); if (devices.size() > 0) { _depthCamera = _sys.connect(devices[0]); if (!_depthCamera) return false; if (!_depthCamera->isInitialized()) return false; } else return false; int profile_id; const Map<int, Voxel::String> &profiles = _depthCamera->getCameraProfileNames(); for(auto &p: profiles) { std::cout << p.first << ", " << p.second; if (p.second == "Calibrated Normal") profile_id = p.first; ConfigurationFile *c = _depthCamera->configFile.getCameraProfile(p.first); if(c && c->getLocation() == ConfigurationFile::IN_CAMERA) std::cout << " (HW)"; std::cout << std::endl; } cout << "Profile ID = " << profile_id << endl; if (_depthCamera->setCameraProfile(profile_id)) cout << "Profile setting succeeded." << endl; _depthCamera->registerCallback(DepthCamera::FRAME_DEPTH_FRAME, frameCallback); _depthCamera->setFrameSize(_dimen); _depthCamera->set("illum_power_percentage", _illum_power); _depthCamera->set("intg_duty_cycle", _intg); _depthCamera->start(); return true; }
bool PacketHeader::loadHeader(char* fileName) throw(PacketException*) { ConfigurationFile header; char **argv = new char* [1]; argv[0] = (char*)fileName; if(header.open(argv)) { delete[] argv; char* line = header.getLine(); /// retrieve name of packet header name = line; line = header.getLine(); numberOfFieldWithPacketDimension = atoi(line); /// delete[] line; line = header.getLine(); if(strcmp(line, "[Field]") == 0) dimensionOfPacketLength = 16; else dimensionOfPacketLength = atoi(line); if(!(dimensionOfPacketLength == 16 || dimensionOfPacketLength == 32)) throw new PacketExceptionIO("Dimension of packet length, 16 or 32 bit");; header.setpos(0); /// find the start position of the fields line = header.getLine("[Field]"); /// delete[] line; if(loadFields(header)) { header.close(); return true; } else throw new PacketExceptionIO("Can't create the header."); } else { delete[] argv; throw new PacketExceptionIO("Can't open the header file configuration."); } }
bool DepthCamera::setCameraProfile(const int id, bool softApply) { if(!configFile.setCurrentCameraProfile(id)) { logger(LOG_ERROR) << "DepthCamera: Could not set the camera profile to '" << id << "'" << std::endl; return false; } if(!_saveCurrentProfileID(id)) logger(LOG_WARNING) << "DepthCamera: Could not save the camera profile ID '" << id << "'" << std::endl; /* // Uncomment this perform soft-reset every time a profile is selected. if(!reset()) { logger(LOG_ERROR) << "DepthCamera: Failed to reset camera, to set new camera profile" << std::endl; return false; } */ if(!refreshParams()) return false; if(!softApply) { ConfigurationFile *config; String cameraProfileName; if(!configFile.getCameraProfileName(id, cameraProfileName)) { logger(LOG_ERROR) << "DepthCamera: Failed to get new camera profile name" << std::endl; return false; } if(!(config = configFile.getCameraProfile(id))) { logger(LOG_ERROR) << "DepthCamera: Failed to get new camera profile information" << std::endl; return false; } const ConfigSet *params; if(config->getConfigSet("params", params) && !_applyConfigParams(params)) { logger(LOG_ERROR) << "DepthCamera: Could not set parameters to initialize profile '" << cameraProfileName << "'" << std::endl; return false; } if(config->getConfigSet("defining_params", params) && !_applyConfigParams(params)) { logger(LOG_ERROR) << "DepthCamera: Could not set parameters to initialize profile '" << cameraProfileName << "'" << std::endl; return false; } } if(!_onReset()) return false; return true; }
* along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA */ #include "base/config_file.h" #include "wb_helpers.h" TEST_MODULE(config_file_test, "Base library config file handling"); using namespace base; TEST_FUNCTION(10) { // No config file. Creates a default section. ConfigurationFile file("", AutoCreateNothing); ensure_equals("Only 1 (default) section exists", file.section_count(), 1); ensure("Default section exists", file.has_section("")); ensure_equals("No key exists", file.key_count(), 0); } TEST_FUNCTION(20) { // Empty config file. No keys, no fun. ConfigurationFile file("data/base/my-1.ini", AutoCreateNothing); ensure_equals("Only 1 (default) section exists", file.section_count(), 1); ensure("Default section exists", file.has_section("")); ensure_equals("No key exists", file.key_count(), 0); } TEST_FUNCTION(30)