修改:
记录上次设置的帧率和曝光时间,打开时,将上次的帧率和曝光时间设置为当前参数;
This commit is contained in:
@ -468,3 +468,172 @@ bool Configfile::updateConfigFile()
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ParameterConfigfile::ParameterConfigfile()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ParameterConfigfile::setConfigfilePath(string configfilePath)
|
||||
{
|
||||
m_configfilePath = configfilePath;
|
||||
}
|
||||
|
||||
bool ParameterConfigfile::isConfigfileExist()
|
||||
{
|
||||
QFileInfo info(QString::fromStdString(m_configfilePath));
|
||||
|
||||
return info.exists();
|
||||
}
|
||||
|
||||
bool ParameterConfigfile::parseConfigfile()
|
||||
{
|
||||
// Read the file. If there is an error, report it and exit.
|
||||
try
|
||||
{
|
||||
cfg.readFile(m_configfilePath);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(const FileIOException &fioex)
|
||||
{
|
||||
std::cerr << "I/O error while reading file." << std::endl;
|
||||
return false;
|
||||
}
|
||||
catch(const ParseException &pex)
|
||||
{
|
||||
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
|
||||
<< " - " << pex.getError() << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ParameterConfigfile::createConfigFile()
|
||||
{
|
||||
using namespace std;
|
||||
using namespace libconfig;
|
||||
|
||||
Config cfg;
|
||||
|
||||
Setting &root = cfg.getRoot();
|
||||
|
||||
// Add some settings to the configuration.
|
||||
// Setting &SN = root.add("SN", Setting::TypeString) = "0098";
|
||||
// Setting &spatialBin = root.add("spatialBin", Setting::TypeInt) = 2;
|
||||
// Setting &SpectralBin = root.add("spectralBin", Setting::TypeInt) = 2;
|
||||
|
||||
Setting &ximeaParam = root.add("ximeaParam", Setting::TypeGroup);
|
||||
ximeaParam.add("frameRate", Setting::TypeInt) = 100;
|
||||
ximeaParam.add("exposeTime", Setting::TypeFloat) = 10.0;
|
||||
|
||||
|
||||
// Write out the new configuration.
|
||||
try
|
||||
{
|
||||
QList<QString> fileInfo = getFileInfo(QString::fromStdString(m_configfilePath));
|
||||
bool ret = createDir(fileInfo[0]);
|
||||
|
||||
cfg.writeFile(m_configfilePath.c_str());
|
||||
cerr << "New configuration successfully written to: " << m_configfilePath.c_str() << endl;
|
||||
|
||||
}
|
||||
catch(const FileIOException &fioex)
|
||||
{
|
||||
cerr << "I/O error while writing configuration file: " << m_configfilePath.c_str() << endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ParameterConfigfile::getFrameRate(int &frameRate)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
try
|
||||
{
|
||||
const Setting &ximeaParam = root["ximeaParam"];
|
||||
frameRate = ximeaParam.lookup("frameRate");
|
||||
|
||||
std::cout << "----------------"<< frameRate<<std::endl;
|
||||
return true;
|
||||
}
|
||||
catch(const SettingNotFoundException &nfex)
|
||||
{
|
||||
cerr << "No 'frameRate' setting in configuration file." << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ParameterConfigfile::setFrameRate(int frameRate)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
try
|
||||
{
|
||||
Setting &frameRate2 = root["ximeaParam"]["frameRate"];
|
||||
frameRate2 = frameRate;
|
||||
|
||||
writeConfig2File();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(const SettingNotFoundException &nfex)
|
||||
{
|
||||
cerr << "No 'frameRate' setting in configuration file." << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ParameterConfigfile::getExposeTime(float &exposeTime)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
try
|
||||
{
|
||||
const Setting &ximeaParam = root["ximeaParam"];
|
||||
exposeTime = ximeaParam.lookup("exposeTime");
|
||||
|
||||
std::cout << "----------------"<< exposeTime<<std::endl;
|
||||
return true;
|
||||
}
|
||||
catch(const SettingNotFoundException &nfex)
|
||||
{
|
||||
cerr << "No 'exposeTime' setting in configuration file." << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ParameterConfigfile::setExposeTime(float exposeTime)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
try
|
||||
{
|
||||
Setting &frameRate2 = root["ximeaParam"]["exposeTime"];
|
||||
frameRate2 = exposeTime;
|
||||
|
||||
writeConfig2File();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(const SettingNotFoundException &nfex)
|
||||
{
|
||||
cerr << "No 'exposeTime' setting in configuration file." << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ParameterConfigfile::writeConfig2File()
|
||||
{
|
||||
try
|
||||
{
|
||||
QList<QString> fileInfo = getFileInfo(QString::fromStdString(m_configfilePath));
|
||||
bool ret = createDir(fileInfo[0]);
|
||||
|
||||
cfg.writeFile(m_configfilePath.c_str());
|
||||
cerr << "New configuration successfully written to: " << m_configfilePath.c_str() << endl;
|
||||
}
|
||||
catch(const FileIOException &fioex)
|
||||
{
|
||||
cerr << "I/O error while writing configuration file: " << m_configfilePath.c_str() << endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user