From 658434e02091e2674ca1b2278e48a5af10f703b2 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 10 Aug 2015 13:20:42 -0700 Subject: [PATCH] Automatically save and restore eye tracker calibration Automatically saves and restores just a single calibration so that user doesn't have to manually save or load, which isn't very convenient to do with an HMD on. --- interface/src/devices/EyeTracker.cpp | 42 +++++++++++++++++++++------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/interface/src/devices/EyeTracker.cpp b/interface/src/devices/EyeTracker.cpp index 7620dc070f..5f89ca0732 100644 --- a/interface/src/devices/EyeTracker.cpp +++ b/interface/src/devices/EyeTracker.cpp @@ -18,6 +18,10 @@ #include "InterfaceLogging.h" #include "OctreeConstants.h" +#ifdef HAVE_IVIEWHMD +char* HIGH_FIDELITY_EYE_TRACKER_CALIBRATION = "HighFidelityEyeTrackerCalibration"; +#endif + #ifdef HAVE_IVIEWHMD static void CALLBACK eyeTrackerCallback(smi_CallbackDataStruct* data) { auto eyeTracker = DependencyManager::get(); @@ -131,26 +135,35 @@ void EyeTracker::setEnabled(bool enabled, bool simulate) { #ifdef HAVE_IVIEWHMD qCDebug(interfaceapp) << "Eye Tracker: Set enabled =" << enabled << ", simulate =" << simulate; - bool success = true; - int result = 0; if (enabled && !_isStreaming) { // There is no smi_stopStreaming() method so keep streaming once started in case tracking is re-enabled after stopping. - result = smi_startStreaming(simulate); + int result = smi_startStreaming(simulate); if (result != SMI_RET_SUCCESS) { qCWarning(interfaceapp) << "Eye Tracker: Error starting streaming:" << smiReturnValueToString(result); - success = false; + // Display error dialog except if SMI SDK has already displayed an error message. + if (result != SMI_ERROR_HMD_NOT_SUPPORTED) { + QMessageBox::warning(nullptr, "Eye Tracker Error", smiReturnValueToString(result)); + } } - _isStreaming = success; + _isStreaming = (result == SMI_RET_SUCCESS); + + if (_isStreaming) { + // Automatically load calibration if one has been saved. + QString availableCalibrations = QString(smi_getAvailableCalibrations()); + if (availableCalibrations.contains(HIGH_FIDELITY_EYE_TRACKER_CALIBRATION)) { + result = smi_loadCalibration(HIGH_FIDELITY_EYE_TRACKER_CALIBRATION); + if (result != SMI_RET_SUCCESS) { + qCWarning(interfaceapp) << "Eye Tracker: Error loading calibration:" << smiReturnValueToString(result); + QMessageBox::warning(nullptr, "Eye Tracker Error", "Error loading calibration" + + smiReturnValueToString(result)); + } + } + } } _isEnabled = enabled && _isStreaming; _isSimulating = _isEnabled && simulate; - - if (!success && result != SMI_ERROR_HMD_NOT_SUPPORTED) { - // Display error dialog after updating _isEnabled. Except if SMI SDK has already displayed an error message. - QMessageBox::warning(nullptr, "Eye Tracker Error", smiReturnValueToString(result)); - } #endif } @@ -199,6 +212,11 @@ void EyeTracker::calibrate(int points) { result = smi_calibrate(); if (result != SMI_RET_SUCCESS) { qCWarning(interfaceapp) << "Eye Tracker: Error performing calibration:" << smiReturnValueToString(result); + } else { + result = smi_saveCalibration(HIGH_FIDELITY_EYE_TRACKER_CALIBRATION); + if (result != SMI_RET_SUCCESS) { + qCWarning(interfaceapp) << "Eye Tracker: Error saving calibration:" << smiReturnValueToString(result); + } } } @@ -226,6 +244,10 @@ QString EyeTracker::smiReturnValueToString(int value) { return "Eye cameras not available"; case smi_ErrorReturnValue::SMI_ERROR_OCULUS_RUNTIME_NOT_SUPPORTED: return "Oculus runtime not supported"; + case smi_ErrorReturnValue::SMI_ERROR_FILE_NOT_FOUND: + return "File not found"; + case smi_ErrorReturnValue::SMI_ERROR_FILE_EMPTY: + return "File empty"; case smi_ErrorReturnValue::SMI_ERROR_UNKNOWN: return "Unknown error"; default: