Skip to content
Snippets Groups Projects
Commit 00b0b837 authored by am0ebe's avatar am0ebe
Browse files

fix load/save settings. check edge cases

parent c2ae16f9
No related branches found
No related tags found
No related merge requests found
#include "cam.h"
#include "VmbC/VmbCommonTypes.h"
#include "VmbC/VmbCTypeDefinitions.h"
#include "iprinter.h"
#include "utils.h"
#include "frameobserver.h"
......@@ -8,6 +9,7 @@
#include <chrono>
#include <memory> //shared_ptr
#include <string>
#include <unistd.h>
#include <QTimer>
......@@ -17,7 +19,7 @@ using State = Cam::State;
using namespace VmbCPP;
using namespace std::chrono;
using utils::DELIM;
using utils::settingsFile;
Cam::Cam(QString name, QString ip) : IPrinter(),
_cam(nullptr),
......@@ -300,34 +302,37 @@ void Cam::onChanged(UpdateTriggerType type)
error("onChanged: unknown trigger type");
}
}
#include <VmbC/VmbCommonTypes.h>
//write out settings.xml for current open cam
void Cam::saveSettings()
{
if(_state != opened)
return error("can only save settings on opened cam. (its " + stateToString(_state) + ")");
// VmbFilePathChar_t* = wchar_t* > std::wstring
// auto file = L"settings_" + name().toStdWString() + L".xml";
std::wstring file = L"settings_" + name().toStdWString() + L".xml";
VmbFeaturePersistSettings_t settingsStruct;
settingsStruct.loggingLevel = VmbLogLevelWarn; //err/warn/dbg
settingsStruct.maxIterations = 5;
settingsStruct.persistType = VmbFeaturePersistNoLUT; //?
settingsStruct.maxIterations = 8;
settingsStruct.persistType = VmbFeaturePersistStreamable; //dont store IP address!
settingsStruct.modulePersistFlags = VmbModulePersistFlagsType::VmbModulePersistFlagsNone; //
// if (f(_cam->SaveSettings( (const VmbFilePathChar_t*)file.c_str() , &settingsStruct ) ))
if (f(_cam->SaveSettings( (const VmbFilePathChar_t*)file.c_str() ) ))
error( "Could not save camera settings to '" + QString::fromStdWString(file) + "'" );
QString file="settings_"+name()+".xml";
if (f(_cam->SaveSettings( file.toStdString().c_str(), &settingsStruct )))
error( "Could not save camera settings to '" + file + "'" );
else
IPrinter::info("Saved settings to " + file);
}
//load settings.xml for current open cam
void Cam::loadSettings()
{
using utils::settingsFile;
if(_state != opened)
return error("can only save settings on opened cam. (its " + stateToString(_state) + ")");
if(f(_cam->LoadSettings( (const VmbFilePathChar_t *) settingsFile().toStdWString().c_str())))
if(f(_cam->LoadSettings( settingsFile().toStdString().c_str())))
error( "Could not load camera settings from '" + settingsFile() + "'" );
else
IPrinter::info("Loaded settings from " + settingsFile());
}
......@@ -30,7 +30,9 @@ void Console::listenKeys()
while( utils::running )
{
std::getline(std::cin, input); //blox
if (input.find_first_not_of("0123456789") == std::string::npos)
if( input.empty() )
continue;
else if ( input.find_first_not_of("0123456789") == std::string::npos)
{
emit numberEntered(std::stoi(input)); // Number
}
......@@ -45,7 +47,7 @@ void Console::listenKeys()
emit lineEntered(QString::fromStdString(input)); // Line
}
}
qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "";
// qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "";
}
void Console::error(const int& errCode )
......@@ -101,7 +103,7 @@ void Console::printHelp()
<< "s: stop recording"
<< "l: list available cameras"
<< "k: deteKt cameras"
<< "y: load cam settings"
<< "y: load cam settings ("+ utils::settingsFile()+")"
<< "u: save cam settings"
<< "v: print versions"
<< "q: quit"
......@@ -131,7 +133,7 @@ getDur(false)
Controller::~Controller()
{
qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "";
// qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "";
thread.quit();
thread.wait(); //wait for thread to finish
qDebug().noquote() << __FUNCTION__ << "():" << __LINE__ << ": ";
......
#include "iprinter.h"
#include <QDebug>
#ifdef CONSOLE
#include "cmd/console.h"
#endif
......
......@@ -176,11 +176,10 @@ QString settingsFile(QString filename)
static QString _settingsFile;
if( _settingsFile.isEmpty() )
{
_settingsFile = filename;
if(filename.isEmpty())
QCoreApplication::applicationDirPath() + "/settings.xml" ; //default
_settingsFile = QCoreApplication::applicationDirPath() + "/settings.xml" ; //default
else
_settingsFile = filename;
}
return _settingsFile;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment