Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • sugu/vimba
1 result
Select Git revision
Show changes
Commits on Source (1)
#include "console.h" #include "console.h"
#include "qcoreapplication.h" #include "qcoreapplication.h"
#include "qnamespace.h"
#include "../utils.h"
#include <QDebug> #include <QDebug>
#include <QCoreApplication> #include <QCoreApplication>
...@@ -20,18 +23,30 @@ void Console::listenKeys() ...@@ -20,18 +23,30 @@ void Console::listenKeys()
} }
} }
void Console::updateCam(const QStringList& camInfo ) void Console::print(const QString& str )
{
qDebug() << str;
}
void Console::printList(QStringList& list )
{ {
qDebug() << camInfo;
for ( auto& str : list )
{
str.replace(DELIM," ");
qDebug() << str << " ";
}
} }
Controller::Controller() Controller::Controller()
{ {
Console *console = new Console; Console* console = new Console;
console->moveToThread(&thread); console->moveToThread(&thread);
connect(&thread, &QThread::finished, console, &QObject::deleteLater); connect(&thread, &QThread::finished, console, &QObject::deleteLater);
connect(this, &Controller::operate, console, &Console::listenKeys); connect(this, &Controller::operate, console, &Console::listenKeys);
connect(console, &Console::keyPressed, this, &Controller::keyPress); connect(console, &Console::keyPressed, this, &Controller::keyPress);
connect(this, &Controller::print, console, &Console::print, Qt::DirectConnection); //just delegate to console
connect(this, &Controller::printList, console, &Console::printList, Qt::DirectConnection); //just delegate to console
thread.start(); thread.start();
} }
...@@ -44,14 +59,33 @@ Controller::~Controller() ...@@ -44,14 +59,33 @@ Controller::~Controller()
void Controller::keyPress(const QChar& key) void Controller::keyPress(const QChar& key)
{ {
qDebug() << __FUNCTION__ << "u pressed " << key;
switch (key.unicode()) qDebug() << __FUNCTION__ << ": " << key;
if ( key.isDigit() )
{ {
case 'l': emit selectCam(key.digitValue());
emit listCams();
break;
case 'q':
qApp->quit();
break;
} }
else
{
switch (key.unicode())
{
case 'h':
emit printHelp();
break;
case 'o':
emit openCam();
break;
case 'l':
emit listCams();
break;
case 'v':
emit printVersion();
break;
case 'q':
qApp->quit();
break;
}
}
} }
...@@ -11,8 +11,10 @@ class Console : public QObject ...@@ -11,8 +11,10 @@ class Console : public QObject
Q_OBJECT Q_OBJECT
public slots: public slots:
void updateCam(const QStringList &);
void listenKeys(); void listenKeys();
void print(const QString&);
void printList(QStringList&);
// ...
signals: signals:
void keyPressed(const QChar &key); void keyPressed(const QChar &key);
...@@ -33,8 +35,21 @@ class Controller : public QObject ...@@ -33,8 +35,21 @@ class Controller : public QObject
signals: signals:
void operate(); void operate();
void print(const QString&);
void printList(QStringList&);
void listCams(); void listCams();
void printVersion(); void printVersion();
void openCam();
void printHelp();
void selectCam(int);
// void openCam();
// void calibrateCam();
// void startRecording();
// void stopRecording();
// void loadSettings();
// void storeSettings();
// ... more signals here // ... more signals here
}; };
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include <VmbCPP/VmbCPP.h> #include <VmbCPP/VmbCPP.h>
// #include "qglobal.h"
#include <QDebug> #include <QDebug>
using namespace VmbCPP; using namespace VmbCPP;
...@@ -15,20 +14,18 @@ Core::Core() : ...@@ -15,20 +14,18 @@ Core::Core() :
apiStarted( false ), apiStarted( false ),
sys( VmbSystem::GetInstance() ), // Create and get Vimba singleton sys( VmbSystem::GetInstance() ), // Create and get Vimba singleton
cameras( CameraPtrVector() ), // Holds camera handles cameras( CameraPtrVector() ), // Holds camera handles
camIdx(0) camIdx(-1),
curCam(NULL)
{ {
if ( VmbErrorSuccess == sys.Startup() ) if ( VmbErrorSuccess != sys.Startup() )
{
apiStarted = true;
qDebug() << "init API :)";
}
else
{ {
qDebug() << "Couldn't initialize API"; qDebug() << "Couldn't initialize API";
exit(1); //add err code
} }
apiStarted = true;
qDebug() << "init API :)";
initCams(); initCams();
} }
...@@ -37,6 +34,12 @@ void Core::initCams() ...@@ -37,6 +34,12 @@ void Core::initCams()
if ( VmbErrorSuccess == sys.GetCameras( cameras ) ) if ( VmbErrorSuccess == sys.GetCameras( cameras ) )
{ {
qDebug() << "found " << cameras.size() << " cameras"; qDebug() << "found " << cameras.size() << " cameras";
if (cameras.size())
{
camIdx = 0; //dflt to 1rst
curCam = cameras.at(camIdx);
}
} }
else else
{ {
...@@ -71,48 +74,60 @@ void Core::setCam(ulong idx) ...@@ -71,48 +74,60 @@ void Core::setCam(ulong idx)
void Core::listCams() void Core::listCams()
{ {
qDebug() << __FUNCTION__ << "():" << __LINE__;
if( !apiStarted ) if( !apiStarted )
return; return;
// id,name,model,serial,interfaceID // id,name,model,serial,interfaceID,state
std::for_each( cameras.begin(), cameras.end(), [this](const CameraPtr & camera) QStringList allCamInfo;
auto idx=0UL;
for ( auto camera : cameras )
{ {
std::string str; std::string str;
QStringList camInfo; QString curCamInfo;
if (idx == camIdx )
curCamInfo += "[*]" + DELIM;
else
curCamInfo += "[ ]" + DELIM;
VmbErrorType err = camera->GetID( str ); VmbErrorType err = camera->GetID( str );
if( VmbErrorSuccess != err ) if( VmbErrorSuccess != err )
str = errorCodeToMessage(err).toStdString(); str = errorCodeToMessage(err).toStdString();
camInfo << QString::fromStdString(str); curCamInfo += QString::fromStdString(str) + DELIM;
err = camera->GetName( str ); err = camera->GetName( str );
if( VmbErrorSuccess != err ) if( VmbErrorSuccess != err )
str = errorCodeToMessage(err).toStdString(); str = errorCodeToMessage(err).toStdString();
camInfo << QString::fromStdString(str); curCamInfo += QString::fromStdString(str) + DELIM;
err = camera->GetModel( str ); err = camera->GetModel( str );
if( VmbErrorSuccess != err ) if( VmbErrorSuccess != err )
str = errorCodeToMessage(err).toStdString(); str = errorCodeToMessage(err).toStdString();
camInfo << QString::fromStdString(str); curCamInfo += QString::fromStdString(str) + DELIM;
err = camera->GetSerialNumber( str ); err = camera->GetSerialNumber( str );
if( VmbErrorSuccess != err ) if( VmbErrorSuccess != err )
str = errorCodeToMessage(err).toStdString(); str = errorCodeToMessage(err).toStdString();
camInfo << QString::fromStdString(str); curCamInfo += QString::fromStdString(str) + DELIM;
err = camera->GetInterfaceID( str ); err = camera->GetInterfaceID( str );
if( VmbErrorSuccess != err ) if( VmbErrorSuccess != err )
str = errorCodeToMessage(err).toStdString(); str = errorCodeToMessage(err).toStdString();
camInfo << QString::fromStdString(str); curCamInfo += QString::fromStdString(str) + DELIM;
curCamInfo += "closed"; //initially cams are closed, right? XXX how to find out?
camInfo << "closed"; //initially cams are closed, right?
qDebug() << camInfo; allCamInfo << curCamInfo;
emit camsDetected(camInfo); idx++;
} ); }
// qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << allCamInfo;
emit camsListed(allCamInfo);
} }
void Core::printVersion()
{
auto version = getVersionString();
emit versionPrinted(version);
}
#pragma once #pragma once
#include "VmbCPP/SharedPointerDefines.h"
#include "qglobal.h" #include "qglobal.h"
#include <QObject> #include <QObject>
#include <VmbCPP/Interface.h> #include <VmbCPP/Interface.h>
...@@ -19,9 +20,12 @@ class Core : public QObject ...@@ -19,9 +20,12 @@ class Core : public QObject
public slots: public slots:
void listCams(); void listCams();
void printVersion();
signals: signals:
void camsDetected(const QStringList &); void camsListed(QStringList &);
void versionPrinted(const QString &);
// ... more signals here
private: private:
void initCams(); void initCams();
...@@ -33,4 +37,5 @@ class Core : public QObject ...@@ -33,4 +37,5 @@ class Core : public QObject
VmbCPP::VmbSystem& sys; VmbCPP::VmbSystem& sys;
VmbCPP::CameraPtrVector cameras; VmbCPP::CameraPtrVector cameras;
ulong camIdx; ulong camIdx;
CameraPtr curCam;
}; };
...@@ -48,16 +48,19 @@ bool maybeCreateDir(QDir out_dir) ...@@ -48,16 +48,19 @@ bool maybeCreateDir(QDir out_dir)
QCoreApplication::setApplicationName("recorder"); QCoreApplication::setApplicationName("recorder");
Controller controller; Controller controller;
QTimer::singleShot(0, &controller, SIGNAL(operate()));
Core core; Core core;
QObject::connect(&controller, &Controller::listCams, &core, &Core::listCams);
QObject::connect(&core, &Core::camsDetected, &console, &Console::updateCam); //ui (controller) -> vmb (core)
QObject::connect(&controller, &Controller::listCams, &core, &Core::listCams);
QObject::connect(&controller, &Controller::printVersion, &core, &Core::printVersion);
//vmb (core) -> ui (controller)
QObject::connect(&core, &Core::camsListed, &controller, &Controller::printList);
QObject::connect(&core, &Core::versionPrinted, &controller, &Controller::print);
// for testing: QTimer::singleShot(0, &controller, SIGNAL(operate()));
QTimer::singleShot(0, &core, SLOT(listCams())); QTimer::singleShot(10, &core, SLOT(printVersion())); // for testing
QTimer::singleShot(15, &core, SLOT(listCams())); // for testing
......
...@@ -28,7 +28,6 @@ const QString getVersionString() ...@@ -28,7 +28,6 @@ const QString getVersionString()
return s; return s;
} }
const QString errorCodeToMessage( VmbError_t err ) const QString errorCodeToMessage( VmbError_t err )
{ {
QString msg = "error: "; QString msg = "error: ";
......
...@@ -8,4 +8,6 @@ const QString getVersionString(); ...@@ -8,4 +8,6 @@ const QString getVersionString();
const QString errorCodeToMessage( VmbError_t ); const QString errorCodeToMessage( VmbError_t );
QString randomString(); QString randomString();
const QChar DELIM='|';
#endif #endif
This diff is collapsed.