Initialize, start, and stop eye tracking with simulated data

This commit is contained in:
David Rowe 2015-07-28 11:02:56 -07:00
parent e0ca6eb5ed
commit 72a590e34c
3 changed files with 86 additions and 5 deletions

View file

@ -595,6 +595,12 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
loadScripts();
}
#ifdef HAVE_IVIEWHMD
// Do this before loading settings
auto eyeTracker = DependencyManager::get<EyeTracker>();
eyeTracker->init();
#endif
loadSettings();
int SAVE_SETTINGS_INTERVAL = 10 * MSECS_PER_SECOND; // Let's save every seconds for now
connect(&_settingsTimer, &QTimer::timeout, this, &Application::saveSettings);
@ -636,11 +642,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
connect(ddeTracker.data(), &FaceTracker::muteToggled, this, &Application::faceTrackerMuteToggled);
#endif
#ifdef HAVE_IVIEWHMD
auto eyeTracker = DependencyManager::get<EyeTracker>();
eyeTracker->init();
#endif
auto applicationUpdater = DependencyManager::get<AutoUpdater>();
connect(applicationUpdater.data(), &AutoUpdater::newVersionIsAvailable, dialogsManager.data(), &DialogsManager::showUpdateDialog);
applicationUpdater->checkForUpdate();
@ -703,6 +704,9 @@ void Application::cleanupBeforeQuit() {
#ifdef HAVE_DDE
DependencyManager::destroy<DdeFaceTracker>();
#endif
#ifdef HAVE_IVIEWHMD
DependencyManager::destroy<EyeTracker>();
#endif
}
void Application::emptyLocalCache() {

View file

@ -11,10 +11,75 @@
#include "EyeTracker.h"
#include "InterfaceLogging.h"
#ifdef HAVE_IVIEWHMD
static void CALLBACK eyeTrackerCallback(smi_CallbackDataStruct* data) {
auto eyeTracker = DependencyManager::get<EyeTracker>();
if (eyeTracker) { // Guard against a few callbacks that continue to be received after smi_quit().
eyeTracker->processData(data);
}
}
#endif
EyeTracker::~EyeTracker() {
#ifdef HAVE_IVIEWHMD
int result = smi_quit();
if (result != SMI_RET_SUCCESS) {
qCWarning(interfaceapp) << "Eye Tracker: Error terminating tracking:" << result;
}
#endif
}
void EyeTracker::processData(smi_CallbackDataStruct* data) {
if (!_isEnabled) {
return;
}
#ifdef HAVE_IVIEWHMD
if (data->type == SMI_SIMPLE_GAZE_SAMPLE) {
smi_SampleHMDStruct* sample = (smi_SampleHMDStruct*)data->result;
}
#endif
}
void EyeTracker::init() {
if (_isInitialized) {
qCWarning(interfaceapp) << "Eye Tracker: Already initialized";
return;
}
#ifdef HAVE_IVIEWHMD
int result = smi_setCallback(eyeTrackerCallback);
if (result != SMI_RET_SUCCESS) {
qCWarning(interfaceapp) << "Eye Tracker: Error setting callback:" << result;
} else {
_isInitialized = true;
}
#endif
}
void EyeTracker::setEnabled(bool enabled) {
if (!_isInitialized) {
qCWarning(interfaceapp) << "Eye Tracker: Not initialized before setting enabled";
return;
}
#ifdef HAVE_IVIEWHMD
qCDebug(interfaceapp) << "Eye Tracker: Set enabled =" << enabled;
if (enabled && !_isStreaming) {
// There is no smi_stopStreaming() method so start streaming a maximum of once per program run.
int result = smi_startStreaming(true);
if (result != SMI_RET_SUCCESS) {
qCWarning(interfaceapp) << "Eye Tracker: Error starting streaming:" << result;
} else {
_isStreaming = true;
}
}
_isEnabled = enabled && _isStreaming;
#endif
}
void EyeTracker::reset() {

View file

@ -15,15 +15,27 @@
#include <QObject>
#include <DependencyManager.h>
#include <iViewHMDAPI.h>
class EyeTracker : public QObject, public Dependency {
Q_OBJECT
SINGLETON_DEPENDENCY
public:
~EyeTracker();
void processData(smi_CallbackDataStruct* data);
public slots:
void init();
void setEnabled(bool enabled);
void reset();
private:
bool _isInitialized = false;
bool _isStreaming = false;
bool _isEnabled = false;
};
#endif // hifi_EyeTracker_h