Tidy up handling of eye tracker streaming

This commit is contained in:
David Rowe 2015-08-10 12:52:47 -07:00
parent 051a398fa2
commit 4f3c4a5312
2 changed files with 10 additions and 5 deletions

View file

@ -29,9 +29,11 @@ static void CALLBACK eyeTrackerCallback(smi_CallbackDataStruct* data) {
EyeTracker::~EyeTracker() { EyeTracker::~EyeTracker() {
#ifdef HAVE_IVIEWHMD #ifdef HAVE_IVIEWHMD
int result = smi_quit(); if (_isStreaming) {
if (result != SMI_RET_SUCCESS) { int result = smi_quit();
qCWarning(interfaceapp) << "Eye Tracker: Error terminating tracking:" << smiReturnValueToString(result); if (result != SMI_RET_SUCCESS) {
qCWarning(interfaceapp) << "Eye Tracker: Error terminating tracking:" << smiReturnValueToString(result);
}
} }
#endif #endif
} }
@ -131,16 +133,18 @@ void EyeTracker::setEnabled(bool enabled, bool simulate) {
qCDebug(interfaceapp) << "Eye Tracker: Set enabled =" << enabled << ", simulate =" << simulate; qCDebug(interfaceapp) << "Eye Tracker: Set enabled =" << enabled << ", simulate =" << simulate;
bool success = true; bool success = true;
int result = 0; int result = 0;
if (enabled) { if (enabled && !_isStreaming) {
// There is no smi_stopStreaming() method so keep streaming once started in case tracking is re-enabled after stopping. // There is no smi_stopStreaming() method so keep streaming once started in case tracking is re-enabled after stopping.
result = smi_startStreaming(simulate); result = smi_startStreaming(simulate);
if (result != SMI_RET_SUCCESS) { if (result != SMI_RET_SUCCESS) {
qCWarning(interfaceapp) << "Eye Tracker: Error starting streaming:" << smiReturnValueToString(result); qCWarning(interfaceapp) << "Eye Tracker: Error starting streaming:" << smiReturnValueToString(result);
success = false; success = false;
} }
_isStreaming = success;
} }
_isEnabled = enabled && success; _isEnabled = enabled && _isStreaming;
_isSimulating = _isEnabled && simulate; _isSimulating = _isEnabled && simulate;
if (!success && result != SMI_ERROR_HMD_NOT_SUPPORTED) { if (!success && result != SMI_ERROR_HMD_NOT_SUPPORTED) {

View file

@ -50,6 +50,7 @@ private:
QString smiReturnValueToString(int value); QString smiReturnValueToString(int value);
bool _isInitialized = false; bool _isInitialized = false;
bool _isStreaming = false;
bool _isEnabled = false; bool _isEnabled = false;
bool _isSimulating = false; bool _isSimulating = false;