Commit 4c2e9478 authored by Thiago Santini's avatar Thiago Santini

Adds audible feedback for calibration

parent 5df14ff4
......@@ -12,6 +12,8 @@ GazeEstimationWidget::GazeEstimationWidget(QWidget *parent) :
QMainWindow(parent),
isCollecting(false),
isSampling(false),
lastStatus(false),
calibrationRequested(false),
ui(new Ui::GazeEstimationWidget)
{
ui->setupUi(this);
......@@ -137,6 +139,12 @@ GazeEstimationWidget::GazeEstimationWidget(QWidget *parent) :
gazeEstimation->settings = settings;
QMetaObject::invokeMethod(gazeEstimation, "updateConfig");
// Load sound effects
loadSoundEffect(startSound, "start.wav");
loadSoundEffect(successSound, "success.wav");
loadSoundEffect(failureSound, "failure.wav");
loadSoundEffect(collectedSound, "collected.wav");
}
GazeEstimationWidget::~GazeEstimationWidget()
......@@ -213,6 +221,7 @@ void GazeEstimationWidget::finishSampling()
}
samples.clear();
collectedSound.play();
}
void GazeEstimationWidget::newSample(DataTuple dataTuple)
{
......@@ -255,7 +264,7 @@ void GazeEstimationWidget::on_startFinishButton_toggled(bool checked)
emit setCalibrating(true);
connect(this, SIGNAL(newClick(Timestamp,QPoint,QSize)),
this, SLOT(startSampling(Timestamp,QPoint,QSize)) );
//startSound.play();
startSound.play();
isCollecting = true;
} else {
ui->startFinishButton->setText("Start");
......@@ -264,6 +273,7 @@ void GazeEstimationWidget::on_startFinishButton_toggled(bool checked)
disconnect(this, SIGNAL(newClick(Timestamp,QPoint,QSize)),
this, SLOT(startSampling(Timestamp,QPoint,QSize)) );
emit setCalibrating(false);
calibrationRequested = true;
emit calibrationRequest();
isCollecting = false;
}
......@@ -410,6 +420,14 @@ void GazeEstimationWidget::on_visualizationTimeSpinBox_valueChanged(int arg1)
void GazeEstimationWidget::updateStatus(bool status, QString msg)
{
// There are two different triggers for an status update:
// 1) We requested a calibration, in which case we always give the user feedback
// 2) The configuration changed, in which case we only give feedback if the status changed
if (calibrationRequested || status != lastStatus)
status ? successSound.play() : failureSound.play();
lastStatus = status;
calibrationRequested = false;
if (status) {
statusBarLabel->setText("Calibrated.");
statusBarLabel->setStyleSheet("QLabel { color : green }");
......@@ -417,5 +435,6 @@ void GazeEstimationWidget::updateStatus(bool status, QString msg)
statusBarLabel->setText(QString("Uncalibrated: %1").arg(msg));
statusBarLabel->setStyleSheet("QLabel { color : red }");
}
}
......@@ -7,6 +7,7 @@
#include <QFileDialog>
#include <QThread>
#include <QKeyEvent>
#include <QSoundEffect>
#include "Synchronizer.h"
#include "GazeEstimation.h"
......@@ -49,9 +50,13 @@ private:
cv::Point2f fieldRatio;
bool isCollecting;
bool isSampling;
bool lastStatus;
bool calibrationRequested;
QLabel *statusBarLabel;
QSoundEffect startSound, successSound, failureSound, collectedSound;
private slots:
void startSampling(Timestamp timestamp, QPoint calibrationPoint, QSize previewSize);
void newSample(DataTuple dataTuple);
......
......@@ -172,3 +172,20 @@ QString iniStr(QString str)
// CPU hoggers for testing
void delay(int thMs) { Timestamp cur = gTimer.elapsed(); volatile int a=0; while ( gTimer.elapsed() - cur < thMs ) a++; }
void loadSoundEffect(QSoundEffect &effect, QString fileName)
{
// TODO: clean this up; QSoundEffect doesn't work with resources currently so
// we search manually in case this is a release or a development environment.
// It assumes the build location for the development environment!
QStringList searchPaths;
searchPaths << "../EyeRecToo/effects" << "./effects";
for (int i=0; i<searchPaths.size(); i++) {
QString target = searchPaths[i] + "/" + fileName;
if (QFile(target).exists()) {
qDebug() << "Loaded" << target;
effect.setSource(QUrl::fromLocalFile(target));
break;
}
}
}
......@@ -18,6 +18,7 @@
#include <QCameraInfo>
#include <QWidget>
#include <QSettings>
#include <QSoundEffect>
#include <opencv/cv.h>
#include <opencv2/imgproc.hpp>
......@@ -93,4 +94,6 @@ template<typename T> void set(const QSettings *settings, const QString key, T &v
v = qvariant_cast<T>(variant);
}
void loadSoundEffect(QSoundEffect &effect, QString fileName);
#endif // UTILS_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