Commit e6d9d343 authored by Thiago Santini's avatar Thiago Santini

Tries to load default camera if none was available in the config

parent f5cb85c6
...@@ -23,7 +23,7 @@ Camera::Camera(QString id, QObject *parent) ...@@ -23,7 +23,7 @@ Camera::Camera(QString id, QObject *parent)
connect(ui, SIGNAL(setCamera(QCameraInfo)), this, SLOT(setCamera(QCameraInfo)) ); connect(ui, SIGNAL(setCamera(QCameraInfo)), this, SLOT(setCamera(QCameraInfo)) );
connect(ui, SIGNAL(setViewfinderSettings(QCameraViewfinderSettings)), this, SLOT(setViewfinderSettings(QCameraViewfinderSettings)) ); connect(ui, SIGNAL(setViewfinderSettings(QCameraViewfinderSettings)), this, SLOT(setViewfinderSettings(QCameraViewfinderSettings)) );
connect(ui, SIGNAL(setColorCode(int)), this, SLOT(setColorCode(int)) ); connect(ui, SIGNAL(setColorCode(int)), this, SLOT(setColorCode(int)) );
settings = new QSettings(gCfgDir + "/" + id + " Camera", QSettings::IniFormat); settings = new QSettings(gCfgDir + "/" + id + " Camera", QSettings::IniFormat);
} }
Camera::~Camera() Camera::~Camera()
...@@ -257,7 +257,10 @@ void Camera::loadCfg() ...@@ -257,7 +257,10 @@ void Camera::loadCfg()
set(settings, "colorCode", colorCode); set(settings, "colorCode", colorCode);
setCamera(info, viewFinderSetting); setCamera(info, viewFinderSetting);
if ( info.isNull() ) // failed to load something, search for default cameras
searchDefaultCamera();
} }
void Camera::timedout() void Camera::timedout()
...@@ -285,3 +288,34 @@ void Camera::retry() ...@@ -285,3 +288,34 @@ void Camera::retry()
QTimer::singleShot(1000, this, SLOT(retry())); QTimer::singleShot(1000, this, SLOT(retry()));
} }
} }
void Camera::searchDefaultCamera()
{
/* TODO:
* 1) consider searching for the cameras periodically -- e.g., if the
* plugs the eye tracker *after* we are running, nothing will happen.
*
* 2) extend this so the user can add his own default cameras
*/
QRegularExpression re;
if (id.contains("eye", Qt::CaseInsensitive) ) {
if (id.contains("right", Qt::CaseInsensitive) )
re.setPattern("Pupil Cam. ID0");
if (id.contains("left", Qt::CaseInsensitive) )
re.setPattern("Pupil Cam. ID1");
}
if (id.contains("field", Qt::CaseInsensitive) )
re.setPattern("Pupil Cam. ID2");
QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
for (int i=0; i<cameras.size(); i++) {
if (re.match(cameras[i].deviceName()).hasMatch()) {
setCamera(cameras[i]);
if (!currentCameraInfo.isNull())
return;
}
}
}
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <QComboBox> #include <QComboBox>
#include <QLabel> #include <QLabel>
#include <QGridLayout> #include <QGridLayout>
#include <QRegularExpression>
#include "opencv/cv.h" #include "opencv/cv.h"
...@@ -170,10 +171,11 @@ private: ...@@ -170,10 +171,11 @@ private:
int retriesLeft; int retriesLeft;
int maxRetries; int maxRetries;
static QMutex setCameraMutex; static QMutex setCameraMutex;
void searchDefaultCamera();
private slots: private slots:
void reset(); void reset();
}; };
#endif // CAMERA_H #endif // CAMERA_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment